diff --git a/study.py b/study.py index 2823fa1..4cd4b53 100644 --- a/study.py +++ b/study.py @@ -2,8 +2,13 @@ import time, sys, random, copy import importlib +from joblib import Parallel, delayed from DAS import * +# Parallel execution: +# The code currently uses 'joblib' to execute on multiple cores. For other options such as 'ray', see +# https://stackoverflow.com/questions/9786102/how-do-i-parallelize-a-simple-python-loop + def runOnce(sim, config, shape): if not config.deterministic: random.seed(datetime.now()) @@ -41,9 +46,7 @@ def study(): sim.logger.info("Starting simulations:", extra=sim.format) start = time.time() - for shape in config.nextShape(): - result = runOnce(sim, config, shape) - results.append(copy.deepcopy(result)) + results = Parallel(-1)(delayed(runOnce)(sim, config, shape) for shape in config.nextShape()) end = time.time() sim.logger.info("A total of %d simulations ran in %d seconds" % (len(results), end-start), extra=sim.format)