12 #ifndef ROOT_TThreadExecutor 13 #define ROOT_TThreadExecutor 15 #include "RConfigure.h" 20 # if !defined(__ROOTCLING__) && !defined(G__DICTIONARY) 21 # error "Cannot use ROOT::TThreadExecutor without defining R__USE_IMT." 30 namespace tbb {
class task_scheduler_init;}
34 class TThreadExecutor:
public TExecutor<TThreadExecutor> {
36 friend class ParallelReductionResolver;
39 explicit TThreadExecutor();
41 explicit TThreadExecutor(
size_t nThreads);
43 TThreadExecutor(TThreadExecutor &) =
delete;
44 TThreadExecutor & operator=(TThreadExecutor &) =
delete;
48 template<
class F,
class Cond = noReferenceCond<F>>
51 template<
class F,
class INTEGER,
class Cond = noReferenceCond<F, INTEGER>>
53 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
56 using TExecutor<TThreadExecutor>::Map;
58 template<
class T,
class BINARYOP>
auto Reduce(
const std::vector<T> &objs, BINARYOP redfunc) -> decltype(redfunc(objs.front(), objs.front()));
59 template<
class T,
class R>
auto Reduce(
const std::vector<T> &objs,
R redfunc) -> decltype(redfunc(objs));
62 void ParallelFor(
unsigned start,
unsigned end,
const std::function<
void(
unsigned int i)> &
f);
63 double ParallelReduce(
const std::vector<double> &objs,
const std::function<
double(
double a,
double b)> &redfunc);
64 float ParallelReduce(
const std::vector<float> &objs,
const std::function<
float(
float a,
float b)> &redfunc);
65 template<
class T,
class R>
66 auto SeqReduce(
const std::vector<T> &objs,
R redfunc) -> decltype(redfunc(objs));
67 std::unique_ptr<tbb::task_scheduler_init> fInitTBB;
77 template<
class F,
class Cond>
80 using retType = decltype(
func());
81 std::vector<retType> reslist(nTimes);
83 auto lambda = [&](
unsigned int i){reslist[i] =
func();};
84 ParallelFor(0U, nTimes, lambda);
89 template<
class F,
class INTEGER,
class Cond>
92 unsigned start = *args.begin();
93 unsigned end = *args.end();
94 using retType = decltype(
func(start));
95 std::vector<retType> reslist(end-start);
97 auto lambda = [&](
unsigned int i){reslist[i] =
func(i);};
98 ParallelFor(start, end, lambda);
108 template<
class F,
class T,
class Cond>
112 using retType = decltype(
func(args.front()));
114 unsigned int fNToProcess = args.size();
115 std::vector<retType> reslist(fNToProcess);
117 auto lambda = [&](
unsigned int i){reslist[i] =
func(args[i]);};
118 ParallelFor(0U, fNToProcess, lambda);
126 template<
class T,
class BINARYOP>
127 auto TThreadExecutor::Reduce(
const std::vector<T> &objs, BINARYOP redfunc) -> decltype(redfunc(objs.front(), objs.front()))
130 static_assert(std::is_same<decltype(redfunc(objs.front(), objs.front())),
T>::value,
"redfunc does not have the correct signature");
131 return ParallelReduce(objs, redfunc);
134 template<
class T,
class R>
135 auto TThreadExecutor::Reduce(
const std::vector<T> &objs,
R redfunc) -> decltype(redfunc(objs))
138 static_assert(std::is_same<decltype(redfunc(objs)),
T>::value,
"redfunc does not have the correct signature");
139 return SeqReduce(objs, redfunc);
142 template<
class T,
class R>
143 auto TThreadExecutor::SeqReduce(
const std::vector<T> &objs,
R redfunc) -> decltype(redfunc(objs))
145 return redfunc(objs);
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
A pseudo container class which is a generator of indices.
double func(double *x, double *p)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b