32 #ifndef MCKL_SMP_BACKEND_STD_HPP 33 #define MCKL_SMP_BACKEND_STD_HPP 55 void reset() { np_ = std::thread::hardware_concurrency(); }
57 unsigned np()
const {
return np_; }
59 void np(
unsigned n) { np_ = n; }
64 BackendSTD() : np_(std::thread::hardware_concurrency()) {}
72 const std::size_t N =
static_cast<std::size_t
>(particle.
size());
75 const std::size_t m = N / n;
76 const std::size_t r = N % n;
81 for (std::size_t i = 0; i != n; ++i) {
82 const std::size_t l = m + (i < r ? 1 : 0);
83 range.emplace_back(b, b + l);
94 template <
typename T,
typename Derived>
109 run(iter, particle, 1);
112 template <
typename... Args>
115 this->eval_first(iter, particle);
118 task_group.push_back(std::async(
119 std::launch::async, [
this, iter, &particle, range]() {
120 this->eval_range(iter, range);
123 for (
auto &task : task_group) {
126 this->eval_last(iter, particle);
132 template <
typename T,
typename Derived>
138 std::size_t iter, std::size_t dim,
Particle<T> &particle,
double *r)
140 run(iter, dim, particle, r);
147 std::
size_t iter,
std::
size_t dim,
Particle<T> &particle,
double *r)
149 run(iter, dim, particle, r, 1);
152 template <
typename... Args>
154 double *r, std::size_t, Args &&...)
156 this->eval_first(iter, particle);
159 task_group.push_back(std::async(
160 std::launch::async, [
this, iter, dim, &particle, r, range]() {
161 this->eval_range(iter, dim, range,
162 r + static_cast<std::size_t>(range.ibegin()) * dim);
165 for (
auto &task : task_group) {
168 this->eval_last(iter, particle);
174 template <
typename T,
typename Derived>
179 template <
typename T,
typename Derived>
184 #endif // MCKL_SMP_BACKEND_STD_HPP SMCSampler evaluation base dispatch class.
SMCEstimator<T>::eval_type subtype using the standard library.
BackendSTD & operator=(const BackendSTD &)=delete
void operator()(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r)
std::vector< T, Alloc > Vector
std::vector with Allocator as the default allocator
void run(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r, std::size_t, Args &&...)
ParticleIndex< T > begin()
Get a ParticleIndex<T> object for the first particle.
SMCSMCSampler<T>::eval_type.
SMCEstimator<T>::eval_type.
SMCSampler<T>::eval_type subtype using the standard library.
size_type size() const
The number of particles.
SMCEstimator evalution base dispatch class.
mckl::Vector< ParticleRange< T > > backend_std_range(Particle< T > &particle)
A thin wrapper over a complete Particle.
void operator()(std::size_t iter, Particle< T > &particle)
static BackendSTD & instance()
#define MCKL_DEFINE_SMP_BACKEND_SPECIAL(Impl, Name)
void run(std::size_t iter, Particle< T > &particle, std::size_t, Args &&...)