11#ifndef ROOT_TSequentialExecutor
12#define ROOT_TSequentialExecutor
14#include "RConfigure.h"
30 void Foreach(
F func,
unsigned nTimes);
31 template<
class F,
class INTEGER>
34 template<
class F,
class T>
35 void Foreach(
F func, std::initializer_list<T> args);
37 template<
class F,
class T>
38 void Foreach(
F func, std::vector<T> &args);
41 template<
class F,
class Cond = noReferenceCond<F>>
42 auto Map(
F func,
unsigned nTimes) -> std::vector<
typename std::result_of<
F()>
::type>;
43 template<
class F,
class INTEGER,
class Cond = noReferenceCond<F, INTEGER>>
45 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
46 auto Map(
F func, std::vector<T> &args) -> std::vector<
typename std::result_of<
F(
T)>
::type>;
53 template<
class F,
class R,
class Cond = noReferenceCond<F>>
54 auto MapReduce(
F func,
unsigned nTimes,
R redfunc) ->
typename std::result_of<
F()>
::type;
55 template<
class F,
class T,
class R,
class Cond = noReferenceCond<F, T>>
56 auto MapReduce(
F func, std::vector<T> &args,
R redfunc) ->
typename std::result_of<
F(
T)>
::type;
59 template<
class T,
class R>
auto Reduce(
const std::vector<T> &objs,
R redfunc) ->
decltype(redfunc(objs));
70 for (
auto i = 0U; i < nTimes; ++i) func();
76 template<
class F,
class INTEGER>
78 for(
auto i : args) func(i);
85 template<
class F,
class T>
87 std::vector<T> vargs(std::move(args));
95 template<
class F,
class T>
97 unsigned int nToProcess = args.size();
106 template<
class F,
class Cond>
108 using retType =
decltype(func());
109 std::vector<retType> reslist(nTimes);
110 for(
auto i:
ROOT::TSeqI(nTimes)) reslist[i] = func();
118 template<
class F,
class INTEGER,
class Cond>
120 using retType =
decltype(func(*args.begin()));
121 std::vector<retType> reslist(args.size());
122 for(
auto i: args) reslist[i] = func(i);
132 template<
class F,
class T,
class Cond>
135 using retType =
decltype(func(args.front()));
136 unsigned int nToProcess = args.size();
137 std::vector<retType> reslist(nToProcess);
138 for(
auto i:
ROOT::TSeqI(nToProcess)) reslist[i] = func(args[i]);
142 template<
class F,
class R,
class Cond>
144 return Reduce(
Map(func, nTimes), redfunc);
147 template<
class F,
class T,
class R,
class Cond>
149 return Reduce(
Map(func, args), redfunc);
155 template<
class T,
class R>
159 static_assert(std::is_same<
decltype(redfunc(objs)),
T>::value,
"redfunc does not have the correct signature");
160 return redfunc(objs);
This class defines an interface to execute the same task multiple times in parallel,...
A pseudo container class which is a generator of indices.
void Foreach(F func, unsigned nTimes)
Execute func (with no arguments) nTimes.
auto MapReduce(F func, unsigned nTimes, R redfunc) -> typename std::result_of< F()>::type
auto Map(F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >
Execute func (with no arguments) nTimes.
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...
TSequentialExecutor(TSequentialExecutor &)=delete
TSequentialExecutor & operator=(TSequentialExecutor &)=delete
auto Map(Args &&... args) -> decltype(ROOT::Detail::VecOps::MapFromTuple(std::forward_as_tuple(args...), std::make_index_sequence< sizeof...(args) - 1 >()))
Create new collection applying a callable to the elements of the input collection.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...