MCKL
Monte Carlo Kernel Library
backend_seq.hpp
Go to the documentation of this file.
1 //============================================================================
2 // MCKL/include/mckl/smp/backend_seq.hpp
3 //----------------------------------------------------------------------------
4 // MCKL: Monte Carlo Kernel Library
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013-2018, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef MCKL_SMP_BACKEND_SEQ_HPP
33 #define MCKL_SMP_BACKEND_SEQ_HPP
34 
36 
37 namespace mckl {
38 
41 template <typename T, typename Derived>
42 class SMCSamplerEvalSMP<T, Derived, BackendSEQ>
43  : public SMCSamplerEvalBase<T, Derived>
44 {
45  public:
46  void operator()(std::size_t iter, Particle<T> &particle)
47  {
48  run(iter, particle);
49  }
50 
51  protected:
52  MCKL_DEFINE_SMP_BACKEND_SPECIAL(SEQ, SMCSamplerEval)
53 
54  void run(std::size_t iter, Particle<T> &particle)
55  {
56  run(iter, particle, 1);
57  }
58 
59  template <typename... Args>
60  void run(std::size_t iter, Particle<T> &particle, std::size_t, Args &&...)
61  {
62  this->eval_first(iter, particle);
63  this->eval_range(iter, particle.range());
64  this->eval_last(iter, particle);
65  }
66 }; // class SMCSamplerEvalSMP
67 
70 template <typename T, typename Derived>
71 class SMCEstimatorEvalSMP<T, Derived, BackendSEQ>
72  : public SMCEstimatorEvalBase<T, Derived>
73 {
74  public:
75  void operator()(
76  std::size_t iter, std::size_t dim, Particle<T> &particle, double *r)
77  {
78  run(iter, dim, particle, r);
79  }
80 
81  protected:
82  MCKL_DEFINE_SMP_BACKEND_SPECIAL(SEQ, SMCEstimatorEval)
83 
84  void run(
85  std::size_t iter, std::size_t dim, Particle<T> &particle, double *r)
86  {
87  run(iter, dim, particle, r, 1);
88  }
89 
90  template <typename... Args>
91  void run(std::size_t iter, std::size_t dim, Particle<T> &particle,
92  double *r, std::size_t, Args &&...)
93  {
94  this->eval_first(iter, particle);
95  this->eval_range(iter, dim, particle.range(), r);
96  this->eval_last(iter, particle);
97  }
98 }; // class SMCEstimatorEvalSMP
99 
102 template <typename T, typename Derived>
104 
107 template <typename T, typename Derived>
109 
110 } // namespace mckl
111 
112 #endif // MCKL_SMP_BACKEND_SEQ_HPP
SMCSampler evaluation base dispatch class.
void run(std::size_t iter, Particle< T > &particle, std::size_t, Args &&...)
Definition: backend_seq.hpp:60
void operator()(std::size_t iter, Particle< T > &particle)
Definition: backend_seq.hpp:46
STL namespace.
SMCSMCSampler<T>::eval_type.
SMCEstimator<T>::eval_type subtype.
Definition: backend_seq.hpp:71
ParticleRange< T > range(size_type grainsize=1)
Get a Range<ParticleItrator<T>> object of all particles.
Definition: particle.hpp:391
SMCEstimator<T>::eval_type.
SMCSampler<T>::eval_type subtype.
Definition: backend_seq.hpp:42
void run(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r, std::size_t, Args &&...)
Definition: backend_seq.hpp:91
Definition: mcmc.hpp:40
SMCEstimator evalution base dispatch class.
void operator()(std::size_t iter, std::size_t dim, Particle< T > &particle, double *r)
Definition: backend_seq.hpp:75
Particle system.
Definition: particle.hpp:45
#define MCKL_DEFINE_SMP_BACKEND_SPECIAL(Impl, Name)