This class implements the interface to execute the same task multiple times, sequentially or in parallel depending on the execution policy passed as a first parameter on construction, and possibly with different arguments every time.
The two possible usages of the Map method are:
Map(F func, unsigned nTimes)
: func is executed nTimes with no arguments
Map(F func, T& args)
: func is executed on each element of the collection of arguments args
For either signature, func is executed as many times as needed by a pool of n workers; where n tipically defaults to the number of cores.
A collection containing the result of each execution is returned.
Note: the user is responsible for the deletion of any object that might be created upon execution of func, returned objects included. ROOT::::Internal::TExecutor never deletes what it returns, it simply forgets it.
- Parameters
-
func | a callable object, such as a lambda expression, an std::function, a functor object or a function that takes zero arguments (for the first signature) or one (for the second signature). |
args | a standard vector, a ROOT::TSeq of integer type or an initializer list for the second signature. An integer only for the first.
|
Note: in cases where the function to be executed takes more than zero/one argument but all are fixed except zero/one, the function can be wrapped in a lambda or via std::bind to give it the right signature.
Return value:
An std::vector. The elements in the container will be the objects returned by func.
This set of methods behaves exactly like Map, but takes an additional function as a third argument. This function is applied to the set of objects returned by the corresponding Map execution to "squash" them into a single object.
An integer can be passed as the fourth argument indicating the number of chunks we want to divide our work in. (Note: Please be aware that chunking is only available when the policy is kMultiThread, ignoring this argument in other cases) This may be useful to avoid the overhead introduced when running really short tasks. In this case, the reduction function should be independent of the size of the vector returned by Map due to optimization of the number of chunks.
Examples:
Merge collection of TObjects.
This class implements the interface to execute the same task multiple times, sequentially or in paral...
auto MapReduce(F func, unsigned nTimes, R redfunc, unsigned nChunks) -> typename std::result_of< F()>::type
Execute a function nTimes (Map) and accumulate the results into a single value (Reduce).
Definition at line 38 of file TExecutor.hxx.
|
| TExecutor (const TExecutor &)=delete |
|
| TExecutor (ROOT::EExecutionPolicy execPolicy, unsigned nWorkers=0) |
| Class constructor.
|
|
| TExecutor (unsigned nWorkers=0) |
| Class constructor.
|
|
unsigned | GetPoolSize () const |
| Return the number of pooled workers.
|
|
template<class F , class T , class R , class Cond = noReferenceCond<F, T>> |
auto | MapReduce (F func, const std::vector< T > &args, R redfunc, unsigned nChunks) -> typename std::result_of< F(T)>::type |
| Execute a function over the elements of an immutable vector (Map) and accumulate the results into a single value (Reduce).
|
|
template<class F , class INTEGER , class R , class Cond = noReferenceCond<F, INTEGER>> |
auto | MapReduce (F func, ROOT::TSeq< INTEGER > args, R redfunc, unsigned nChunks) -> typename std::result_of< F(INTEGER)>::type |
| Execute a function over a sequence of indexes (Map) and accumulate the results into a single value (Reduce).
|
|
template<class F , class T , class R , class Cond = noReferenceCond<F, T>> |
auto | MapReduce (F func, std::initializer_list< T > args, R redfunc, unsigned nChunks) -> typename std::result_of< F(T)>::type |
| Execute a function over the elements of an initializer_list (Map) and accumulate the results into a single value (Reduce).
|
|
template<class F , class T , class R , class Cond = noReferenceCond<F, T>> |
auto | MapReduce (F func, std::vector< T > &args, R redfunc, unsigned nChunks) -> typename std::result_of< F(T)>::type |
| Execute a function over the elements of a vector (Map) and accumulate the results into a single value (Reduce).
|
|
template<class F , class R , class Cond = noReferenceCond<F>> |
auto | MapReduce (F func, unsigned nTimes, R redfunc, unsigned nChunks) -> typename std::result_of< F()>::type |
| Execute a function nTimes (Map) and accumulate the results into a single value (Reduce).
|
|
TExecutor & | operator= (const TExecutor &)=delete |
|
ROOT::EExecutionPolicy | Policy () const |
| Return the execution policy the executor is set to.
|
|
| TExecutorCRTP ()=default |
|
| TExecutorCRTP (const TExecutorCRTP &)=delete |
|
auto | Map (F func, const std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type > |
| Execute a function over the elements of an immutable vector.
|
|
auto | Map (F func, ROOT::TSeq< INTEGER > args) -> std::vector< typename std::result_of< F(INTEGER)>::type > |
| Execute a function over a sequence of indexes.
|
|
auto | Map (F func, std::initializer_list< T > args) -> std::vector< typename std::result_of< F(T)>::type > |
| Execute a function over the elements of an initializer_list.
|
|
auto | Map (F func, std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type > |
| Execute a function over the elements of a vector.
|
|
auto | Map (F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type > |
| Execute a function without arguments several times.
|
|
T * | MapReduce (F func, const std::vector< T * > &args) |
| Execute a function over the TObject-inheriting elements of an immutable vector (Map) and merge the objects into a single one (Reduce).
|
|
auto | MapReduce (F func, const std::vector< T > &args, R redfunc) -> typename std::result_of< F(T)>::type |
| Execute a function over the elements of an immutable vector (Map) and accumulate the results into a single value (Reduce).
|
|
auto | MapReduce (F func, ROOT::TSeq< INTEGER > args, R redfunc) -> typename std::result_of< F(INTEGER)>::type |
| Execute a function over a sequence of indexes (Map) and accumulate the results into a single value (Reduce).
|
|
auto | MapReduce (F func, std::initializer_list< T > args, R redfunc) -> typename std::result_of< F(T)>::type |
| Execute a function over the elements of an initializer_list (Map) and accumulate the results into a single value (Reduce).
|
|
T * | MapReduce (F func, std::vector< T * > &args) |
| Execute a function over the TObject-inheriting elements of a vector (Map) and merge the objects into a single one (Reduce).
|
|
auto | MapReduce (F func, std::vector< T > &args, R redfunc) -> typename std::result_of< F(T)>::type |
| Execute a function over the elements of a vector (Map) and accumulate the results into a single value (Reduce).
|
|
auto | MapReduce (F func, unsigned nTimes, R redfunc) -> typename std::result_of< F()>::type |
| Execute a function without arguments several times (Map) and accumulate the results into a single value (Reduce).
|
|
TExecutorCRTP & | operator= (const TExecutorCRTP &)=delete |
|
T * | Reduce (const std::vector< T * > &mergeObjs) |
| "Reduce" an std::vector into a single object by using the object's Merge method.
|
|
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 the reduction operation.
|
|
|
template<class F , class T , class Cond = noReferenceCond<F, T>> |
auto | MapImpl (F func, const std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type > |
| Execute a function over the elements of an immutable vector.
|
|
template<class F , class INTEGER , class Cond = noReferenceCond<F, INTEGER>> |
auto | MapImpl (F func, ROOT::TSeq< INTEGER > args) -> std::vector< typename std::result_of< F(INTEGER)>::type > |
| Execute a function over a sequence of indexes.
|
|
template<class F , class T , class Cond = noReferenceCond<F, T>> |
auto | MapImpl (F func, std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type > |
| Execute a function over the elements of a vector.
|
|
template<class F , class Cond = noReferenceCond<F>> |
auto | MapImpl (F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type > |
| Execute a function without arguments several times.
|
|
template<class F , class T > |
auto | ResolveExecutorAndMap (F func, T &&args) -> std::vector< typename MapRetType< F, typename std::decay< T >::type >::type > |
| Function called from Map to select and execute the correct Executor according to the set Execution Policy.
|
|