use joblib to run in parallel
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
0b6cfad967
commit
f5ffb0a07b
9
study.py
9
study.py
|
@ -2,8 +2,13 @@
|
||||||
|
|
||||||
import time, sys, random, copy
|
import time, sys, random, copy
|
||||||
import importlib
|
import importlib
|
||||||
|
from joblib import Parallel, delayed
|
||||||
from DAS import *
|
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):
|
def runOnce(sim, config, shape):
|
||||||
if not config.deterministic:
|
if not config.deterministic:
|
||||||
random.seed(datetime.now())
|
random.seed(datetime.now())
|
||||||
|
@ -41,9 +46,7 @@ def study():
|
||||||
sim.logger.info("Starting simulations:", extra=sim.format)
|
sim.logger.info("Starting simulations:", extra=sim.format)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
for shape in config.nextShape():
|
results = Parallel(-1)(delayed(runOnce)(sim, config, shape) for shape in config.nextShape())
|
||||||
result = runOnce(sim, config, shape)
|
|
||||||
results.append(copy.deepcopy(result))
|
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
sim.logger.info("A total of %d simulations ran in %d seconds" % (len(results), end-start), extra=sim.format)
|
sim.logger.info("A total of %d simulations ran in %d seconds" % (len(results), end-start), extra=sim.format)
|
||||||
|
|
Loading…
Reference in New Issue