32 #ifndef VSMC_SMP_BACKEND_BASE_HPP 33 #define VSMC_SMP_BACKEND_BASE_HPP 38 #pragma clang diagnostic push 39 #pragma clang diagnostic ignored "-Wweak-vtables" 44 #ifndef VSMC_SMP_BACKEND 46 #define VSMC_SMP_BACKEND ::vsmc::BackendOMP 48 #define VSMC_SMP_BACKEND ::vsmc::BackendTBB 50 #define VSMC_SMP_BACKEND ::vsmc::BackendSTD 54 #define VSMC_DEFINE_SMP_BACKEND_BASE_SPECIAL(Name) \ 55 Name##Base() = default; \ 56 Name##Base(const Name##Base<T, Derived> &) = default; \ 57 Name##Base<T, Derived> &operator=(const Name##Base<T, Derived> &) = \ 59 Name##Base(Name##Base<T, Derived> &&) = default; \ 60 Name##Base<T, Derived> &operator=(Name##Base<T, Derived> &&) = default; 62 #define VSMC_DEFINE_SMP_BACKEND_BASE_SPECIAL_VIRTUAL(Name) \ 63 Name##Base() = default; \ 64 Name##Base(const Name##Base<T, Virtual> &) = default; \ 65 Name##Base<T, Virtual> &operator=(const Name##Base<T, Virtual> &) = \ 67 Name##Base(Name##Base<T, Virtual> &&) = default; \ 68 Name##Base<T, Virtual> &operator=(Name##Base<T, Virtual> &&) = default; \ 69 virtual ~Name##Base() {} 71 #define VSMC_DEFINE_SMP_BACKEND_SPECIAL(Impl, Name) \ 72 Name##SMP() = default; \ 73 Name##SMP(const Name##SMP<T, Derived, Backend##Impl> &) = default; \ 74 Name##SMP<T, Derived, Backend##Impl> &operator=( \ 75 Name##SMP<T, Derived, Backend##Impl> &) = default; \ 76 Name##SMP(Name##SMP<T, Derived, Backend##Impl> &&) = default; \ 77 Name##SMP<T, Derived, Backend##Impl> &operator=( \ 78 Name##SMP<T, Derived, Backend##Impl> &&) = default; 106 template <
typename T,
typename = Virtual,
typename = VSMC_SMP_BACKEND>
111 template <
typename T,
typename = Virtual,
typename = VSMC_SMP_BACKEND>
116 template <
typename T,
typename Derived>
122 return eval_sp_dispatch(iter, sp, &Derived::eval_sp);
127 return eval_range_dispatch(iter, range, &Derived::eval_range);
132 eval_pre_dispatch(iter, particle, &Derived::eval_pre);
137 eval_post_dispatch(iter, particle, &Derived::eval_post);
146 template <
typename D>
150 return static_cast<Derived *
>(
this)->
eval_sp(iter, sp);
153 template <
typename D>
157 return static_cast<Derived *
>(
this)->
eval_range(iter, range);
160 template <
typename D>
161 void eval_pre_dispatch(std::size_t iter,
Particle<T> &particle,
164 static_cast<Derived *
>(
this)->
eval_pre(iter, particle);
167 template <
typename D>
168 void eval_post_dispatch(std::size_t iter,
Particle<T> &particle,
171 static_cast<Derived *
>(
this)->
eval_post(iter, particle);
176 template <
typename D>
180 return static_cast<Derived *
>(
this)->
eval_sp(iter, sp);
183 template <
typename D>
187 return static_cast<Derived *
>(
this)->
eval_range(iter, range);
190 template <
typename D>
191 void eval_pre_dispatch(std::size_t iter,
Particle<T> &particle,
194 static_cast<Derived *
>(
this)->
eval_pre(iter, particle);
197 template <
typename D>
198 void eval_post_dispatch(std::size_t iter,
Particle<T> &particle,
201 static_cast<Derived *
>(
this)->
eval_post(iter, particle);
209 return Derived::eval_sp(iter, sp);
215 return Derived::eval_range(iter, range);
218 void eval_pre_dispatch(std::size_t iter,
Particle<T> &particle,
221 Derived::eval_pre(iter, particle);
224 void eval_post_dispatch(std::size_t iter,
Particle<T> &particle,
227 Derived::eval_post(iter, particle);
243 std::size_t accept = 0;
244 for (size_type i = range.
begin(); i != range.
end(); ++i)
255 void eval_post_dispatch(std::size_t,
Particle<T> &,
263 template <
typename T>
273 std::size_t accept = 0;
274 for (size_type i = range.
begin(); i != range.
end(); ++i)
290 template <
typename T,
typename Derived>
297 eval_sp_dispatch(iter, dim, sp, r, &Derived::eval_sp);
303 eval_range_dispatch(iter, dim, range, r, &Derived::eval_range);
308 eval_pre_dispatch(iter, particle, &Derived::eval_pre);
313 eval_post_dispatch(iter, particle, &Derived::eval_post);
322 template <
typename D>
323 void eval_sp_dispatch(std::size_t iter, std::size_t dim,
327 static_cast<Derived *
>(
this)->
eval_sp(iter, dim, sp, r);
330 template <
typename D>
331 void eval_range_dispatch(std::size_t iter, std::size_t dim,
335 static_cast<Derived *
>(
this)->
eval_range(iter, dim, range, r);
338 template <
typename D>
339 void eval_pre_dispatch(std::size_t iter,
Particle<T> &particle,
342 static_cast<Derived *
>(
this)->
eval_pre(iter, particle);
345 template <
typename D>
346 void eval_post_dispatch(std::size_t iter,
Particle<T> &particle,
349 static_cast<Derived *
>(
this)->
eval_post(iter, particle);
354 template <
typename D>
355 void eval_sp_dispatch(std::size_t iter, std::size_t dim,
360 static_cast<Derived *
>(
this)->
eval_sp(iter, dim, sp, r);
363 template <
typename D>
364 void eval_range_dispatch(std::size_t iter, std::size_t dim,
369 static_cast<Derived *
>(
this)->
eval_range(iter, dim, range, r);
372 template <
typename D>
373 void eval_pre_dispatch(std::size_t iter,
Particle<T> &particle,
376 static_cast<Derived *
>(
this)->
eval_pre(iter, particle);
379 template <
typename D>
380 void eval_post_dispatch(std::size_t iter,
Particle<T> &particle,
383 static_cast<Derived *
>(
this)->
eval_post(iter, particle);
388 void eval_sp_dispatch(std::size_t iter, std::size_t dim,
392 Derived::eval_sp(iter, dim, sp, r);
395 void eval_range_dispatch(std::size_t iter, std::size_t dim,
399 Derived::eval_range(iter, dim, range, r);
402 void eval_pre_dispatch(std::size_t iter,
Particle<T> &particle,
405 Derived::eval_pre(iter, particle);
408 void eval_post_dispatch(std::size_t iter,
Particle<T> &particle,
411 Derived::eval_post(iter, particle);
422 void eval_range_dispatch(std::size_t iter, std::size_t dim,
429 for (size_type i = range.
begin(); i != range.
end(); ++i, r += dim)
438 void eval_post_dispatch(std::size_t,
Particle<T> &,
446 template <
typename T>
459 for (size_type i = range.
begin(); i != range.
end(); ++i, r += dim)
474 #pragma clang diagnostic pop 477 #endif // VSMC_SMP_BACKEND_BASE_HPP
Particle class representing the whole particle set.
#define VSMC_DEFINE_SMP_BACKEND_BASE_SPECIAL(Name)
virtual void eval_post(std::size_t, Particle< T > &)
Monitor evalution base dispatch class.
void eval_sp(std::size_t iter, std::size_t dim, SingleParticle< T > sp, double *r)
std::size_t eval_sp(std::size_t iter, SingleParticle< T > sp)
void eval_post(std::size_t iter, Particle< T > &particle)
virtual std::size_t eval_sp(std::size_t, SingleParticle< T >)
void eval_range(std::size_t iter, std::size_t dim, ParticleRange< T > range, double *r)
void eval_pre(std::size_t iter, Particle< T > &particle)
std::size_t eval_range(std::size_t iter, ParticleRange< T > range)
Sampler evaluation base dispatch class.
virtual void eval_pre(std::size_t, Particle< T > &)
void eval_post(std::size_t iter, Particle< T > &particle)
#define VSMC_DEFINE_SMP_BACKEND_BASE_SPECIAL_VIRTUAL(Name)
virtual std::size_t eval_range(std::size_t iter, ParticleRange< T > range)
virtual void eval_post(std::size_t, Particle< T > &)
virtual void eval_pre(std::size_t, Particle< T > &)
Particle< T > & particle() const
Particle< T >::size_type begin() const
A thin wrapper over a complete Particle.
virtual void eval_range(std::size_t iter, std::size_t dim, ParticleRange< T > range, double *r)
virtual void eval_sp(std::size_t, std::size_t, SingleParticle< T >, double *)
void eval_pre(std::size_t iter, Particle< T > &particle)
Particle< T >::size_type end() const