32 #ifndef MCKL_SMP_BACKEND_OMP_HPP 33 #define MCKL_SMP_BACKEND_OMP_HPP 45 template <
typename IntType>
49 const IntType np =
static_cast<IntType
>(::omp_get_num_threads());
50 const IntType
id =
static_cast<IntType
>(::omp_get_thread_num());
55 const IntType m = N / np;
56 const IntType r = N % np;
57 const IntType n = m + (
id < r ? 1 : 0);
58 ibegin =
id < r ? n * id : (n + 1) * r + n * (
id - r);
66 template <
typename T,
typename Derived>
81 run(iter, particle, 1);
84 template <
typename... Args>
89 this->eval_first(iter, particle);
92 #pragma omp parallel default(none) firstprivate(pptr, iter) 98 this->eval_range(iter, pptr->
range(ibegin, iend));
100 this->eval_last(iter, particle);
106 template <
typename T,
typename Derived>
112 std::size_t iter, std::size_t dim,
Particle<T> &particle,
double *r)
114 run(iter, dim, particle, r);
121 std::
size_t iter,
std::
size_t dim,
Particle<T> &particle,
double *r)
123 run(iter, dim, particle, r, 1);
126 template <
typename... Args>
128 double *r, std::size_t, Args &&...)
132 this->eval_first(iter, particle);
135 #pragma omp parallel default(none) firstprivate(pptr, iter, dim, r) 138 size_type ibegin = 0;
141 this->eval_range(iter, dim, pptr->
range(ibegin, iend),
142 r +
static_cast<std::size_t
>(ibegin) * dim);
144 this->eval_last(iter, particle);
150 template <
typename T,
typename Derived>
155 template <
typename T,
typename Derived>
160 #endif // MCKL_SMP_BACKEND_OMP_HPP SMCSampler evaluation base dispatch class.
void run(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r, std::size_t, Args &&...)
SMCEstimator<T>::eval_type subtype using OpenMP.
void run(std::size_t iter, Particle< T > &particle, std::size_t, Args &&...)
void backend_omp_range(IntType N, IntType &ibegin, IntType &iend)
SMCSMCSampler<T>::eval_type.
void operator()(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r)
ParticleRange< T > range(size_type grainsize=1)
Get a Range<ParticleItrator<T>> object of all particles.
SMCEstimator<T>::eval_type.
size_type size() const
The number of particles.
SMCEstimator evalution base dispatch class.
SMCSampler<T>::eval_type subtype using OpenMP.
void operator()(std::size_t iter, Particle< T > &particle)
#define MCKL_DEFINE_SMP_BACKEND_SPECIAL(Impl, Name)