32 #ifndef VSMC_SMP_BACKEND_OMP_HPP 33 #define VSMC_SMP_BACKEND_OMP_HPP 44 template <
typename IntType>
47 const IntType np =
static_cast<IntType
>(::omp_get_num_threads());
48 const IntType
id =
static_cast<IntType
>(::omp_get_thread_num());
49 const IntType m = N / np;
50 const IntType r = N % np;
51 const IntType n = m + (
id < r ? 1 : 0);
52 begin =
id < r ? n *
id : (n + 1) * r + n * (
id - r);
60 template <
typename T,
typename Derived>
69 this->eval_pre(iter, particle);
70 std::size_t accept = 0;
72 #pragma omp parallel default(none) shared(accept) firstprivate(pptr, iter) 77 std::size_t acc = this->eval_range(iter, pptr->
range(begin, end));
81 this->eval_post(iter, particle);
92 template <
typename T,
typename Derived>
98 std::size_t iter, std::size_t dim,
Particle<T> &particle,
double *r)
102 this->eval_pre(iter, particle);
104 #pragma omp parallel default(none) firstprivate(pptr, iter, dim, r) 109 this->eval_range(iter, dim, pptr->
range(begin, end),
110 r +
static_cast<std::size_t
>(begin) * dim);
112 this->eval_post(iter, particle);
121 template <
typename T,
typename Derived>
126 template <
typename T,
typename Derived>
131 #endif // VSMC_SMP_BACKEND_OMP_HPP range_type range(size_type begin, size_type end)
Get a ParticleRange<T> object.
Particle class representing the whole particle set.
void operator()(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r)
Monitor evalution base dispatch class.
std::size_t operator()(std::size_t iter, Particle< T > &particle)
#define VSMC_DEFINE_SMP_BACKEND_SPECIAL(Impl, Name)
Monitor<T>::eval_type subtype using OpenMP.
void backend_omp_range(IntType N, IntType &begin, IntType &end)
Sampler evaluation base dispatch class.
Sampler<T>::eval_type subtype using OpenMP.
size_type size() const
Number of particles.