Skip to content

Commit e6905ab

Browse files
committed
Preload data for CLI fit-grains
A while back, we started lazily loading the data when a frame-cache imageseries was opened. This was so that a user could open an imageseries and investigate things like the shape and metadata before actually performing the data load. For the CLI running fit grains, however, the data preload can be very helpful, because all the processes in the multiprocessing can share the loaded data if `fork` multiprocessing is being used (such as is the case for Linux). We restore that behavior in this PR. Before this PR, a frame cache that required 70 GB of RAM to load in the sparse arrays (which is not uncommon) would end up being loaded separately on every process, which would result in 70 GB times the number of processes of RAM being taken up (easily requiring terabytes of RAM). Now, we ensure the data is preloaded, and the fork multiprocessing enables all 70 GB to just be shared with every process. Signed-off-by: Patrick Avery <[email protected]>
1 parent 20bb998 commit e6905ab

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

hexrd/fitgrains.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,16 @@ def fit_grains(cfg,
386386
else:
387387
nproc = min(ncpus, len(grains_table))
388388
chunksize = max(1, len(grains_table)//ncpus)
389+
390+
if multiprocessing.get_start_method() == 'fork':
391+
# For frame cache, we need to load in all of the data up-front
392+
# so it can use fork multiprocessing to share with the other
393+
# processes. Otherwise, every process will load in the data on
394+
# its own. Accessing one frame in the imageseries is currently
395+
# all we need to do to trigger frame caches to load in all the data.
396+
for ims in imsd.values():
397+
ims[0]
398+
389399
logger.info("\tstarting fit on %d processes with chunksize %d",
390400
nproc, chunksize)
391401
start = timeit.default_timer()

0 commit comments

Comments
 (0)