32 #ifndef VSMC_SMP_BACKEND_TBB_HPP 33 #define VSMC_SMP_BACKEND_TBB_HPP 36 #include <tbb/blocked_range.h> 37 #include <tbb/parallel_for.h> 38 #include <tbb/parallel_reduce.h> 46 template <
typename IntType>
48 IntType N, std::size_t grainsize)
50 return grainsize == 0 ? ::tbb::blocked_range<IntType>(0, N) :
51 ::tbb::blocked_range<IntType>(0, N, grainsize);
58 template <
typename T,
typename Derived>
65 return run(iter, particle);
78 : wptr_(wptr), iter_(iter), pptr_(pptr), accept_(0)
90 void operator()(const ::tbb::blocked_range<size_type> &range)
92 accept_ += wptr_->eval_range(
93 iter_, pptr_->range(range.begin(), range.end()));
96 void join(
const work_type &other) { accept_ += other.accept_; }
98 std::size_t
accept()
const {
return accept_; }
102 const std::size_t iter_;
107 template <
typename... Args>
109 std::size_t grainsize, Args &&... args)
111 this->eval_pre(iter, particle);
112 work_type work(
this, iter, &particle);
113 ::tbb::parallel_reduce(
115 std::forward<Args>(args)...);
116 this->eval_post(iter, particle);
118 return work.accept();
123 return run(iter, particle, 0);
129 template <
typename T,
typename Derived>
135 std::size_t iter, std::size_t dim,
Particle<T> &particle,
double *r)
137 run(iter, dim, particle, r);
149 std::size_t iter, std::size_t dim,
Particle<T> *pptr,
double *r)
150 : wptr_(wptr), iter_(iter), dim_(dim), pptr_(pptr), r_(r)
154 void operator()(const ::tbb::blocked_range<size_type> &range)
const 156 wptr_->eval_range(iter_, dim_,
157 pptr_->range(range.begin(), range.end()),
158 r_ + static_cast<std::size_t>(range.begin()) * dim_);
163 const std::size_t iter_;
164 const std::size_t dim_;
169 template <
typename... Args>
171 double *r, std::size_t grainsize, Args &&... args)
173 this->eval_pre(iter, particle);
174 work_type work(
this, iter, dim, &particle, r);
177 std::forward<Args>(args)...);
178 this->eval_post(iter, particle);
182 std::size_t iter, std::size_t dim,
Particle<T> &particle,
double *r)
184 run(iter, dim, particle, r, 1);
190 template <
typename T,
typename Derived>
195 template <
typename T,
typename Derived>
200 #endif // VSMC_SMP_BACKEND_TBB_HPP
Particle class representing the whole particle set.
std::size_t run(std::size_t iter, Particle< T > &particle)
work_type(const work_type &other,::tbb::split)
void operator()(const ::tbb::blocked_range< size_type > &range)
Monitor evalution base dispatch class.
std::size_t run(std::size_t iter, Particle< T > &particle, std::size_t grainsize, Args &&...args)
#define VSMC_DEFINE_SMP_BACKEND_SPECIAL(Impl, Name)
void run(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r, std::size_t grainsize, Args &&...args)
std::size_t accept() const
void run(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r)
void operator()(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r)
void operator()(const ::tbb::blocked_range< size_type > &range) const
Sampler<T>::eval_type subtype using Intel Threading Building Blocks.
std::size_t operator()(std::size_t iter, Particle< T > &particle)
work_type(SamplerEvalSMP< T, Derived, BackendTBB > *wptr, std::size_t iter, Particle< T > *pptr)
Sampler evaluation base dispatch class.
typename Particle< T >::size_type size_type
void join(const work_type &other)
size_type size() const
Number of particles.
typename Particle< T >::size_type size_type
Monitor<T>::eval_type subtype using Intel Threading Building Blocks.
work_type(MonitorEvalSMP< T, Derived, BackendTBB > *wptr, std::size_t iter, std::size_t dim, Particle< T > *pptr, double *r)
inline::tbb::blocked_range< IntType > backend_tbb_range(IntType N, std::size_t grainsize)