Adds a ParallelFor wrapper for tbb::parallel_for.

This is in preparation for adding support for a c++11 based parallel
for implementation. The parallel for abstraction does not have the
ability to constrain the total number of threads in nested for loops.
This is solved by distributing the number of threads evenly between
the nested for loops. Adds a TODO to consolidate the next for loops
into a single loop that can be properly split between threads.

Tested by building with TBB and running tests.

Change-Id: I546973b9a4d19b9cdd53caff55d1c80bac8ea953
This commit is contained in:
Mike Vitus
2018-01-24 15:53:19 -08:00
parent c426f464ab
commit dc5ea0ea4d
8 changed files with 228 additions and 50 deletions
@@ -31,8 +31,7 @@
#include "ceres/coordinate_descent_minimizer.h"
#ifdef CERES_USE_TBB
#include <tbb/parallel_for.h>
#include <tbb/task_arena.h>
#include "ceres/parallel_for.h"
#endif
#include <iterator>
@@ -174,12 +173,10 @@ void CoordinateDescentMinimizer::Minimize(
j < independent_set_offsets_[i + 1];
++j) {
#else
tbb::task_arena task_arena(num_inner_iteration_threads);
task_arena.execute([&]{
tbb::parallel_for(independent_set_offsets_[i],
independent_set_offsets_[i + 1],
[&](int j) {
ParallelFor(independent_set_offsets_[i],
independent_set_offsets_[i + 1],
num_inner_iteration_threads,
[&](int j) {
#endif // !CERES_USE_TBB
const ScopedThreadToken scoped_thread_token(&thread_token_provider);
@@ -217,7 +214,6 @@ void CoordinateDescentMinimizer::Minimize(
}
#ifdef CERES_USE_TBB
);
});
#endif
}