ROOT 6.16/01 Reference Guide |
This class defines an interface to execute the same task multiple times in parallel, possibly with different arguments every time.
The classes implementing it mimic the behaviour of python's pool.Map method.
The two possible usages of the Map method are:
For either signature, func is executed as many times as needed by a pool of nThreads threads; It 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::TExecutor never deletes what it returns, it simply forgets it.
func | a lambda expression, an std::function, a loaded macro, a functor class 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.
Definition at line 61 of file TExecutor.hxx.
Public Types | |
template<class F , class... T> | |
using | noReferenceCond = typename std::enable_if<"Function can't return a reference" &&!(std::is_reference< typename std::result_of< F(T...)>::type >::value)>::type |
Public Member Functions | |
TExecutor ()=default | |
TExecutor (size_t) | |
template<class F , class INTEGER , class Cond = noReferenceCond<F, INTEGER>> | |
auto | Map (F func, ROOT::TSeq< INTEGER > args) -> std::vector< typename std::result_of< F(INTEGER)>::type > |
Execute func in parallel, taking an element of a sequence as argument. More... | |
template<class F , class T , class Cond > | |
auto | Map (F func, std::initializer_list< T > args) -> std::vector< typename std::result_of< F(T)>::type > |
Execute func in parallel, taking an element of the std::initializer_list as argument. More... | |
template<class F , class T , class Cond = noReferenceCond<F, T>> | |
auto | Map (F func, std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type > |
Execute func in parallel, taking an element of an std::vector as argument. More... | |
template<class F , class Cond = noReferenceCond<F>> | |
auto | Map (F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type > |
Execute func (with no arguments) nTimes in parallel. More... | |
template<class F , class INTEGER , class R , class Cond = noReferenceCond<F, INTEGER>> | |
auto | MapReduce (F func, ROOT::TSeq< INTEGER > args, R redfunc) -> typename std::result_of< F(INTEGER)>::type |
This method behaves just like Map, but an additional redfunc function must be provided. More... | |
template<class F , class T , class R , class Cond > | |
auto | MapReduce (F func, std::initializer_list< T > args, R redfunc) -> typename std::result_of< F(T)>::type |
template<class F , class T , class Cond = noReferenceCond<F, T>> | |
T * | MapReduce (F func, std::vector< T * > &args) |
template<class T > | |
T * | Reduce (const std::vector< T * > &mergeObjs) |
"Reduce" an std::vector into a single object by using the object's Merge More... | |
Private Member Functions | |
subc & | Derived () |
#include <ROOT/TExecutor.hxx>
using ROOT::TExecutor< subc >::noReferenceCond = typename std::enable_if<"Function can't return a reference" && !(std::is_reference<typename std::result_of<F(T...)>::type>::value)>::type |
Definition at line 67 of file TExecutor.hxx.
|
explicitdefault |
|
inlineexplicit |
Definition at line 64 of file TExecutor.hxx.
|
inlineprivate |
Definition at line 99 of file TExecutor.hxx.
auto ROOT::TExecutor< subc >::Map | ( | F | func, |
ROOT::TSeq< INTEGER > | args | ||
) | -> std::vector<typename std::result_of<F(INTEGER)>::type> |
Execute func in parallel, taking an element of a sequence as argument.
Divides and groups the executions in nChunks with partial reduction; A vector containg partial reductions' results is returned.
Definition at line 121 of file TExecutor.hxx.
auto ROOT::TExecutor< subc >::Map | ( | F | func, |
std::initializer_list< T > | args | ||
) | -> std::vector<typename std::result_of<F(T)>::type> |
Execute func in parallel, taking an element of the std::initializer_list as argument.
Divides and groups the executions in nChunks with partial reduction; A vector containg partial reductions' results is returned.
Definition at line 131 of file TExecutor.hxx.
auto ROOT::TExecutor< subc >::Map | ( | F | func, |
std::vector< T > & | args | ||
) | -> std::vector<typename std::result_of<F(T)>::type> |
Execute func in parallel, taking an element of an std::vector as argument.
A vector containg executions' results is returned.
Definition at line 145 of file TExecutor.hxx.
auto ROOT::TExecutor< subc >::Map | ( | F | func, |
unsigned | nTimes | ||
) | -> std::vector<typename std::result_of<F()>::type> |
Execute func (with no arguments) nTimes in parallel.
A vector containg executions' results is returned. Functions that take more than zero arguments can be executed (with fixed arguments) by wrapping them in a lambda or with std::bind.
Definition at line 111 of file TExecutor.hxx.
auto ROOT::TExecutor< subc >::MapReduce | ( | F | func, |
ROOT::TSeq< INTEGER > | args, | ||
R | redfunc | ||
) | -> typename std::result_of<F(INTEGER)>::type |
This method behaves just like Map, but an additional redfunc function must be provided.
redfunc is applied to the vector Map would return and must return the same type as func. In practice, redfunc can be used to "squash" the vector returned by Map into a single object by merging, adding, mixing the elements of the vector.
Definition at line 157 of file TExecutor.hxx.
auto ROOT::TExecutor< subc >::MapReduce | ( | F | func, |
std::initializer_list< T > | args, | ||
R | redfunc | ||
) | -> typename std::result_of<F(T)>::type |
Definition at line 165 of file TExecutor.hxx.
T * ROOT::TExecutor< subc >::MapReduce | ( | F | func, |
std::vector< T * > & | args | ||
) |
Definition at line 172 of file TExecutor.hxx.
T * ROOT::TExecutor< subc >::Reduce | ( | const std::vector< T * > & | mergeObjs | ) |
"Reduce" an std::vector into a single object by using the object's Merge
Definition at line 181 of file TExecutor.hxx.