4#pragma GCC diagnostic push
5#pragma GCC diagnostic ignored "-Wshadow"
8#define TBB_PREVIEW_GLOBAL_CONTROL 1
9#include "tbb/global_control.h"
11#pragma GCC diagnostic pop
121 using BRange_t = tbb::blocked_range<
decltype(objs.begin())>;
123 auto pred = [redfunc](BRange_t
const & range, T init) {
124 return std::accumulate(range.begin(), range.end(), init, redfunc);
127 BRange_t objRange(objs.begin(), objs.end());
129 return tbb::this_task_arena::isolate([&] {
130 return tbb::parallel_reduce(objRange, T{}, pred, redfunc);
159 const std::function<
void(
unsigned int i)> &
f)
161 if (
GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
162 Warning(
"TThreadExecutor::ParallelFor",
163 "tbb::global_control is limiting the number of parallel workers."
164 " Proceeding with %zu threads this time",
165 tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism));
168 tbb::this_task_arena::isolate([&] {
169 tbb::parallel_for(start, end, step,
f);
181 const std::function<
double(
double a,
double b)> &redfunc)
183 if (
GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
184 Warning(
"TThreadExecutor::ParallelReduce",
185 "tbb::global_control is limiting the number of parallel workers."
186 " Proceeding with %zu threads this time",
187 tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism));
189 return fTaskArenaW->Access().execute([&] {
return ROOT::Internal::ParallelReduceHelper<double>(objs, redfunc); });
199 const std::function<
float(
float a,
float b)> &redfunc)
201 if (
GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
202 Warning(
"TThreadExecutor::ParallelReduce",
203 "tbb::global_control is limiting the number of parallel workers."
204 " Proceeding with %zu threads this time",
205 tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism));
207 return fTaskArenaW->Access().execute([&] {
return ROOT::Internal::ParallelReduceHelper<float>(objs, redfunc); });
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
void ParallelFor(unsigned start, unsigned end, unsigned step, const std::function< void(unsigned int i)> &f)
Execute a function in parallel over the indices of a loop.
unsigned GetPoolSize() const
Returns the number of worker threads in the task arena.
std::shared_ptr< ROOT::Internal::RTaskArenaWrapper > fTaskArenaW
Pointer to the TBB task arena wrapper.
TThreadExecutor(UInt_t nThreads=0u)
Class constructor.
double ParallelReduce(const std::vector< double > &objs, const std::function< double(double a, double b)> &redfunc)
"Reduce" in parallel an std::vector<double> into a single double value
static T ParallelReduceHelper(const std::vector< T > &objs, const std::function< T(T a, T b)> &redfunc)
A helper function to implement the TThreadExecutor::ParallelReduce methods.
std::shared_ptr< ROOT::Internal::RTaskArenaWrapper > GetGlobalTaskArena(unsigned maxConcurrency=0)
Factory function returning a shared pointer to the instance of the global RTaskArenaWrapper.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...