Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::TThreadExecutor Class Reference

This class provides a simple interface to execute the same task multiple times in parallel threads, possibly with different arguments every time.

ROOT::TThreadExecutor::Map

This class inherits its interfaces from ROOT::TExecutorCRTP
, adapting them for multithreaded parallelism and extends them supporting:

  • Parallel Foreach operations.
  • Custom task granularity and partial reduction, by specifying reduction function and the number of chunks as extra parameters for the Map call. This is specially useful to reduce the size of intermediate results when dealing with a sizeable number of elements in the input data.

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

For either signature, func is executed as many times as needed by a pool of nThreads threads, where nThreads typically 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::TThreadExecutor never deletes what it returns, it simply forgets it.

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

Examples:

root[] ROOT::TThreadExecutor pool; auto hists = pool.Map(CreateHisto, 10);
root[] ROOT::TThreadExecutor pool(2); auto squares = pool.Map([](int a) { return a*a; }, {1,2,3});
#define a(i)
Definition RSha256.hxx:99
This class provides a simple interface to execute the same task multiple times in parallel threads,...
auto Map(F func, unsigned nTimes, R redfunc, unsigned nChunks) -> std::vector< typename std::result_of< F()>::type >
Execute a function nTimes in parallel, dividing the execution in nChunks and providing a result per c...

ROOT::TThreadExecutor::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.

If this function is a binary operator, the "squashing" will be performed in parallel. This is exclusive to ROOT::TThreadExecutor and not any other ROOT::TExecutorCRTP-derived classes.
An integer can be passed as the fourth argument indicating the number of chunks we want to divide our work in. This may be useful to avoid the overhead introduced when running really short tasks.

Examples:

root[] ROOT::TThreadExecutor pool; auto ten = pool.MapReduce([]() { return 1; }, 10, [](const std::vector<int> &v) { return std::accumulate(v.begin(), v.end(), 0); })
root[] ROOT::TThreadExecutor pool; auto hist = pool.MapReduce(CreateAndFillHists, 10, PoolUtils::ReduceObjects);
Merge collection of TObjects.
Definition PoolUtils.h:35
auto MapReduce(F func, unsigned nTimes, R redfunc) -> typename std::result_of< F()>::type
Execute a function nTimes in parallel (Map) and accumulate the results into a single value (Reduce).

Definition at line 40 of file TThreadExecutor.hxx.

Public Member Functions

 TThreadExecutor (const TThreadExecutor &)=delete
 
 TThreadExecutor (UInt_t nThreads=0u)
 Class constructor.
 
template<class F , class T >
void Foreach (F func, const std::vector< T > &args, unsigned nChunks=0)
 Execute a function in parallel over the elements of a immutable vector, dividing the execution in nChunks.
 
template<class F , class INTEGER >
void Foreach (F func, ROOT::TSeq< INTEGER > args, unsigned nChunks=0)
 Execute a function in parallel over a sequence of indexes, dividing the execution in nChunks.
 
template<class F , class T >
void Foreach (F func, std::initializer_list< T > args, unsigned nChunks=0)
 Execute a function in parallel over the elements of an initializer_list, dividing the execution in nChunks.
 
template<class F , class T >
void Foreach (F func, std::vector< T > &args, unsigned nChunks=0)
 Execute a function in parallel over the elements of a vector, dividing the execution in nChunks.
 
template<class F >
void Foreach (F func, unsigned nTimes, unsigned nChunks=0)
 Execute a function without arguments several times in parallel, dividing the execution in nChunks.
 
unsigned GetPoolSize () const
 Returns the number of worker threads in the task arena.
 
