Commit 3e2e5817 authored by Médéric Boquien's avatar Médéric Boquien

Limit the number of threads to 1 per process in order to prevent MKL from...

Limit the number of threads to 1 per process in order to prevent MKL from creating numerous threads leading to a strong oversubscription of the CPU/RAM as pcigale already does its own parallelisation.
parent 16040c52
......@@ -11,6 +11,7 @@
- When the pcigale.ini file was missing, pcigale would crash and display a fairly cryptic backtrace. Now it explicitly states that the file could not be found. (Médéric Boquien)
### Optimised
- By default the MKL library created many threads for each for the parallel processes. Not only was this not necessary as a high-level parallelisation already exists, but it generated a strong oversubscription on the CPU and on the RAM. The slowdown was over a factor of ~2 in some cases. Now we mandate KML to use only 1 thread fo each process. (Médéric Boquien & Yannick Roehlly)
## 0.10.0 (2016-09-15)
### Added
......
......@@ -12,6 +12,7 @@ from astropy.cosmology import WMAP7 as cosmology
import numpy as np
import scipy.stats as st
from ..utils import nothread
from .utils import (save_best_sed, save_pdf, save_chi2, compute_chi2,
weighted_param)
from ...warehouse import SedWarehouse
......@@ -44,6 +45,10 @@ def init_sed(params, filters, analysed, fluxes, variables, t_begin, n_computed):
global gbl_params, gbl_previous_idx, gbl_filters, gbl_analysed_variables
global gbl_warehouse
# Limit the number of threads to 1 if we use MKL in order to limit the
# oversubscription of the CPU/RAM.
nothread()
gbl_model_fluxes = np.ctypeslib.as_array(fluxes[0])
gbl_model_fluxes = gbl_model_fluxes.reshape(fluxes[1])
......
......@@ -11,6 +11,7 @@ import numpy as np
from ...warehouse import SedWarehouse
from ..utils import OUT_DIR
from ..utils import nothread
def init_fluxes(params, filters, save_sed, variables, fluxes, info, t_begin,
......@@ -41,6 +42,10 @@ def init_fluxes(params, filters, save_sed, variables, fluxes, info, t_begin,
global gbl_params, gbl_previous_idx, gbl_filters, gbl_save_sed
global gbl_warehouse, gbl_variables
# Limit the number of threads to 1 if we use MKL in order to limit the
# oversubscription of the CPU/RAM.
nothread()
gbl_model_fluxes = np.ctypeslib.as_array(fluxes[0])
gbl_model_fluxes = gbl_model_fluxes.reshape(fluxes[1])
......
......@@ -69,3 +69,25 @@ def save_fluxes(model_fluxes, model_parameters, filters, names,
out_table.write("{}/computed_fluxes.fits".format(directory))
out_table.write("{}/computed_fluxes.txt".format(directory),
format='ascii.fixed_width', delimiter=None)
def nothread():
"""Some libraries such as Intel's MKL have automatic threading. This is good
when having only one process. However we already do our own parallelisation.
The additional threads created by the MKL increase in excess the pressure on
the CPU and on the RAM slowing everything down.
Parameters
----------
None
Returns
-------
None
"""
try:
import mkl
mkl.set_num_threads(1)
except ImportError:
pass
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