2#define TBB_USE_CAPTURED_EXCEPTION 0
7#pragma GCC diagnostic push
8#pragma GCC diagnostic ignored "-Wshadow"
11#define TBB_PREVIEW_GLOBAL_CONTROL 1
12#include "tbb/global_control.h"
14#pragma GCC diagnostic pop
124 using BRange_t = tbb::blocked_range<
decltype(objs.begin())>;
126 auto pred = [redfunc](BRange_t
const & range, T init) {
127 return std::accumulate(range.begin(), range.end(), init, redfunc);
130 BRange_t objRange(objs.begin(), objs.end());
132 return tbb::this_task_arena::isolate([&] {
133 return tbb::parallel_reduce(objRange, T{}, pred, redfunc);
162 const std::function<
void(
unsigned int i)> &
f)
164 if (
GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
165 Warning(
"TThreadExecutor::ParallelFor",
166 "tbb::global_control is limiting the number of parallel workers."
167 " Proceeding with %zu threads this time",
168 tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism));
171 tbb::this_task_arena::isolate([&] {
172 tbb::parallel_for(start, end, step,
f);
184 const std::function<
double(
double a,
double b)> &redfunc)
186 if (
GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
187 Warning(
"TThreadExecutor::ParallelReduce",
188 "tbb::global_control is limiting the number of parallel workers."
189 " Proceeding with %zu threads this time",
190 tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism));
192 return fTaskArenaW->Access().execute([&] {
return ROOT::Internal::ParallelReduceHelper<double>(objs, redfunc); });
202 const std::function<
float(
float a,
float b)> &redfunc)
204 if (
GetPoolSize() > tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism)) {
205 Warning(
"TThreadExecutor::ParallelReduce",
206 "tbb::global_control is limiting the number of parallel workers."
207 " Proceeding with %zu threads this time",
208 tbb::global_control::active_value(tbb::global_control::max_allowed_parallelism));
210 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.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.