use joblib to run in parallel

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-03-03 11:15:55 +01:00
parent 0b6cfad967
commit f5ffb0a07b
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
1 changed files with 6 additions and 3 deletions

View File

@ -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)