6 #include "tbb/parallel_for.h" 7 #include "tbb/task_scheduler_init.h" 8 #include "tbb/enumerable_thread_specific.h" 16 template<
typename Impl,
typename... Types>
19 template<
typename Impl,
typename Type,
typename... Rest>
22 using RestType =
typename Impl::template RMType<Impl, Rest...>;
24 using TLSType = tbb::enumerable_thread_specific<Type>;
28 template<
typename F,
typename... Args>
29 typename std::result_of<F(Type&, Args...)>::type
call(
const F& func, Args&& ... args) {
30 return this->m_rest.call(func, std::forward<Type&>(m_tls->local()), std::forward<Args>(args)...);
35 this->m_tls.reset(
new TLSType(f));
42 template<
typename Impl>
49 template<
typename Impl,
typename... Types>
59 template<
typename IndexF,
typename IndexL,
typename IndexS,
typename Func,
typename RM>
60 void parallelFor(IndexF first, IndexL last, IndexS step,
const Func& f, RM& rm) {
62 auto wrapper = [&](Largest i) {
66 if (m_nthreads == -1) {
67 tbb::parallel_for<Largest, decltype(wrapper)>(first, last, step, wrapper);
70 tbb::task_scheduler_init init(m_nthreads);
71 tbb::parallel_for<Largest, decltype(wrapper)>(first, last, step, wrapper);
76 if (m_nthreads == -1) {
77 return tbb::task_scheduler_init::default_num_threads();
void parallelFor(IndexF first, IndexL last, IndexS step, const Func &f, RM &rm)
_TbbParallel(int nthreads=-1)
tbb::enumerable_thread_specific< Type > TLSType
void setFunc(const FuncType &f)
void setNumThreads(int nthreads)
int getNumThreads() const
is_cond<(sizeof(_type_temp) > sizeof(T3)), _type_temp, T3 >::type type
std::unique_ptr< TLSType > m_tls
std::function< Type()> FuncType
typename Impl::template RMType< Impl, Rest... > RestType
std::result_of< F(Type &, Args...)>::type call(const F &func, Args &&...args)