12 #ifndef ROOT_TThreadExecutor 13 #define ROOT_TThreadExecutor 24 class TThreadExecutor:
public TExecutor<TThreadExecutor> {
26 explicit TThreadExecutor(){
27 fInitTBB.initialize();
30 explicit TThreadExecutor(
size_t nThreads){
31 fInitTBB.initialize(nThreads);
39 template<
class F,
class Cond = noReferenceCond<F>>
42 template<
class F,
class INTEGER,
class Cond = noReferenceCond<F, INTEGER>>
44 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
49 template<
class T,
class BINARYOP>
auto Reduce(
const std::vector<T> &objs, BINARYOP redfunc) -> decltype(redfunc(objs.front(), objs.front()));
53 tbb::task_scheduler_init fInitTBB{tbb::task_scheduler_init::deferred};
63 template<
class F,
class Cond>
66 using retType = decltype(
func());
67 std::vector<retType> reslist(nTimes);
69 tbb::parallel_for(0U, nTimes, [&](
unsigned int i) {
76 template<
class F,
class INTEGER,
class Cond>
79 unsigned start = *args.begin();
80 unsigned end = *args.end();
81 using retType = decltype(
func(start));
82 std::vector<retType> reslist(end-start);
84 tbb::parallel_for(start, end, [&](
unsigned int i) {
96 template<
class F,
class T,
class Cond>
100 using retType = decltype(
func(args.front()));
102 unsigned int fNToProcess = args.size();
103 std::vector<retType> reslist(fNToProcess);
105 tbb::parallel_for(0U, fNToProcess, [&](
size_t i) {
106 reslist[i] =
func(args[i]);
114 template<
class T,
class BINARYOP>
115 auto TThreadExecutor::Reduce(
const std::vector<T> &objs, BINARYOP redfunc) -> decltype(redfunc(objs.front(), objs.front()))
118 static_assert(std::is_same<decltype(redfunc(objs.front(), objs.front())),
T>::value,
"redfunc does not have the correct signature");
119 return tbb::parallel_reduce(tbb::blocked_range<decltype(objs.begin())>(objs.begin(), objs.end()),
T{},
120 [redfunc](tbb::blocked_range<decltype(objs.begin())>
const & range,
T init) {
121 return std::accumulate(range.begin(), range.end(),
init, redfunc);
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
auto Reduce(const std::vector< T > &objs, R redfunc) -> decltype(redfunc(objs))
auto Map(F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >
Execute func (with no arguments) nTimes in parallel.
A pseudo container class which is a generator of indices.
double func(double *x, double *p)