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
+2 -6
View File
@@ -98,8 +98,7 @@
#ifdef CERES_USE_TBB
#include <atomic>
#include <tbb/parallel_for.h>
#include <tbb/task_arena.h>
#include "ceres/parallel_for.h"
#endif
namespace ceres {
@@ -196,10 +195,8 @@ class ProgramEvaluator : public Evaluator {
#ifdef CERES_USE_TBB
std::atomic_bool abort(false);
tbb::task_arena task_arena(options_.num_threads);
task_arena.execute([&]{
tbb::parallel_for(0, num_residual_blocks, [&](int i) {
ParallelFor(0, num_residual_blocks, options_.num_threads, [&](int i) {
#endif // CERES_USE_TBB
if (abort) {
@@ -290,7 +287,6 @@ class ProgramEvaluator : public Evaluator {
}
#ifdef CERES_USE_TBB
);
});
#endif // CERES_USE_TBB
if (!abort) {