This class defines an interface to execute the same task multiple times, possibly in parallel and 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 argumentsMap(F func, T& args)
: func is executed on each element of the collection of arguments argsThe 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.
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.
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.
These set of methods combine all elements from a std::vector into a single value.
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 |
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.
Definition at line 103 of file TExecutorCRTP.hxx.
Public Member Functions | |
TExecutorCRTP ()=default | |
TExecutorCRTP (const TExecutorCRTP &)=delete | |
template<class F , class T , class Cond = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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. | |
Protected Types | |
template<typename F , typename... Args> | |
using | InvokeResult_t = ROOT::TypeTraits::InvokeResult_t<F, Args...> |
template<class F , class... T> | |
using | validMapReturnCond |
type definition used in templated functions for not allowing mapping functions that return references or void. | |
Private Member Functions | |
SubC & | Derived () |
template<class F , class T , class Cond = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<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 = validMapReturnCond<F>> | |
auto | MapImpl (F func, unsigned nTimes) -> std::vector< InvokeResult_t< F > >=delete |
Implementation of the Map method, left to the derived classes. | |
#include <ROOT/TExecutorCRTP.hxx>
|
protected |
Definition at line 107 of file TExecutorCRTP.hxx.
|
protected |
type definition used in templated functions for not allowing mapping functions that return references or void.
The resulting vector elements must be assignable, references aren't.
Definition at line 112 of file TExecutorCRTP.hxx.
|
default |
|
delete |
|
inlineprivate |
Definition at line 156 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::Map | ( | F | func, |
const std::vector< T > & | args ) -> std::vector<InvokeResult_t<F, T>> |
Execute a function over the elements of an immutable vector.
func | Function to be executed on the elements of the vector passed as second parameter. |
args | Vector of elements passed as an argument to func . |
Definition at line 240 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::Map | ( | F | func, |
ROOT::TSeq< INTEGER > | args ) -> std::vector<InvokeResult_t<F, INTEGER>> |
Execute a function over a sequence of indexes.
func | Function to be executed. Must take an element of the sequence passed assecond argument as a parameter. |
args | Sequence of indexes to execute func on. |
Definition at line 198 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::Map | ( | F | func, |
std::initializer_list< T > | args ) -> std::vector<InvokeResult_t<F, T>> |
Execute a function over the elements of an initializer_list.
func | Function to be executed on the elements of the initializer_list passed as second parameter. |
args | initializer_list for a vector to apply func on. |
Definition at line 211 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::Map | ( | F | func, |
std::vector< T > & | args ) -> std::vector<InvokeResult_t<F, T>> |
Execute a function over the elements of a vector.
func | Function to be executed on the elements of the vector passed as second parameter. |
args | Vector of elements passed as an argument to func . |
Definition at line 226 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::Map | ( | F | func, |
unsigned | nTimes ) -> std::vector<InvokeResult_t<F>> |
Execute a function without arguments several times.
func | Function to be executed. |
nTimes | Number of times function should be called. |
Definition at line 185 of file TExecutorCRTP.hxx.
|
privatedelete |
Implementation of the Map method, left to the derived classes.
|
privatedelete |
Implementation of the Map method, left to the derived classes.
|
privatedelete |
Implementation of the Map method, left to the derived classes.
|
privatedelete |
Implementation of the Map method, left to the derived classes.
T * ROOT::TExecutorCRTP< SubC >::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).
func | Function to be executed on the elements of the vector passed as second parameter. |
args | Immutable vector of elements passed as an argument to func . |
Definition at line 336 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::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).
func | Function to be executed on the elements of the vector passed as second parameter. |
args | Immutable vector of elements passed as an argument to func . |
redfunc | Reduction function to combine the results of the calls to func . Must return the same type as func . |
Definition at line 312 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::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).
func | Function to be executed. Must take an element of the sequence passed assecond argument as a parameter. |
args | Sequence of indexes to execute func on. |
redfunc | Reduction function to combine the results of the calls to func . Must return the same type as func . |
Definition at line 269 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::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).
func | Function to be executed on the elements of the initializer_list passed as second parameter. |
args | initializer_list for a vector to apply func on. |
redfunc | Reduction function to combine the results of the calls to func . Must return the same type as func . |
Definition at line 283 of file TExecutorCRTP.hxx.
T * ROOT::TExecutorCRTP< SubC >::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).
func | Function to be executed on the elements of the vector passed as second parameter. |
args | Vector of elements passed as an argument to func . |
Definition at line 324 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::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).
func | Function to be executed on the elements of the vector passed as second parameter. |
args | Vector of elements passed as an argument to func . |
redfunc | Reduction function to combine the results of the calls to func . Must return the same type as func . |
Definition at line 298 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::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).
func | Function to be executed. |
nTimes | Number of times function should be called. |
redfunc | Reduction function to combine the results of the calls to func . Must return the same type as func . |
Definition at line 255 of file TExecutorCRTP.hxx.
|
delete |
T * ROOT::TExecutorCRTP< SubC >::Reduce | ( | const std::vector< T * > & | mergeObjs | ) |
"Reduce" an std::vector into a single object by using the object's Merge method.
mergeObjs | A vector of ROOT objects implementing the Merge method |
Definition at line 347 of file TExecutorCRTP.hxx.
auto ROOT::TExecutorCRTP< SubC >::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.
objs | A vector of elements to combine. |
redfunc | Reduction function to combine the elements of the vector objs |
Definition at line 373 of file TExecutorCRTP.hxx.