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< InvokeResult_t< F > >
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) -> InvokeResult_t< F >
Execute a function nTimes in parallel (Map) and accumulate the results into a single value (Reduce).

Definition at line 42 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.
 
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 T , class R , class Cond = validMapReturnCond<F, T>>
auto Map (F func, const std::vector< T > &args, R redfunc, unsigned nChunks) -> std::vector< InvokeResult_t< F, T > >
 Execute a function in parallel over the elements of an immutable vector, dividing the execution in nChunks and providing a result per chunk.
 
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 INTEGER , class R , class Cond = validMapReturnCond<F, INTEGER>>
auto Map (F func, ROOT::TSeq< INTEGER > args, R redfunc, unsigned nChunks) -> std::vector< InvokeResult_t< F, INTEGER > >
 Execute a function in parallel over the elements of a sequence, dividing the execution in nChunks and providing a result per chunk.
 
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 R , class Cond = validMapReturnCond<F, T>>
auto Map (F func, std::initializer_list< T > args, R redfunc, unsigned nChunks) -> std::vector< InvokeResult_t< F, T > >
 Execute a function in parallel over the elements of an initializer_list, dividing the execution in nChunks and providing a result per chunk.
 
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 T , class R , class Cond = validMapReturnCond<F, T>>
auto Map (F func, std::vector< T > &args, R redfunc, unsigned nChunks) -> std::vector< InvokeResult_t< F, T > >
 Execute a function in parallel over the elements of a vector, dividing the execution in nChunks and providing a result per chunk.
 
auto Map (F func, unsigned nTimes) -> std::vector< InvokeResult_t< F > >
 Execute a function without arguments several times.
 
