Commit 9042dfda authored by Médéric Boquien's avatar Médéric Boquien

Maximise the CPU cache hit rate with computing the χ² by storing contiguously...

Maximise the CPU cache hit rate with computing the χ² by storing contiguously all the models at a given redshift.
parent ad964607
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
### Optimised ### Optimised
- Slight speedup of the computation of the likelihood from the χ² (Médéric Boquien) - Slight speedup of the computation of the likelihood from the χ² (Médéric Boquien)
- Speedup of the computation of the χ² by ~10% (Médéric Boquien) - Speedup of the computation of the χ² by ~10% (Médéric Boquien)
- Thanks to a change in the layout of the models storage in RAM, the computation of the χ² is now massively faster when the run contains multiple redshifts. (Médéric Boquien)
- The the fritz2006 module should now run faster thanks to an optimisation of the computation of the luminosity of the various AGN components (Médéric Boquien & Guang Yang) - The the fritz2006 module should now run faster thanks to an optimisation of the computation of the luminosity of the various AGN components (Médéric Boquien & Guang Yang)
## 2018.0 (2018-11-06) ## 2018.0 (2018-11-06)
......
...@@ -103,6 +103,9 @@ def sed(idx, midx): ...@@ -103,6 +103,9 @@ def sed(idx, midx):
sed = gbl_warehouse.get_sed(gbl_models.params.modules, sed = gbl_warehouse.get_sed(gbl_models.params.modules,
gbl_models.params.from_index(midx)) gbl_models.params.from_index(midx))
# The redshift is the fastest varying variable but we want to store it
# as the slowest one so that models at a given redshift are contiguous
idx = (idx % gbl_models.nz) * gbl_models.nm + idx // gbl_models.nz
if 'sfh.age' in sed.info and sed.info['sfh.age'] > sed.info['universe.age']: if 'sfh.age' in sed.info and sed.info['sfh.age'] > sed.info['universe.age']:
for band in gbl_models.flux: for band in gbl_models.flux:
gbl_models.flux[band][idx] = np.nan gbl_models.flux[band][idx] = np.nan
...@@ -117,10 +120,11 @@ def sed(idx, midx): ...@@ -117,10 +120,11 @@ def sed(idx, midx):
gbl_models.extprop[prop][idx] = sed.info[prop] gbl_models.extprop[prop][idx] = sed.info[prop]
for prop in gbl_models.intprop: for prop in gbl_models.intprop:
gbl_models.intprop[prop][idx] = sed.info[prop] gbl_models.intprop[prop][idx] = sed.info[prop]
gbl_models.index[idx] = midx
gbl_counter.inc() gbl_counter.inc()
@profile
def analysis(idx, obs): def analysis(idx, obs):
"""Worker process to analyse the PDF and estimate parameters values and """Worker process to analyse the PDF and estimate parameters values and
store them in an instance of ResultsManager. store them in an instance of ResultsManager.
...@@ -141,8 +145,10 @@ def analysis(idx, obs): ...@@ -141,8 +145,10 @@ def analysis(idx, obs):
# work on views of the arrays and not on copies to save on RAM. # work on views of the arrays and not on copies to save on RAM.
z = np.array( z = np.array(
gbl_models.conf['sed_modules_params']['redshifting']['redshift']) gbl_models.conf['sed_modules_params']['redshifting']['redshift'])
wz = slice(np.abs(obs.redshift-z).argmin(), None, z.size) length = gbl_models.nm
corr_dz = compute_corr_dz(z[wz.start], obs) zidx = np.abs(obs.redshift-z).argmin()
wz = slice(zidx * length, (zidx + 1) * length, 1)
corr_dz = compute_corr_dz(z[zidx], obs)
else: # We do not know the redshift so we use the full grid else: # We do not know the redshift so we use the full grid
wz = slice(0, None, 1) wz = slice(0, None, 1)
corr_dz = 1. corr_dz = 1.
...@@ -205,8 +211,7 @@ def analysis(idx, obs): ...@@ -205,8 +211,7 @@ def analysis(idx, obs):
best_idx_z = np.nanargmin(chi2) best_idx_z = np.nanargmin(chi2)
gbl_results.best.chi2[idx] = chi2[best_idx_z] gbl_results.best.chi2[idx] = chi2[best_idx_z]
gbl_results.best.scaling[idx] = scaling[best_idx_z] gbl_results.best.scaling[idx] = scaling[best_idx_z]
gbl_results.best.index[idx] = (wz.start + best_idx_z*wz.step + gbl_results.best.index[idx] = gbl_models.index[wz][best_idx_z]
gbl_models.block.start)
gbl_counter.inc() gbl_counter.inc()
......
...@@ -41,11 +41,16 @@ class ModelsManager(object): ...@@ -41,11 +41,16 @@ class ModelsManager(object):
bandnames = set(obs.bands+conf['analysis_params']['bands']) bandnames = set(obs.bands+conf['analysis_params']['bands'])
else: else:
bandnames = obs.bands bandnames = obs.bands
size = len(params.blocks[iblock]) size = len(params.blocks[iblock])
if conf['parameters_file'] is "":
self.nz = len(conf['sed_modules_params']['redshifting']['redshift'])
self.nm = size // self.nz
self.flux = {band: SharedArray(size) for band in bandnames} self.flux = {band: SharedArray(size) for band in bandnames}
self.intprop = {prop: SharedArray(size) for prop in self.intpropnames} self.intprop = {prop: SharedArray(size) for prop in self.intpropnames}
self.extprop = {prop: SharedArray(size) for prop in self.extpropnames} self.extprop = {prop: SharedArray(size) for prop in self.extpropnames}
self.index = SharedArray(size)
def save(self, filename): def save(self, filename):
"""Save the fluxes and properties of all the models into a table. """Save the fluxes and properties of all the models into a table.
......
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