Why won't Ceres run in parallel or with multithreading?
24 Jan 2023I discovered by accident some time ago, wandering through some .h files (solver.h), that the reason I couldn’t get Ceres to run in parallel despite having OpenMP support enabled, was that the default number of threads is …. 1.
solver.h, within the struct CERES_EXPORT Options
section:
// Maximum number of iterations for the minimizer to run for.
int max_num_iterations = 50;
// Maximum time for which the minimizer should run for.
double max_solver_time_in_seconds = 1e9;
// Number of threads used by Ceres for evaluating the cost and
// jacobians.
int num_threads = 1;
To set num_threads
, modify a member of Solver::options
. For example, since I am using OpenMP, I do
Solver::Options options;
options.num_threads = omp_get_max_threads();
Links all in one place:
- solver.h,
- Ceres, the non-linear least squares solver, page,
num_threads
documentation,- OpenMP documentation for
omp_get_max_threads()
.