Logo ROOT   6.19/01
Reference Guide
List of all members | Public Types | Public Member Functions | Private Member Functions | List of all members
ROOT::TExecutor< subc > Class Template Reference

template<class subc>
class ROOT::TExecutor< subc >

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.

ROOT::TExecutor::Map

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.

Parameters
funca 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).
argsa 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.

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 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 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 = 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 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 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 Cond = noReferenceCond<F, T>>
T * MapReduce (F func, std::vector< T *> &args)
 
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 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>

Member Typedef Documentation

◆ noReferenceCond

template<class subc>
template<class F , class... T>
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.

Constructor & Destructor Documentation

◆ TExecutor() [1/2]

template<class subc>
ROOT::TExecutor< subc >::TExecutor ( )
explicitdefault

◆ TExecutor() [2/2]

template<class subc>
ROOT::TExecutor< subc >::TExecutor ( size_t  )
inlineexplicit

Definition at line 64 of file TExecutor.hxx.

Member Function Documentation

◆ Derived()

template<class subc>
subc& ROOT::TExecutor< subc >::Derived ( )
inlineprivate

Definition at line 99 of file TExecutor.hxx.

◆ Map() [1/4]

template<class subc >
template<class F , class Cond >
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.

◆ Map() [2/4]

template<class subc >
template<class F , class INTEGER , class Cond >
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.

◆ Map() [3/4]

template<class subc >
template<class F , class T , class Cond >
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 144 of file TExecutor.hxx.

◆ Map() [4/4]

template<class subc>
template<class F , class T , class Cond >
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.

◆ MapReduce() [1/3]

template<class subc >
template<class F , class INTEGER , class R , class Cond >
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 156 of file TExecutor.hxx.

◆ MapReduce() [2/3]

template<class subc >
template<class F , class T , class Cond >
T * ROOT::TExecutor< subc >::MapReduce ( F  func,
std::vector< T *> &  args 
)

Definition at line 171 of file TExecutor.hxx.

◆ MapReduce() [3/3]

template<class subc>
template<class F , class T , class R , class Cond >
auto ROOT::TExecutor< subc >::MapReduce ( F  func,
std::initializer_list< T >  args,
R  redfunc 
) -> typename std::result_of<F(T)>::type

Definition at line 164 of file TExecutor.hxx.

◆ Reduce()

template<class subc >
template<class T >
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 180 of file TExecutor.hxx.


The documentation for this class was generated from the following file: