template<class SubC>
class ROOT::TExecutorCRTP< SubC >
This class defines an interface to execute the same task multiple times, possibly in parallel and with different arguments every time.
ROOT::TExecutorCRTP<SubC>::Map
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
The Map function forwards the call to MapImpl, to be implemented by the child classes.
For either signature, func is executed as many times as needed by a pool of n workers, where n typically defaults to the number of available 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::TExecutorCRTP derived classes never delete what they return, they simply forget 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. The ordering of the elements corresponds to the ordering of the arguments.
ROOT::TExecutorCRTP<SubC>::Reduce
These set of methods combine all elements from a std::vector into a single value.
- Parameters
-
redfunc | a callable object, such as a lambda expression, an std::function, a functor object or a function that takes an std::vector and combines all its elements into a single result.
|
[args] | a standard vector
|
ROOT::TExecutorCRTP<SubC>::MapReduce
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. This function should be independent of the size of the vector returned by Map due to optimization of the number of chunks.
Examples:
Generate 1 ten times and
sum those tens
root[]
ROOT::TProcessExecutor pool;
auto tenOnes = pool.
Map([]() {
return 1; }, 10);
auto ten =
Reduce([](
const std::vector<int> &
v) {
return std::accumulate(
v.begin(),
v.end(), 0); }, tenOnes)
Create 10 histograms and merge them into one
Merge collection of TObjects.
auto Map(F func, unsigned nTimes) -> std::vector< InvokeResult_t< F > >
Execute a function without arguments several times.
T * Reduce(const std::vector< T * > &mergeObjs)
"Reduce" an std::vector into a single object by using the object's Merge method.
This class provides a simple interface to execute the same task multiple times in parallel,...
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).
This class provides a simple interface to execute the same task multiple times in parallel threads,...
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).
static uint64_t sum(uint64_t i)
Definition at line 103 of file TExecutorCRTP.hxx.
|
| TExecutorCRTP ()=default |
|
| TExecutorCRTP (const TExecutorCRTP &)=delete |
|
template<class F , class T , class Cond = noReferenceCond<F, T>> |
auto | Map (F func, const std::vector< T > &args) -> std::vector< InvokeResult_t< F, T > > |
| Execute a function over the elements of an immutable vector.
|
|
template<class F , class INTEGER , class Cond = noReferenceCond<F, INTEGER>> |
auto | Map (F func, ROOT::TSeq< INTEGER > args) -> std::vector< InvokeResult_t< F, INTEGER > > |
| Execute a function over a sequence of indexes.
|
|
template<class F , class T , class Cond = noReferenceCond<F, T>> |
auto | Map (F func, std::initializer_list< T > args) -> std::vector< InvokeResult_t< F, T > > |
| Execute a function over the elements of an initializer_list.
|
|
template<class F , class T , class Cond = noReferenceCond<F, T>> |
auto | Map (F func, std::vector< T > &args) -> std::vector< InvokeResult_t< F, T > > |
| Execute a function over the elements of a vector.
|
|
template<class F , class Cond = noReferenceCond<F>> |
auto | Map (F func, unsigned nTimes) -> std::vector< InvokeResult_t< F > > |
| Execute a function without arguments several times.
|
|
template<class F , class T , class Cond = noReferenceCond<F, T>> |
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).
|
|
template<class F , class T , class R , class Cond = noReferenceCond<F, T>> |
auto | MapReduce (F func, const std::vector< T > &args, R redfunc) -> InvokeResult_t< F, T > |
| 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) -> InvokeResult_t< F, INTEGER > |
| 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) -> InvokeResult_t< F, T > |
| 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 Cond = noReferenceCond<F, T>> |
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).
|
|
template<class F , class T , class R , class Cond = noReferenceCond<F, T>> |
auto | MapReduce (F func, std::vector< T > &args, R redfunc) -> InvokeResult_t< F, T > |
| 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) -> InvokeResult_t< F > |
| Execute a function without arguments several times (Map) and accumulate the results into a single value (Reduce).
|
|
TExecutorCRTP & | operator= (const TExecutorCRTP &)=delete |
|
template<class T > |
T * | Reduce (const std::vector< T * > &mergeObjs) |
| "Reduce" an std::vector into a single object by using the object's Merge method.
|
|
template<class T , class R > |
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.
|
|
|
SubC & | Derived () |
|
template<class F , class T , class Cond = noReferenceCond<F, T>> |
auto | MapImpl (F func, const std::vector< T > &args) -> std::vector< InvokeResult_t< F, T > >=delete |
| Implementation of the Map method, left to the derived classes.
|
|
template<class F , class INTEGER , class Cond = noReferenceCond<F, INTEGER>> |
auto | MapImpl (F func, ROOT::TSeq< INTEGER > args) -> std::vector< InvokeResult_t< F, INTEGER > >=delete |
| Implementation of the Map method, left to the derived classes.
|
|
template<class F , class T , class Cond = noReferenceCond<F, T>> |
auto | MapImpl (F func, std::vector< T > &args) -> std::vector< InvokeResult_t< F, T > >=delete |
| Implementation of the Map method, left to the derived classes.
|
|
template<class F , class Cond = noReferenceCond<F>> |
auto | MapImpl (F func, unsigned nTimes) -> std::vector< InvokeResult_t< F > >=delete |
| Implementation of the Map method, left to the derived classes.
|
|