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 argumentsMap(F func, T& args)
: func is executed on each element of the collection of arguments argsFor 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.
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.
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. The signature of the reduce function should be (const std::vector<T>) -> T
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.
Definition at line 37 of file TExecutor.hxx.
Classes | |
struct | MapRetType |
Helper class to get the correct return type from the Map function, necessary to infer the ResolveExecutorAndMap function type. More... | |
struct | MapRetType< F, unsigned > |
Public Member Functions | |
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 = validMapReturnCond<F, T>> | |
auto | MapReduce (F func, const std::vector< T > &args, R redfunc, unsigned nChunks) -> 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, unsigned nChunks) -> 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, unsigned nChunks) -> 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 R , class Cond = validMapReturnCond<F, T>> | |
auto | MapReduce (F func, std::vector< T > &args, R redfunc, unsigned nChunks) -> 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, unsigned nChunks) -> InvokeResult_t< F > |
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. | |
Public Member Functions inherited from ROOT::TExecutorCRTP< TExecutor > | |
TExecutorCRTP ()=default | |
TExecutorCRTP (const TExecutorCRTP &)=delete | |
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. | |
auto | Map (F func, ROOT::TSeq< INTEGER > args) -> std::vector< InvokeResult_t< F, INTEGER > > |
Execute a function over a sequence of indexes. | |
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. | |
auto | Map (F func, std::vector< T > &args) -> std::vector< InvokeResult_t< F, T > > |
Execute a function over the elements of a vector. | |
auto | Map (F func, unsigned nTimes) -> std::vector< InvokeResult_t< F > > |
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) -> InvokeResult_t< F, T > |
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) -> InvokeResult_t< F, INTEGER > |
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) -> InvokeResult_t< F, T > |
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) -> InvokeResult_t< F, T > |
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) -> 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 |
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. | |
Private Types | |
using | Unused_t = ROOT::TSequentialExecutor |
Private Member Functions | |
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 > > |
Execute a function over the elements of an immutable vector. | |
template<class F , class INTEGER , class Cond = validMapReturnCond<F, INTEGER>> | |
auto | MapImpl (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 | MapImpl (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 | MapImpl (F func, unsigned nTimes) -> std::vector< InvokeResult_t< F > > |
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. | |
Private Attributes | |
ROOT::EExecutionPolicy | fExecPolicy |
std::unique_ptr< ROOT::TProcessExecutor > | fProcessExecutor |
std::unique_ptr< ROOT::TSequentialExecutor > | fSequentialExecutor |
std::unique_ptr< ROOT::TThreadExecutor > | fThreadExecutor |
friend | TExecutorCRTP |
Additional Inherited Members | |
Protected Types inherited from ROOT::TExecutorCRTP< TExecutor > | |
using | InvokeResult_t = ROOT::TypeTraits::InvokeResult_t< F, Args... > |
using | validMapReturnCond = std::enable_if_t<!std::is_reference< InvokeResult_t< F, T... > >::value &&!std::is_void< InvokeResult_t< F, T... > >::value > |
type definition used in templated functions for not allowing mapping functions that return references or void. | |
#include <ROOT/TExecutor.hxx>
|
private |
Definition at line 101 of file TExecutor.hxx.
|
inlineexplicit |
Class constructor.
Sets the default execution policy and initializes the corresponding executor. Defaults to multithreaded execution policy if ROOT is compiled with IMT=ON and IsImplicitMTEnabled. Otherwise it defaults to a serial execution policy
nWorkers | [optional] Number of parallel workers, only taken into account if the execution policy is kMultiThread |
Definition at line 45 of file TExecutor.hxx.
|
explicit |
Class constructor.
Sets the execution policy and initializes the corresponding executor.
execPolicy | Execution policy(kMultiThread, kMultiprocess, kSerial) to process the data |
nWorkers | [optional] Number of parallel workers, only taken into account if the execution policy is kMultiThread |
Definition at line 78 of file TExecutor.cxx.
|
delete |
|
inline |
Return the number of pooled workers.
Definition at line 320 of file TExecutor.hxx.
|
private |
Execute a function over the elements of an immutable vector.
Implementation of the Map method.
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 195 of file TExecutor.hxx.
|
private |
Execute a function over a sequence of indexes.
Implementation of the Map method.
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 173 of file TExecutor.hxx.
|
private |
Execute a function over the elements of a vector.
Implementation of the Map method.
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 184 of file TExecutor.hxx.
|
private |
Execute a function without arguments several times.
Implementation of the Map method.
func | Function to be executed. |
nTimes | Number of times function should be called. |
Definition at line 162 of file TExecutor.hxx.
auto ROOT::Internal::TExecutor::MapReduce | ( | F | func, |
const std::vector< T > & | args, | ||
R | redfunc, | ||
unsigned | nChunks | ||
) | -> InvokeResult_t<F, T> |
Execute a function over the elements of an immutable vector (Map) and accumulate the results into a single value (Reduce).
Benefits from partial reduction into nChunks
intermediate results if the execution policy is multithreaded. Otherwise, it ignores the nChunks argument and performs a normal MapReduce operation.
func | Function to be executed. Must take an element of the sequence passed assecond argument as a parameter. |
args | Immutable vector, whose elements are passed as an argument to func . |
redfunc | Reduction function to combine the results of the calls to func into partial results, and these into a final result. Must return the same type as func and should be callable with const std::vector<T> where T is the output of func . |
nChunks | Number of chunks to split the input data for processing. |
Definition at line 305 of file TExecutor.hxx.
auto ROOT::Internal::TExecutor::MapReduce | ( | F | func, |
ROOT::TSeq< INTEGER > | args, | ||
R | redfunc, | ||
unsigned | nChunks | ||
) | -> InvokeResult_t<F, INTEGER> |
Execute a function over a sequence of indexes (Map) and accumulate the results into a single value (Reduce).
Benefits from partial reduction into nChunks
intermediate results if the execution policy is multithreaded. Otherwise, it ignores the nChunks argument and performs a normal MapReduce operation.
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 into partial results, and these into a final result. Must return the same type as func and should be callable with std::vector<T> where T is the output of func . |
nChunks | Number of chunks to split the input data for processing. |
Definition at line 236 of file TExecutor.hxx.
auto ROOT::Internal::TExecutor::MapReduce | ( | F | func, |
std::initializer_list< T > | args, | ||
R | redfunc, | ||
unsigned | nChunks | ||
) | -> InvokeResult_t<F, T> |
Execute a function over the elements of an initializer_list (Map) and accumulate the results into a single value (Reduce).
Benefits from partial reduction into nChunks
intermediate results if the execution policy is multithreaded. Otherwise, it ignores the nChunks argument and performs a normal MapReduce operation.
func | Function to be executed. Must take an element of the sequence passed as second argument as a parameter. |
args | initializer_list for a vector to apply func on. |
redfunc | Reduction function to combine the results of the calls to func into partial results, and these into a final result. Must return the same type as func and should be callable with const std::vector<T> where T is the output of func . |
nChunks | Number of chunks to split the input data for processing. |
Definition at line 259 of file TExecutor.hxx.
auto ROOT::Internal::TExecutor::MapReduce | ( | F | func, |
std::vector< T > & | args, | ||
R | redfunc, | ||
unsigned | nChunks | ||
) | -> InvokeResult_t<F, T> |
Execute a function over the elements of a vector (Map) and accumulate the results into a single value (Reduce).
Benefits from partial reduction into nChunks
intermediate results if the execution policy is multithreaded. Otherwise, it ignores the nChunks argument and performs a normal MapReduce operation.
func | Function to be executed. Must take an element of the sequence passed assecond argument as a parameter. |
args | Vector of elements passed as an argument to func . |
redfunc | Reduction function to combine the results of the calls to func into partial results, and these into a final result. Must return the same type as func and should be callable with const std::vector<T> where T is the output of func . |
nChunks | Number of chunks to split the input data for processing. |
Definition at line 282 of file TExecutor.hxx.
auto ROOT::Internal::TExecutor::MapReduce | ( | F | func, |
unsigned | nTimes, | ||
R | redfunc, | ||
unsigned | nChunks | ||
) | -> InvokeResult_t<F> |
Execute a function nTimes
(Map) and accumulate the results into a single value (Reduce).
Benefits from partial reduction into nChunks
intermediate results if the execution policy is multithreaded. Otherwise, it ignores the nChunks argument and performs a normal MapReduce operation.
func | Function to be executed. Must take an element of the sequence passed as second argument as a parameter. |
nTimes | Number of times function should be called. |
redfunc | Reduction function to combine the results of the calls to func into partial results, and these into a final result. Must return the same type as func and should be callable with const std::vector<T> where T is the output of func . |
nChunks | Number of chunks to split the input data for processing. |
Definition at line 213 of file TExecutor.hxx.
|
inline |
Return the execution policy the executor is set to.
Definition at line 57 of file TExecutor.hxx.
|
inlineprivate |
Function called from Map to select and execute the correct Executor according to the set Execution Policy.
Definition at line 136 of file TExecutor.hxx.
|
private |
Definition at line 97 of file TExecutor.hxx.
|
private |
Definition at line 114 of file TExecutor.hxx.
|
private |
Definition at line 115 of file TExecutor.hxx.
|
private |
Definition at line 113 of file TExecutor.hxx.
|
private |
Definition at line 38 of file TExecutor.hxx.