Why won't Ceres run in parallel or with multithreading?

ceres cplusplus optimization

I 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();

© Amy Tabb 2018 - 2023. All rights reserved. The contents of this site reflect my personal perspectives and not those of any other entity.