From 567d13e37083ba7bc7f8ebf4c64ffb2cbff1d1cb Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Mon, 13 Mar 2023 14:22:14 +0100 Subject: [PATCH] add numJobs parameter to config Signed-off-by: Csaba Kiraly --- config_example.py | 4 ++++ study.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config_example.py b/config_example.py index 0ac65ad..c2f7fcf 100644 --- a/config_example.py +++ b/config_example.py @@ -20,6 +20,10 @@ dumpXML = 1 visualization = 1 logLevel = logging.INFO +# number of parallel workers. -1: all cores; 1: sequential +# for more details, see joblib.Parallel +numJobs = 3 + # Number of simulation runs with the same parameters for statistical relevance runs = range(10) diff --git a/study.py b/study.py index 914acfe..f557fc2 100644 --- a/study.py +++ b/study.py @@ -50,7 +50,8 @@ def study(): sim.logger.info("Starting simulations:", extra=sim.format) start = time.time() - results = Parallel(-1)(delayed(runOnce)(sim, config, shape) for shape in config.nextShape()) + results = Parallel(config.numJobs)(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)