4#pragma GCC diagnostic push
5#pragma GCC diagnostic ignored "-Wshadow"
8#include "tbb/global_control.h"
10#pragma GCC diagnostic pop
119 using BRange_t = tbb::blocked_range<
decltype(objs.begin())>;
121 auto pred = [redfunc](BRange_t
const & range, T init) {
122 return std::accumulate(range.begin(), range.end(), init, redfunc);
125 BRange_t objRange(objs.begin(), objs.end());
127 return tbb::this_task_arena::isolate([&] {
128 return tbb::parallel_reduce(objRange, T{}, pred, redfunc);
157 const std::function<
void(
unsigned int i)> &
f)
159 if (
GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
160 Warning(
"TThreadExecutor::ParallelFor",
161 "tbb::global_control is limiting the number of parallel workers."
162 " Proceeding with %zu threads this time",
163 tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism));
166 tbb::this_task_arena::isolate([&] {
167 tbb::parallel_for(start, end, step,
f);
179 const std::function<
double(
double a,
double b)> &redfunc)
181 if (
GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
182 Warning(
"TThreadExecutor::ParallelReduce",
183 "tbb::global_control is limiting the number of parallel workers."
184 " Proceeding with %zu threads this time",
185 tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism));
197 const std::function<
float(
float a,
float b)> &redfunc)
199 if (
GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
200 Warning(
"TThreadExecutor::ParallelReduce",
201 "tbb::global_control is limiting the number of parallel workers."
202 " Proceeding with %zu threads this time",
203 tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism));
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
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.