template<class F , class R , class Cond = validMapReturnCond<F>>
auto Map (F func, unsigned nTimes, R redfunc, unsigned nChunks) -> std::vector< InvokeResult_t< F > >
 Execute a function nTimes in parallel, dividing the execution in nChunks and providing a result per chunk.
 
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 in parallel (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, const std::vector< T > &args, R redfunc, unsigned nChunks) -> InvokeResult_t< F, T >
 Execute a function in parallel 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).
 
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 in parallel over the elements of a vector (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).
 
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 in parallel 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).
 
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 in parallel (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 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 = validMapReturnCond<F>>
auto MapReduce (F func, unsigned nTimes, R redfunc) -> InvokeResult_t< F >
 Execute a function nTimes in parallel (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 in parallel over the elements of a vector (Map) and accumulate the results into a single value (Reduce).
 
TThreadExecutor & operator= (const TThreadExecutor &)=delete
 
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 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.
 

Protected Types

using InvokeResult_t
 
using validMapReturnCond
 type definition used in templated functions for not allowing mapping functions that return references or void.
 

Private Member Functions

TThreadExecutor & 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 > >
 Execute a function over the elements of a vector in parallel.
 
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 in parallel.
 
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 in parallel.
 
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 in parallel.
 
void ParallelFor (std::unique_ptr< ROOT::Internal::IMTUtils::RAbstractTBBRangeImpl > rangeImpl, const std::function< void(const ROOT::Internal::IMTUtils::RAbstractTBBRangeImpl &)> &body)
 
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::RTaskArenaWrapper > fTaskArenaW = nullptr
 Pointer to the TBB task arena wrapper.
 
friend TExecutorCRTP
 

Friends

void ROOT::Internal::IMTUtils::ParallelFor (TThreadExecutor &pool, std::unique_ptr< ROOT::Internal::IMTUtils::RAbstractTBBRangeImpl > rangeImpl, const std::function< void(const ROOT::Internal::IMTUtils::RAbstractTBBRangeImpl &)> &body)
 

#include <ROOT/TThreadExecutor.hxx>

Inheritance diagram for ROOT::TThreadExecutor:
[legend]

Member Typedef Documentation

◆ InvokeResult_t

using ROOT::TExecutorCRTP< TThreadExecutor >::InvokeResult_t
protectedinherited

Definition at line 107 of file TExecutorCRTP.hxx.

◆ validMapReturnCond

using ROOT::TExecutorCRTP< TThreadExecutor >::validMapReturnCond
protectedinherited

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.

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 144 of file TThreadExecutor.cxx.

◆ TThreadExecutor() [2/2]

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

Member Function Documentation

◆ Derived()

TThreadExecutor & ROOT::TExecutorCRTP< TThreadExecutor >::Derived ( )
inlineprivateinherited

Definition at line 156 of file TExecutorCRTP.hxx.

◆ 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 236 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 174 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 200 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 212 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 151 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 211 of file TThreadExecutor.cxx.

◆ Map() [1/10]

auto ROOT::TExecutorCRTP< TThreadExecutor >::Map ( F func,
const std::vector< T > & args )-> std::vector<InvokeResult_t<F, T>>
inherited

Execute a function over the elements of an immutable vector.

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 131 of file TExecutorCRTP.hxx.

◆ Map() [2/10]

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<InvokeResult_t<F, T>>

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 441 of file TThreadExecutor.hxx.

◆ Map() [3/10]

auto ROOT::TExecutorCRTP< TThreadExecutor >::Map ( F func,
ROOT::TSeq< INTEGER > args )-> std::vector<InvokeResult_t<F, INTEGER>>
inherited

Execute a function over a sequence of indexes.

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 125 of file TExecutorCRTP.hxx.

◆ Map() [4/10]

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<InvokeResult_t<F, INTEGER>>

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 373 of file TThreadExecutor.hxx.

◆ Map() [5/10]

auto ROOT::TExecutorCRTP< TThreadExecutor >::Map ( F func,
std::initializer_list< T > args )-> std::vector<InvokeResult_t<F, T>>
inherited

Execute a function over the elements of an initializer_list.

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.
Returns
A vector with the results of the function calls.

Definition at line 127 of file TExecutorCRTP.hxx.

◆ Map() [6/10]

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<InvokeResult_t<F, T>>

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 475 of file TThreadExecutor.hxx.

◆ Map() [7/10]

auto ROOT::TExecutorCRTP< TThreadExecutor >::Map ( F func,
std::vector< T > & args )-> std::vector<InvokeResult_t<F, T>>
inherited

Execute a function over the elements of a vector.

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 129 of file TExecutorCRTP.hxx.

◆ Map() [8/10]

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<InvokeResult_t<F, T>>

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 407 of file TThreadExecutor.hxx.

◆ Map() [9/10]

auto ROOT::TExecutorCRTP< TThreadExecutor >::Map ( F func,
unsigned nTimes )-> std::vector<InvokeResult_t<F>>
inherited

Execute a function without arguments several times.

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 123 of file TExecutorCRTP.hxx.

◆ Map() [10/10]

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

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

Definition at line 294 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<InvokeResult_t<F, T>>
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 349 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<InvokeResult_t<F, INTEGER>>
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 278 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<InvokeResult_t<F, T>>
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 325 of file TThreadExecutor.hxx.

◆ MapImpl() [4/4]

template<class F , class Cond >
auto ROOT::TThreadExecutor::MapImpl ( F func,
unsigned nTimes ) -> std::vector<InvokeResult_t<F>>
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 259 of file TThreadExecutor.hxx.

◆ MapReduce() [1/12]

T * ROOT::TExecutorCRTP< TThreadExecutor >::MapReduce ( F func,
const std::vector< T * > & args )
inherited

Execute a function over the TObject-inheriting elements of an immutable vector (Map) and merge the objects into a single one (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 149 of file TExecutorCRTP.hxx.

◆ MapReduce() [2/12]

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

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.
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 540 of file TThreadExecutor.hxx.

◆ MapReduce() [3/12]

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

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 and should be callable with const std::vector<T> where T is the output of 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 562 of file TThreadExecutor.hxx.

◆ MapReduce() [4/12]

auto ROOT::TExecutorCRTP< TThreadExecutor >::MapReduce ( F func,
ROOT::TSeq< INTEGER > args,
R redfunc )-> InvokeResult_t<F, INTEGER>
inherited

Execute a function over a sequence of indexes (Map) and accumulate the results into a single value (Reduce).

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. 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 139 of file TExecutorCRTP.hxx.

◆ MapReduce() [5/12]

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

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 and should be callable with std::vector<T> where T is the output of 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 509 of file TThreadExecutor.hxx.

◆ MapReduce() [6/12]

auto ROOT::TExecutorCRTP< TThreadExecutor >::MapReduce ( F func,
std::initializer_list< T > args,
R redfunc )-> InvokeResult_t<F, T>
inherited

Execute a function over the elements of an initializer_list (Map) and accumulate the results into a single value (Reduce).

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.
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 141 of file TExecutorCRTP.hxx.

◆ MapReduce() [7/12]

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

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 as second 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 and should be callable with const std::vector<T> where T is the output of 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 521 of file TThreadExecutor.hxx.

◆ MapReduce() [8/12]

T * ROOT::TExecutorCRTP< TThreadExecutor >::MapReduce ( F func,
std::vector< T * > & args )
inherited

Execute a function over the TObject-inheriting elements of a vector (Map) and merge the objects into a single one (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.
Returns
A value result of "reducing" the vector returned by the Map operation into a single object.

Definition at line 147 of file TExecutorCRTP.hxx.

◆ MapReduce() [9/12]

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

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 531 of file TThreadExecutor.hxx.

◆ MapReduce() [10/12]

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

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 and should be callable with const std::vector<T> where T is the output of 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 551 of file TThreadExecutor.hxx.

◆ MapReduce() [11/12]

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

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 487 of file TThreadExecutor.hxx.

◆ MapReduce() [12/12]

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

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 and should be callable with const std::vector<T> where T is the output of 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 498 of file TThreadExecutor.hxx.

◆ operator=()

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

◆ ParallelFor() [1/2]

void ROOT::TThreadExecutor::ParallelFor ( std::unique_ptr< ROOT::Internal::IMTUtils::RAbstractTBBRangeImpl > rangeImpl,
const std::function< void(const ROOT::Internal::IMTUtils::RAbstractTBBRangeImpl &)> & body )
private

Definition at line 249 of file TThreadExecutor.cxx.

◆ ParallelFor() [2/2]

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 156 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 178 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 196 of file TThreadExecutor.cxx.

◆ Reduce() [1/3]

T * ROOT::TExecutorCRTP< TThreadExecutor >::Reduce ( const std::vector< T * > & mergeObjs)
inherited

"Reduce" an std::vector into a single object by using the object's Merge method.

Parameters
mergeObjsA vector of ROOT objects implementing the Merge method
Returns
An object result of merging the vector elements into one.

Definition at line 151 of file TExecutorCRTP.hxx.

◆ Reduce() [2/3]

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 586 of file TThreadExecutor.hxx.

◆ Reduce() [3/3]

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 571 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 600 of file TThreadExecutor.hxx.

Friends And Related Symbol Documentation

◆ ROOT::Internal::IMTUtils::ParallelFor

void ROOT::Internal::IMTUtils::ParallelFor ( TThreadExecutor & pool,
std::unique_ptr< ROOT::Internal::IMTUtils::RAbstractTBBRangeImpl > rangeImpl,
const std::function< void(const ROOT::Internal::IMTUtils::RAbstractTBBRangeImpl &)> & body )
friend

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 139 of file TThreadExecutor.hxx.

◆ TExecutorCRTP

friend ROOT::TThreadExecutor::TExecutorCRTP
private

Definition at line 43 of file TThreadExecutor.hxx.

Libraries for ROOT::TThreadExecutor:

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