You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
People often ask whether iminuit/MINUIT supports parallel computation. MINUITs C++ code does not support it, since the minimization is fundamentally sequential and cannot be parallelized in a straight-forward way.
However, it is comparably easy to calculate the result of the cost function in parallel on several cores. This can be handled entirely on the Python side.
There are two ways to parallelize if you have a single fit.
Parallelize the model.
Parallelize the cost function.
Parallelize the model
Users of the builtin cost functions need to provide a model pdf or cdf, which is expected to be a vectorised function. Vectorised functions are already embarrassingly parallel, so in theory it might be enough to decorate the model with @numba.njit(parallel=True). Users need to check, however, that they function body is actually parallelizable. Numba does not generate a diagnostic if this does not work, unless special steps are taken.
The drawback of the previous option is that it requires a parallel implementation of the model pdf/cdf. This limits the use of library-provided pdfs, for example, numba_stats only provides non-parallel versions at the moment. An alternative is to implement the parallelization in the cost function, which is also embarrassingly parallel.This approach has obvious advantages:
It works with any non-parallel pdf
Parallelization could be turned on/off with keyword passed to the cost function
People often ask whether iminuit/MINUIT supports parallel computation. MINUITs C++ code does not support it, since the minimization is fundamentally sequential and cannot be parallelized in a straight-forward way.
However, it is comparably easy to calculate the result of the cost function in parallel on several cores. This can be handled entirely on the Python side.
There are two ways to parallelize if you have a single fit.
Parallelize the model
Users of the builtin cost functions need to provide a model pdf or cdf, which is expected to be a vectorised function. Vectorised functions are already embarrassingly parallel, so in theory it might be enough to decorate the model with
@numba.njit(parallel=True)
. Users need to check, however, that they function body is actually parallelizable. Numba does not generate a diagnostic if this does not work, unless special steps are taken.Parallelize the cost function
The drawback of the previous option is that it requires a parallel implementation of the model pdf/cdf. This limits the use of library-provided pdfs, for example,
numba_stats
only provides non-parallel versions at the moment. An alternative is to implement the parallelization in the cost function, which is also embarrassingly parallel.This approach has obvious advantages:In theory, both approaches should work equally well. The chunk-size can be optimized to match the size of the CPU cache in the second case.
The text was updated successfully, but these errors were encountered: