Commit 95b6b3f8 authored by Médéric Boquien's avatar Médéric Boquien
Browse files

If the code is to be run only on 1 core, then there is no need to fork a new...

If the code is to be run only on 1 core, then there is no need to fork a new process for that. As a side effect, it should at least allow people who have a multiprocessing code to run the code, even if only on one core.
parent 1ba472f3
......@@ -188,19 +188,30 @@ class PdfAnalysis(AnalysisModule):
# Compute the SED fluxes and ancillary data in parallel
initargs = (model_redshifts, model_fluxes, model_variables,
mp.Value('i', 0), time.time())
with mp.Pool(processes=cores, initializer=init_worker_sed,
initargs=initargs) as pool:
pool.starmap(worker_sed, zip(changed_pars,
range(gbl.n_models)))
if cores == 1: # Do not create a new process
init_worker_sed(*initargs)
for changed_par, idx in zip(changed_pars, range(gbl.n_models)):
worker_sed(changed_par, idx)
else:
with mp.Pool(processes=cores, initializer=init_worker_sed,
initargs=initargs) as pool:
pool.starmap(worker_sed, zip(changed_pars,
range(gbl.n_models)))
print('\nAnalysing models...')
# Analysis of each object in parallel.
initargs = (model_redshifts, model_fluxes, model_variables,
mp.Value('i', 0), time.time())
with mp.Pool(processes=cores, initializer=init_worker_analysis,
initargs=initargs) as pool:
items = pool.starmap(worker_analysis, zip(obs_table))
if cores == 1: # Do not create a new process
init_worker_analysis(*initargs)
items = []
for obs in obs_table:
items.append(worker_analysis(obs))
else:
with mp.Pool(processes=cores, initializer=init_worker_analysis,
initargs=initargs) as pool:
items = pool.starmap(worker_analysis, zip(obs_table))
# Local arrays where to unpack the results of the analysis
analysed_averages = np.empty((gbl.n_obs, gbl.n_variables))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment