From f5ffb0a07b0ac0bece35e0b701ae7a5f9e851a68 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Fri, 3 Mar 2023 11:15:55 +0100 Subject: [PATCH] use joblib to run in parallel Signed-off-by: Csaba Kiraly --- study.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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)