template<class F , class T , class R , class Cond = noReferenceCond<F, T>>
auto MapReduce (F func, const std::vector< T > &args, R redfunc) -> typename std::result_of< F(T)>::type
 Execute a function over the elements of an immutable vector in parallel (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, const std::vector< T > &args, R redfunc, unsigned nChunks) -> typename std::result_of< F(T)>::type
 Execute a function in parallel 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, unsigned nChunks) -> typename std::result_of< F(INTEGER)>::type
 Execute a function in parallel over the elements of a vector (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, unsigned nChunks) -> typename std::result_of< F(T)>::type
 Execute a function in parallel 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 = noReferenceCond<F, T>>
auto MapReduce (F func, std::vector< T > &args, R redfunc) -> typename std::result_of< F(T)>::type
 Execute a function over the elements of a vector in parallel (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::vector< T > &args, R redfunc, unsigned nChunks) -> typename std::result_of< F(T)>::type
 Execute a function in parallel 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) -> typename std::result_of< F()>::type
 Execute a function nTimes in parallel (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, unsigned nChunks) -> typename std::result_of< F()>::type
 Execute a function in parallel over the elements of a vector (Map) and accumulate the results into a single value (Reduce).
 
TThreadExecutoroperator= (const TThreadExecutor &)=delete
 
template<class T , class BINARYOP >
auto Reduce (const std::vector< T > &objs, BINARYOP redfunc) -> decltype(redfunc(objs.front(), objs.front()))
 "Reduce" an std::vector into a single object in parallel by passing a binary function as the second argument defining the reduction operation.
 
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.
 
- Public Member Functions inherited from ROOT::TExecutorCRTP< TThreadExecutor >
 TExecutorCRTP ()=default
 
 TExecutorCRTP (const TExecutorCRTP &)=delete
 
auto Map (F func, const std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type >
 Execute a function over the elements of an immutable vector.
 
auto Map (F func, ROOT::TSeq< INTEGER > args) -> std::vector< typename std::result_of< F(INTEGER)>::type >
 Execute a function over a sequence of indexes.
 
auto Map (F func, std::initializer_list< T > args) -> std::vector< typename std::result_of< F(T)>::type >
 Execute a function over the elements of an initializer_list.
 
auto Map (F func, std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type >
 Execute a function over the elements of a vector.
 
auto Map (F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >
 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) -> typename std::result_of< F(T)>::type
 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) -> typename std::result_of< F(INTEGER)>::type
 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) -> typename std::result_of< F(T)>::type
 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) -> typename std::result_of< F(T)>::type
 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) -> typename std::result_of< F()>::type
 Execute a function without arguments several times (Map) and accumulate the results into a single value (Reduce).
 
