12#ifndef ROOT_TThreadExecutor
13#define ROOT_TThreadExecutor
15#include "RConfigure.h"
20# if !defined(__ROOTCLING__) && !defined(G__DICTIONARY)
21# error "Cannot use ROOT::TThreadExecutor without defining R__USE_IMT."
32#include <initializer_list>
55 template<
class F,
class INTEGER>
57 template<
class F,
class T>
58 void Foreach(F func, std::initializer_list<T> args,
unsigned nChunks = 0);
59 template<
class F,
class T>
61 template<
class F,
class T>
62 void Foreach(F func,
const std::vector<T> &args,
unsigned nChunks = 0);
69 template <
class F,
class R,
class Cond = val
idMapReturnCond<F>>
71 template <
class F,
class INTEGER,
class R,
class Cond = val
idMapReturnCond<F, INTEGER>>
73 -> std::vector<InvokeResult_t<F, INTEGER>>;
74 template <
class F,
class T,
class R,
class Cond = val
idMapReturnCond<F, T>>
75 auto Map(F func, std::initializer_list<T> args,
R redfunc,
unsigned nChunks) -> std::vector<InvokeResult_t<F, T>>;
76 template <
class F,
class T,
class R,
class Cond = val
idMapReturnCond<F, T>>
77 auto Map(F func, std::vector<T> &args,
R redfunc,
unsigned nChunks) -> std::vector<InvokeResult_t<F, T>>;
78 template <
class F,
class T,
class R,
class Cond = val
idMapReturnCond<F, T>>
79 auto Map(F func,
const std::vector<T> &args,
R redfunc,
unsigned nChunks) -> std::vector<InvokeResult_t<F, T>>;
90 template <
class F,
class R,
class Cond = val
idMapReturnCond<F>>
92 template <
class F,
class R,
class Cond = val
idMapReturnCond<F>>
94 template <
class F,
class INTEGER,
class R,
class Cond = val
idMapReturnCond<F, INTEGER>>
96 template <
class F,
class T,
class R,
class Cond = val
idMapReturnCond<F, T>>
98 template <
class F,
class T,
class R,
class Cond = val
idMapReturnCond<F, T>>
100 template <
class F,
class T,
class R,
class Cond = val
idMapReturnCond<F, T>>
102 template <
class F,
class T,
class R,
class Cond = val
idMapReturnCond<F, T>>
104 template <
class F,
class T,
class R,
class Cond = val
idMapReturnCond<F, T>>
116 template <
class F,
class Cond = val
idMapReturnCond<F>>
117 auto MapImpl(F func,
unsigned nTimes) -> std::vector<InvokeResult_t<F>>;
118 template <
class F,
class INTEGER,
class Cond = val
idMapReturnCond<F, INTEGER>>
120 template <
class F,
class T,
class Cond = val
idMapReturnCond<F, T>>
121 auto MapImpl(F func, std::vector<T> &args) -> std::vector<InvokeResult_t<F, T>>;
122 template <
class F,
class T,
class Cond = val
idMapReturnCond<F, T>>
123 auto MapImpl(F func,
const std::vector<T> &args) -> std::vector<InvokeResult_t<F, T>>;
126 void ParallelFor(
unsigned start,
unsigned end,
unsigned step,
const std::function<
void(
unsigned int i)> &
f);
129 template<
class T,
class R>
133 std::shared_ptr<ROOT::Internal::RTaskArenaWrapper>
fTaskArenaW =
nullptr;
152 auto lambda = [&](
unsigned int i)
154 for (
unsigned j = 0;
j < step && (i +
j) <
nTimes;
j++) {
167 template<
class F,
class INTEGER>
173 unsigned start = *args.
begin();
174 unsigned end = *args.
end();
178 auto lambda = [&](
unsigned int i)
180 for (
unsigned j = 0;
j < step && (i +
j) < end;
j+=
seqStep) {
193 template<
class F,
class T>
195 std::vector<T>
vargs(std::move(args));
205 template<
class F,
class T>
214 auto lambda = [&](
unsigned int i)
229 template<
class F,
class T>
238 auto lambda = [&](
unsigned int i)
252 template <
class F,
class Cond>
255 using retType =
decltype(func());
257 auto lambda = [&](
unsigned int i)
261 ParallelFor(0U,
nTimes, 1, lambda);
271 template <
class F,
class INTEGER,
class Cond>
274 using retType =
decltype(func(*args.begin()));
275 std::vector<retType>
reslist(args.size());
276 auto lambda = [&](
unsigned int i) {
reslist[i] = func(args[i]); };
277 ParallelFor(0U, args.size(), 1, lambda);
287 template <
class F,
class R,
class Cond>
298 using retType =
decltype(func());
300 auto lambda = [&](
unsigned int i)
303 for (
unsigned j = 0;
j < step && (i +
j) <
nTimes;
j++) {
308 ParallelFor(0U,
nTimes, step, lambda);
318 template <
class F,
class T,
class Cond>
322 using retType =
decltype(func(args.front()));
327 auto lambda = [&](
unsigned int i)
342 template <
class F,
class T,
class Cond>
346 using retType =
decltype(func(args.front()));
351 auto lambda = [&](
unsigned int i)
366 template <
class F,
class INTEGER,
class R,
class Cond>
368 -> std::vector<InvokeResult_t<F, INTEGER>>
372 return Map(func, args);
380 using retType =
decltype(func(*args.begin()));
382 auto lambda = [&](
unsigned int i) {
400 template <
class F,
class T,
class R,
class Cond>
402 -> std::vector<InvokeResult_t<F, T>>
406 return Map(func, args);
414 using retType =
decltype(func(args.front()));
416 auto lambda = [&](
unsigned int i) {
434 template <
class F,
class T,
class R,
class Cond>
436 -> std::vector<InvokeResult_t<F, T>>
440 return Map(func, args);
448 using retType =
decltype(func(args.front()));
450 auto lambda = [&](
unsigned int i) {
468 template <
class F,
class T,
class R,
class Cond>
470 -> std::vector<InvokeResult_t<F, T>>
472 std::vector<T>
vargs(std::move(args));
480 template <
class F,
class R,
class Cond>
491 template <
class F,
class R,
class Cond>
502 template <
class F,
class INTEGER,
class R,
class Cond>
514 template <
class F,
class T,
class R,
class Cond>
524 template <
class F,
class T,
class R,
class Cond>
527 return Reduce(Map(func, args),
redfunc);
533 template <
class F,
class T,
class R,
class Cond>
536 return Reduce(Map(func, args),
redfunc);
544 template <
class F,
class T,
class R,
class Cond>
555 template <
class F,
class T,
class R,
class Cond>
564 template<
class T,
class R>
568 static_assert(std::is_same<
decltype(
redfunc(
objs)), T>
::value,
"redfunc does not have the correct signature");
579 template<
class T,
class BINARYOP>
583 static_assert(std::is_same<
decltype(
redfunc(
objs.front(),
objs.front())), T>
::value,
"redfunc does not have the correct signature");
593 template<
class T,
class R>
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
This class defines an interface to execute the same task multiple times, possibly in parallel and wit...
A pseudo container class which is a generator of indices.
This class provides a simple interface to execute the same task multiple times in parallel threads,...
auto SeqReduce(const std::vector< T > &objs, R redfunc) -> decltype(redfunc(objs))
"Reduce", sequentially, an std::vector into a single object
auto Map(F func, unsigned nTimes, R redfunc, unsigned nChunks) -> std::vector< InvokeResult_t< F > >
Execute a function nTimes in parallel, dividing the execution in nChunks and providing a result per c...
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.
auto MapReduce(F func, unsigned nTimes, R redfunc) -> InvokeResult_t< F >
Execute a function nTimes in parallel (Map) and accumulate the results into a single value (Reduce).
std::shared_ptr< ROOT::Internal::RTaskArenaWrapper > fTaskArenaW
Pointer to the TBB task arena wrapper.
auto Reduce(const std::vector< T > &objs, R redfunc) -> decltype(redfunc(objs))
"Reduce" an std::vector into a single object by passing a function as the second argument defining th...
void Foreach(F func, unsigned nTimes, unsigned nChunks=0)
Execute a function without arguments several times in parallel, dividing the execution in nChunks.
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
TThreadExecutor & operator=(const TThreadExecutor &)=delete
TThreadExecutor(const TThreadExecutor &)=delete
auto MapImpl(F func, unsigned nTimes) -> std::vector< InvokeResult_t< F > >
Execute a function without arguments several times in parallel.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...