TExecutorCRTPoperator= (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 Member Functions

template<class F , class T , class R , class Cond = noReferenceCond<F, T>>
auto Map (F func, const std::vector< T > &args, R redfunc, unsigned nChunks) -> std::vector< typename std::result_of< F(T)>::type >
 Execute a function in parallel over the elements of an immutable vector, dividing the execution in nChunks and providing a result per chunk.
 
template<class F , class INTEGER , class R , class Cond = noReferenceCond<F, INTEGER>>
auto Map (F func, ROOT::TSeq< INTEGER > args, R redfunc, unsigned nChunks) -> std::vector< typename std::result_of< F(INTEGER)>::type >
 Execute a function in parallel over the elements of a sequence, dividing the execution in nChunks and providing a result per chunk.
 
template<class F , class T , class R , class Cond = noReferenceCond<F, T>>
auto Map (F func, std::initializer_list< T > args, R redfunc, unsigned nChunks) -> std::vector< typename std::result_of< F(T)>::type >
 Execute a function in parallel over the elements of an initializer_list, dividing the execution in nChunks and providing a result per chunk.
 
template<class F , class T , class R , class Cond = noReferenceCond<F, T>>
auto Map (F func, std::vector< T > &args, R redfunc, unsigned nChunks) -> std::vector< typename std::result_of< F(T)>::type >
 Execute a function in parallel over the elements of a vector, dividing the execution in nChunks and providing a result per chunk.
 
template<class F , class R , class Cond = noReferenceCond<F>>
auto Map (F func, unsigned nTimes, R redfunc, unsigned nChunks) -> std::vector< typename std::result_of< F()>::type >
 Execute a function nTimes in parallel, dividing the execution in nChunks and providing a result per chunk.
 
template<class F , class T , class Cond = noReferenceCond<F, T>>
auto MapImpl (F func, const std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type >
 Execute a function over the elements of a vector in parallel.
 
template<class F , class INTEGER , class Cond = noReferenceCond<F, INTEGER>>
auto MapImpl (F func, ROOT::TSeq< INTEGER > args) -> std::vector< typename std::result_of< F(INTEGER)>::type >
 Execute a function over a sequence of indexes in parallel.
 
template<class F , class T , class Cond = noReferenceCond<F, T>>
auto MapImpl (F func, std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type >
 Execute a function over the elements of a vector in parallel.
 
template<class F , class Cond = noReferenceCond<F>>
auto MapImpl (F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >
 Execute a function without arguments several times in parallel.
 
void ParallelFor (unsigned start, unsigned end, unsigned step, const std::function< void(unsigned int i)> &f)
 Execute a function in parallel over the indices of a loop.
 
double ParallelReduce (const std::vector< double > &objs, const std::function< double(double a, double b)> &redfunc)
 "Reduce" in parallel an std::vector<double> into a single double value
 
float ParallelReduce (const std::vector< float > &objs, const std::function< float(float a, float b)> &redfunc)
 "Reduce" in parallel an std::vector<float> into a single float value
 
template<class T , class R >
auto SeqReduce (const std::vector< T > &objs, R redfunc) -> decltype(redfunc(objs))
 "Reduce", sequentially, an std::vector into a single object
 

Private Attributes

std::shared_ptr< ROOT::Internal::RTaskArenaWrapperfTaskArenaW = nullptr
 Pointer to the TBB task arena wrapper.
 
friend TExecutorCRTP
 

Additional Inherited Members

- Public Types inherited from ROOT::TExecutorCRTP< TThreadExecutor >
using noReferenceCond = typename std::enable_if<"Function can't return a reference" &&!(std::is_reference< typename std::result_of< F(T...)>::type >::value)>::type
 type definition in used in templated functions for not allowing mapping functions that return references.
 

#include <ROOT/TThreadExecutor.hxx>

Inheritance diagram for ROOT::TThreadExecutor:
[legend]

Constructor & Destructor Documentation

◆ TThreadExecutor() [1/2]

ROOT::TThreadExecutor::TThreadExecutor ( UInt_t  nThreads = 0u)
explicit

Class constructor.

If the scheduler is active (e.g. because another TThreadExecutor is in flight, or ROOT::EnableImplicitMT() was called), work with the current pool of threads. If not, initialize the pool of threads, spawning nThreads. nThreads' default value, 0, initializes the pool with as many logical threads as are available in the system (see NLogicalCores in RTaskArenaWrapper.cxx).

At construction time, TThreadExecutor automatically enables ROOT's thread-safety locks as per calling ROOT::EnableThreadSafety().

Definition at line 149 of file TThreadExecutor.cxx.

◆ TThreadExecutor() [2/2]

ROOT::TThreadExecutor::TThreadExecutor ( const TThreadExecutor )
delete

Member Function Documentation

◆ Foreach() [1/5]

template<class F , class T >
void ROOT::TThreadExecutor::Foreach ( F  func,
const std::vector< T > &  args,
unsigned  nChunks = 0 
)

Execute a function in parallel over the elements of a immutable vector, dividing the execution in nChunks.

Parameters
funcFunction to be executed on the elements of the vector passed as second parameter.
argsImmutable vector of elements passed as an argument to func.
nChunksNumber of chunks to split the input data for processing.

Definition at line 228 of file TThreadExecutor.hxx.

◆ Foreach() [2/5]

template<class F , class INTEGER >
void ROOT::TThreadExecutor::Foreach ( F  func,
ROOT::TSeq< INTEGER >  args,
unsigned  nChunks = 0 
)

Execute a function in parallel over a sequence of indexes, dividing the execution in nChunks.

Parameters
funcFunction to be executed. Must take an element of the sequence passed assecond argument as a parameter.
argsSequence of indexes to execute func on.
nChunksNumber of chunks to split the input data for processing.

Definition at line 166 of file TThreadExecutor.hxx.

◆ Foreach() [3/5]

template<class F , class T >
void ROOT::TThreadExecutor::Foreach ( F  func,
std::initializer_list< T >  args,
unsigned  nChunks = 0 
)

Execute a function in parallel over the elements of an initializer_list, dividing the execution in nChunks.

Parameters
funcFunction to be executed on the elements of the initializer_list passed as second parameter.
argsinitializer_list for a vector to apply func on.
nChunksNumber of chunks to split the input data for processing.

Definition at line 192 of file TThreadExecutor.hxx.

◆ Foreach() [4/5]

template<class F , class T >
void ROOT::TThreadExecutor::Foreach ( F  func,
std::vector< T > &  args,
unsigned  nChunks = 0 
)

Execute a function in parallel over the elements of a vector, dividing the execution in nChunks.

Parameters
funcFunction to be executed on the elements of the vector passed as second parameter.
argsVector of elements passed as an argument to func.
nChunksNumber of chunks to split the input data for processing.

Definition at line 204 of file TThreadExecutor.hxx.

◆ Foreach() [5/5]

template<class F >
void ROOT::TThreadExecutor::Foreach ( F  func,
unsigned  nTimes,
unsigned  nChunks = 0 
)

Execute a function without arguments several times in parallel, dividing the execution in nChunks.

Parameters
funcFunction to be executed.
nTimesNumber of times function should be called.
nChunksNumber of chunks to split the input data for processing.

Definition at line 143 of file TThreadExecutor.hxx.

◆ GetPoolSize()

unsigned ROOT::TThreadExecutor::GetPoolSize ( ) const

Returns the number of worker threads in the task arena.

Returns
the number of worker threads assigned to the task arena.

Definition at line 216 of file TThreadExecutor.cxx.

◆ Map() [1/5]

template<class F , class T , class R , class Cond >
auto ROOT::TThreadExecutor::Map ( F  func,
const std::vector< T > &  args,
R  redfunc,
unsigned  nChunks 
) -> std::vector<typename std::result_of<F(T)>::type>
private

Execute a function in parallel over the elements of an immutable vector, dividing the execution in nChunks and providing a result per chunk.

Definition at line 434 of file TThreadExecutor.hxx.

◆ Map() [2/5]

template<class F , class INTEGER , class R , class Cond >
auto ROOT::TThreadExecutor::Map ( F  func,
ROOT::TSeq< INTEGER >  args,
R  redfunc,
unsigned  nChunks 
) -> std::vector<typename std::result_of<F(INTEGER)>::type>
private

Execute a function in parallel over the elements of a sequence, dividing the execution in nChunks and providing a result per chunk.

Definition at line 367 of file TThreadExecutor.hxx.

◆ Map() [3/5]

template<class F , class T , class R , class Cond >
auto ROOT::TThreadExecutor::Map ( F  func,
std::initializer_list< T >  args,
R  redfunc,
unsigned  nChunks 
) -> std::vector<typename std::result_of<F(T)>::type>
private

Execute a function in parallel over the elements of an initializer_list, dividing the execution in nChunks and providing a result per chunk.

Definition at line 467 of file TThreadExecutor.hxx.

◆ Map() [4/5]

template<class F , class T , class R , class Cond >
auto ROOT::TThreadExecutor::Map ( F  func,
std::vector< T > &  args,
R  redfunc,
unsigned  nChunks 
) -> std::vector<typename std::result_of<F(T)>::type>
private

Execute a function in parallel over the elements of a vector, dividing the execution in nChunks and providing a result per chunk.

Definition at line 401 of file TThreadExecutor.hxx.

◆ Map() [5/5]

template<class F , class R , class Cond >
auto ROOT::TThreadExecutor::Map ( F  func,
unsigned  nTimes,
R  redfunc,
unsigned  nChunks 
) -> std::vector<typename std::result_of<F()>::type>
private

Execute a function nTimes in parallel, dividing the execution in nChunks and providing a result per chunk.

Definition at line 291 of file TThreadExecutor.hxx.

◆ MapImpl() [1/4]

template<class F , class T , class Cond >
auto ROOT::TThreadExecutor::MapImpl ( F  func,
const std::vector< T > &  args 
) -> std::vector<typename std::result_of<F(T)>::type>
private

Execute a function over the elements of a vector in parallel.

Implementation of the Map method.

Parameters
funcFunction to be executed on the elements of the vector passed as second parameter.
argsVector of elements passed as an argument to func.
Returns
A vector with the results of the function calls.

Definition at line 344 of file TThreadExecutor.hxx.

◆ MapImpl() [2/4]

template<class F , class INTEGER , class Cond >
auto ROOT::TThreadExecutor::MapImpl ( F  func,
ROOT::TSeq< INTEGER >  args 
) -> std::vector<typename std::result_of<F(INTEGER)>::type>
private

Execute a function over a sequence of indexes in parallel.

Implementation of the Map method.

Parameters
funcFunction to be executed. Must take an element of the sequence passed assecond argument as a parameter.
argsSequence of indexes to execute func on.
Returns
A vector with the results of the function calls.

Definition at line 269 of file TThreadExecutor.hxx.

◆ MapImpl() [3/4]

template<class F , class T , class Cond >
auto ROOT::TThreadExecutor::MapImpl ( F  func,
std::vector< T > &  args 
) -> std::vector<typename std::result_of<F(T)>::type>
private

Execute a function over the elements of a vector in parallel.

Implementation of the Map method.

Parameters
funcFunction to be executed on the elements of the vector passed as second parameter.
argsVector of elements passed as an argument to func.
Returns
A vector with the results of the function calls.

Definition at line 321 of file TThreadExecutor.hxx.

◆ MapImpl() [4/4]

template<class F , class Cond >
auto ROOT::TThreadExecutor::MapImpl ( F  func,
unsigned  nTimes 
) -> std::vector<typename std::result_of<F()>::type>
private

Execute a function without arguments several times in parallel.

Implementation of the Map method.

Parameters
funcFunction to be executed.
nTimesNumber of times function should be called.
Returns
A vector with the results of the function calls. Functions that take arguments can be executed (with fixed arguments) by wrapping them in a lambda or with std::bind.

Definition at line 251 of file TThreadExecutor.hxx.

◆ MapReduce() [1/8]

template<class F , class T , class R , class Cond >
auto ROOT::TThreadExecutor::MapReduce ( F  func,
const std::vector< T > &  args,
R  redfunc 
) -> typename std::result_of<F(T)>::type

Execute a function over the elements of an immutable vector in parallel (Map) and accumulate the results into a single value (Reduce).

Parameters
funcFunction to be executed on the elements of the vector passed as second parameter.
argsImmutable vector of elements passed as an argument to func.
Returns
A value result of "reducing" the vector returned by the Map operation into a single object.

Definition at line 523 of file TThreadExecutor.hxx.

◆ MapReduce() [2/8]

template<class F , class T , class R , class Cond >
auto ROOT::TThreadExecutor::MapReduce ( F  func,
const std::vector< T > &  args,
R  redfunc,
unsigned  nChunks 
) -> typename std::result_of<F(T)>::type

Execute a function in parallel 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.

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.

Parameters
funcFunction to be executed. Must take an element of the sequence passed assecond argument as a parameter.
argsImmutable vector, whose elements are passed as an argument to func.
redfuncReduction 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.
nChunksNumber of chunks to split the input data for processing.
Returns
A value result of "reducing" the vector returned by the Map operation into a single object.

Definition at line 543 of file TThreadExecutor.hxx.

◆ MapReduce() [3/8]

template<class F , class INTEGER , class R , class Cond >
auto ROOT::TThreadExecutor::MapReduce ( F  func,
ROOT::TSeq< INTEGER >  args,
R  redfunc,
unsigned  nChunks 
) -> typename std::result_of<F(INTEGER)>::type

Execute a function in parallel over the elements of a vector (Map) and accumulate the results into a single value (Reduce).

Benefits from partial reduction into nChunks intermediate results.

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.

Parameters
funcFunction to be executed. Must take an element of the sequence passed assecond argument as a parameter.
argsSequence of indexes to execute func on.
redfuncReduction 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.
nChunksNumber of chunks to split the input data for processing.
Returns
A value result of "reducing" the vector returned by the Map operation into a single object.

Definition at line 497 of file TThreadExecutor.hxx.

◆ MapReduce() [4/8]

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

Execute a function in parallel 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.

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.

Parameters
funcFunction to be executed. Must take an element of the sequence passed assecond argument as a parameter.
argsinitializer_list for a vector to apply func on.
redfuncReduction 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.
nChunksNumber of chunks to split the input data for processing.
Returns
A value result of "reducing" the vector returned by the Map operation into a single object.

Definition at line 507 of file TThreadExecutor.hxx.

◆ MapReduce() [5/8]

template<class F , class T , class R , class Cond >
auto ROOT::TThreadExecutor::MapReduce ( F  func,
std::vector< T > &  args,
R  redfunc 
) -> typename std::result_of<F(T)>::type

Execute a function over the elements of a vector in parallel (Map) and accumulate the results into a single value (Reduce).

Parameters
funcFunction to be executed on the elements of the vector passed as second parameter.
argsVector of elements passed as an argument to func.
redfuncReduction function to combine the results of the calls to func. Must return the same type as func.
Returns
A value result of "reducing" the vector returned by the Map operation into a single object.

Definition at line 515 of file TThreadExecutor.hxx.

◆ MapReduce() [6/8]

template<class F , class T , class R , class Cond >
auto ROOT::TThreadExecutor::MapReduce ( F  func,
std::vector< T > &  args,
R  redfunc,
unsigned  nChunks 
) -> typename std::result_of<F(T)>::type

Execute a function in parallel over the elements of a vector (Map) and accumulate the results into a single value (Reduce).

Benefits from partial reduction into nChunks intermediate results.

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.

Parameters
funcFunction to be executed. Must take an element of the sequence passed assecond argument as a parameter.
argsVector of elements passed as an argument to func.
redfuncReduction 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.
nChunksNumber of chunks to split the input data for processing.
Returns
A value result of "reducing" the vector returned by the Map operation into a single object.

Definition at line 533 of file TThreadExecutor.hxx.

◆ MapReduce() [7/8]

template<class F , class R , class Cond >
auto ROOT::TThreadExecutor::MapReduce ( F  func,
unsigned  nTimes,
R  redfunc 
) -> typename std::result_of<F()>::type

Execute a function nTimes in parallel (Map) and accumulate the results into a single value (Reduce).

Parameters
funcFunction to be executed.
nTimesNumber of times function should be called.
Returns
A vector with the results of the function calls.
Parameters
redfuncReduction function to combine the results of the calls to func. Must return the same type as func.
Returns
A value result of "reducing" the vector returned by the Map operation into a single object.

Definition at line 477 of file TThreadExecutor.hxx.

◆ MapReduce() [8/8]

template<class F , class R , class Cond >
auto ROOT::TThreadExecutor::MapReduce ( F  func,
unsigned  nTimes,
R  redfunc,
unsigned  nChunks 
) -> typename std::result_of<F()>::type

Execute a function in parallel over the elements of a vector (Map) and accumulate the results into a single value (Reduce).

Benefits from partial reduction into nChunks intermediate results.

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.

Parameters
funcFunction to be executed. Must take an element of the sequence passed as second argument as a parameter.
nTimesNumber of times function should be called.
redfuncReduction 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.
nChunksNumber of chunks to split the input data for processing.
Returns
A value result of "reducing" the vector returned by the Map operation into a single object.

Definition at line 487 of file TThreadExecutor.hxx.

◆ operator=()

TThreadExecutor & ROOT::TThreadExecutor::operator= ( const TThreadExecutor )
delete

◆ ParallelFor()

void ROOT::TThreadExecutor::ParallelFor ( unsigned  start,
unsigned  end,
unsigned  step,
const std::function< void(unsigned int i)> &  f 
)
private

Execute a function in parallel over the indices of a loop.

Parameters
startStart index of the loop.
endEnd index of the loop.
stepStep size of the loop.
ffunction to execute.

Definition at line 161 of file TThreadExecutor.cxx.

◆ ParallelReduce() [1/2]

double ROOT::TThreadExecutor::ParallelReduce ( const std::vector< double > &  objs,
const std::function< double(double a, double b)> &  redfunc 
)
private

"Reduce" in parallel an std::vector<double> into a single double value

Parameters
objsA vector of elements to combine.
redfuncReduction function to combine the elements of the vector objs.
Returns
A value result of combining the vector elements into a single object of the same type.

Definition at line 183 of file TThreadExecutor.cxx.

◆ ParallelReduce() [2/2]

float ROOT::TThreadExecutor::ParallelReduce ( const std::vector< float > &  objs,
const std::function< float(float a, float b)> &  redfunc 
)
private

"Reduce" in parallel an std::vector<float> into a single float value

Parameters
objsA vector of elements to combine.
redfuncReduction function to combine the elements of the vector objs.
Returns
A value result of combining the vector elements into a single object of the same type.

Definition at line 201 of file TThreadExecutor.cxx.

◆ Reduce() [1/2]

template<class T , class BINARYOP >
auto ROOT::TThreadExecutor::Reduce ( const std::vector< T > &  objs,
BINARYOP  redfunc 
) -> decltype(redfunc(objs.front(), objs.front()))

"Reduce" an std::vector into a single object in parallel by passing a binary function as the second argument defining the reduction operation.

Parameters
objsA vector of elements to combine.
redfuncBinary reduction function to combine the elements of the vector objs.
Returns
A value result of combining the vector elements into a single object of the same type.

Definition at line 565 of file TThreadExecutor.hxx.

◆ Reduce() [2/2]

template<class T , class R >
auto ROOT::TThreadExecutor::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.

Parameters
objsA vector of elements to combine.
redfuncReduction function to combine the elements of the vector objs
Returns
A value result of combining the vector elements into a single object of the same type.

Definition at line 550 of file TThreadExecutor.hxx.

◆ SeqReduce()

template<class T , class R >
auto ROOT::TThreadExecutor::SeqReduce ( const std::vector< T > &  objs,
R  redfunc 
) -> decltype(redfunc(objs))
private

"Reduce", sequentially, an std::vector into a single object

Parameters
objsA vector of elements to combine.
redfuncReduction function to combine the elements of the vector objs.
Returns
A value result of combining the vector elements into a single object of the same type.

Definition at line 579 of file TThreadExecutor.hxx.

Member Data Documentation

◆ fTaskArenaW

std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> ROOT::TThreadExecutor::fTaskArenaW = nullptr
private

Pointer to the TBB task arena wrapper.

Definition at line 131 of file TThreadExecutor.hxx.

◆ TExecutorCRTP

friend ROOT::TThreadExecutor::TExecutorCRTP
private

Definition at line 41 of file TThreadExecutor.hxx.

Libraries for ROOT::TThreadExecutor:

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