vSMC
vSMC: Scalable Monte Carlo
backend_base.hpp
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/smp/backend_base.hpp
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013-2015, 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 VSMC_SMP_BACKEND_BASE_HPP
33 #define VSMC_SMP_BACKEND_BASE_HPP
34 
35 #include <vsmc/internal/common.hpp>
36 
37 #if VSMC_NO_RUNTIME_ASSERT
38 #define VSMC_BACKEND_BASE_DESTRUCTOR_PREFIX
39 #else
40 #define VSMC_BACKEND_BASE_DESTRUCTOR_PREFIX virtual
41 #endif
42 
43 #define VSMC_DEFINE_SMP_BACKEND_BASE_SPECIAL(Name) \
44  Name##Base() = default; \
45  Name##Base(const Name##Base<T, Derived> &) = default; \
46  Name##Base<T, Derived> &operator=(const Name##Base<T, Derived> &) = \
47  default; \
48  Name##Base(Name##Base<T, Derived> &&) = default; \
49  Name##Base<T, Derived> &operator=(Name##Base<T, Derived> &&) = default; \
50  VSMC_BACKEND_BASE_DESTRUCTOR_PREFIX ~Name##Base() {}
51 
52 #define VSMC_DEFINE_SMP_BACKEND_BASE_SPECIAL_VIRTUAL(Name) \
53  Name##Base() = default; \
54  Name##Base(const Name##Base<T, Virtual> &) = default; \
55  Name##Base<T, Virtual> &operator=(const Name##Base<T, Virtual> &) = \
56  default; \
57  Name##Base(Name##Base<T, Virtual> &&) = default; \
58  Name##Base<T, Virtual> &operator=(Name##Base<T, Virtual> &&) = default; \
59  virtual ~Name##Base() {}
60 
61 #define VSMC_DEFINE_SMP_BACKEND_SPECIAL(SMP, Name) \
62  Name##SMP() = default; \
63  Name##SMP(const Name##SMP<T, Derived> &) = default; \
64  Name##SMP<T, Derived> &operator=(Name##SMP<T, Derived> &) = default; \
65  Name##SMP(Name##SMP<T, Derived> &&) = default; \
66  Name##SMP<T, Derived> &operator=(Name##SMP<T, Derived> &&) = default; \
67  ~Name##SMP() {}
68 
69 #define VSMC_DEFINE_SMP_BACKEND_FORWARD(Name) \
70  template <typename T, typename = Virtual> \
71  class Initialize##Name; \
72  template <typename T, typename = Virtual> \
73  class Move##Name; \
74  template <typename T, typename = Virtual> \
75  class MonitorEval##Name; \
76  template <typename T, typename = Virtual> \
77  class PathEval##Name;
78 
79 #define VSMC_RUNTIME_ASSERT_SMP_BACKEND_BASE_DERIVED(basename) \
80  VSMC_RUNTIME_ASSERT((dynamic_cast<Derived *>(this) != nullptr), \
81  "DERIVED FROM " #basename \
82  " WITH INCORRECT **Derived** TEMPLATE PARAMTER");
83 
84 namespace vsmc
85 {
86 
90 class Virtual;
91 
94 template <typename T, typename Derived>
96 {
97  public:
98  std::size_t eval_sp(SingleParticle<T> sp)
99  {
100  return eval_sp_dispatch(sp, &Derived::eval_sp);
101  }
102 
103  void eval_param(Particle<T> &particle, void *param)
104  {
105  eval_param_dispatch(particle, param, &Derived::eval_param);
106  }
107 
108  void eval_pre(Particle<T> &particle)
109  {
110  eval_pre_dispatch(particle, &Derived::eval_pre);
111  }
112 
113  void eval_post(Particle<T> &particle)
114  {
115  eval_post_dispatch(particle, &Derived::eval_post);
116  }
117 
118  protected:
120 
121  private:
122  // non-static non-const
123 
124  template <typename D>
125  std::size_t eval_sp_dispatch(
126  SingleParticle<T> sp, std::size_t (D::*)(SingleParticle<T>))
127  {
128  return static_cast<Derived *>(this)->eval_sp(sp);
129  }
130 
131  template <typename D>
132  void eval_param_dispatch(
133  Particle<T> &particle, void *param, void (D::*)(Particle<T> &, void *))
134  {
135  static_cast<Derived *>(this)->eval_param(particle, param);
136  }
137 
138  template <typename D>
139  void eval_pre_dispatch(Particle<T> &particle, void (D::*)(Particle<T> &))
140  {
141  static_cast<Derived *>(this)->eval_pre(particle);
142  }
143 
144  template <typename D>
145  void eval_post_dispatch(Particle<T> &particle, void (D::*)(Particle<T> &))
146  {
147  static_cast<Derived *>(this)->eval_post(particle);
148  }
149 
150  // non-static const
151 
152  template <typename D>
153  std::size_t eval_sp_dispatch(
154  SingleParticle<T> sp, std::size_t (D::*)(SingleParticle<T>) const)
155  {
156  return static_cast<Derived *>(this)->eval_sp(sp);
157  }
158 
159  template <typename D>
160  void eval_param_dispatch(Particle<T> &particle, void *param,
161  void (D::*)(Particle<T> &, void *) const)
162  {
163  static_cast<Derived *>(this)->eval_param(particle, param);
164  }
165 
166  template <typename D>
167  void eval_pre_dispatch(
168  Particle<T> &particle, void (D::*)(Particle<T> &) const)
169  {
170  static_cast<Derived *>(this)->eval_pre(particle);
171  }
172 
173  template <typename D>
174  void eval_post_dispatch(
175  Particle<T> &particle, void (D::*)(Particle<T> &) const)
176  {
177  static_cast<Derived *>(this)->eval_post(particle);
178  }
179 
180  // static
181 
182  std::size_t eval_sp_dispatch(
183  SingleParticle<T> sp, std::size_t (*)(SingleParticle<T>))
184  {
185  return Derived::eval_sp(sp);
186  }
187 
188  void eval_param_dispatch(
189  Particle<T> &particle, void *param, void (*)(Particle<T> &, void *))
190  {
191  Derived::eval_param(particle, param);
192  }
193 
194  void eval_pre_dispatch(Particle<T> &particle, void (*)(Particle<T> &))
195  {
196  Derived::eval_pre(particle);
197  }
198 
199  void eval_post_dispatch(Particle<T> &particle, void (*)(Particle<T> &))
200  {
201  Derived::eval_post(particle);
202  }
203 
204  // base
205 
206  std::size_t eval_sp_dispatch(
208  {
209  return 0;
210  }
211 
212  void eval_param_dispatch(
213  Particle<T> &, void *, void (InitializeBase::*)(Particle<T> &, void *))
214  {
215  }
216 
217  void eval_pre_dispatch(
218  Particle<T> &, void (InitializeBase::*)(Particle<T> &))
219  {
220  }
221 
222  void eval_post_dispatch(
223  Particle<T> &, void (InitializeBase::*)(Particle<T> &))
224  {
225  }
226 }; // class InitializeBase
227 
230 template <typename T>
231 class InitializeBase<T, Virtual>
232 {
233  public:
234  virtual std::size_t eval_sp(SingleParticle<T>) { return 0; }
235  virtual void eval_param(Particle<T> &, void *) {}
236  virtual void eval_pre(Particle<T> &) {}
237  virtual void eval_post(Particle<T> &) {}
238 
239  protected:
241 }; // class InitializeBase<T, Virtual>
242 
245 template <typename T, typename Derived>
246 class MoveBase
247 {
248  public:
249  std::size_t eval_sp(std::size_t iter, SingleParticle<T> sp)
250  {
251  return eval_sp_dispatch(iter, sp, &Derived::eval_sp);
252  }
253 
254  void eval_pre(std::size_t iter, Particle<T> &particle)
255  {
256  eval_pre_dispatch(iter, particle, &Derived::eval_pre);
257  }
258 
259  void eval_post(std::size_t iter, Particle<T> &particle)
260  {
261  eval_post_dispatch(iter, particle, &Derived::eval_post);
262  }
263 
264  protected:
266 
267  private:
268  // non-static non-const
269 
270  template <typename D>
271  std::size_t eval_sp_dispatch(std::size_t iter, SingleParticle<T> sp,
272  std::size_t (D::*)(std::size_t, SingleParticle<T>))
273  {
274  return static_cast<Derived *>(this)->eval_sp(iter, sp);
275  }
276 
277  template <typename D>
278  void eval_pre_dispatch(std::size_t iter, Particle<T> &particle,
279  void (D::*)(std::size_t, Particle<T> &))
280  {
281  static_cast<Derived *>(this)->eval_pre(iter, particle);
282  }
283 
284  template <typename D>
285  void eval_post_dispatch(std::size_t iter, Particle<T> &particle,
286  void (D::*)(std::size_t, Particle<T> &))
287  {
288  static_cast<Derived *>(this)->eval_post(iter, particle);
289  }
290 
291  // non-static const
292 
293  template <typename D>
294  std::size_t eval_sp_dispatch(std::size_t iter, SingleParticle<T> sp,
295  std::size_t (D::*)(std::size_t, SingleParticle<T>) const)
296  {
297  return static_cast<Derived *>(this)->eval_sp(iter, sp);
298  }
299 
300  template <typename D>
301  void eval_pre_dispatch(std::size_t iter, Particle<T> &particle,
302  void (D::*)(std::size_t, Particle<T> &) const)
303  {
304  static_cast<Derived *>(this)->eval_pre(iter, particle);
305  }
306 
307  template <typename D>
308  void eval_post_dispatch(std::size_t iter, Particle<T> &particle,
309  void (D::*)(std::size_t, Particle<T> &) const)
310  {
311  static_cast<Derived *>(this)->eval_post(iter, particle);
312  }
313 
314  // static
315 
316  std::size_t eval_sp_dispatch(std::size_t iter, SingleParticle<T> sp,
317  std::size_t (*)(std::size_t, SingleParticle<T>))
318  {
319  return Derived::eval_sp(iter, sp);
320  }
321 
322  void eval_pre_dispatch(std::size_t iter, Particle<T> &particle,
323  void (*)(std::size_t, Particle<T> &))
324  {
325  Derived::eval_pre(iter, particle);
326  }
327 
328  void eval_post_dispatch(std::size_t iter, Particle<T> &particle,
329  void (*)(std::size_t, Particle<T> &))
330  {
331  Derived::eval_post(iter, particle);
332  }
333 
334  // base
335 
336  std::size_t eval_sp_dispatch(std::size_t, SingleParticle<T>,
337  std::size_t (MoveBase::*)(std::size_t, SingleParticle<T>))
338  {
339  return 0;
340  }
341 
342  void eval_pre_dispatch(std::size_t, Particle<T> &,
343  void (MoveBase::*)(std::size_t, Particle<T> &))
344  {
345  }
346 
347  void eval_post_dispatch(std::size_t, Particle<T> &,
348  void (MoveBase::*)(std::size_t, Particle<T> &))
349  {
350  }
351 }; // class MoveBase
352 
355 template <typename T>
356 class MoveBase<T, Virtual>
357 {
358  public:
359  virtual std::size_t eval_sp(std::size_t, SingleParticle<T>) { return 0; }
360  virtual void eval_pre(std::size_t, Particle<T> &) {}
361  virtual void eval_post(std::size_t, Particle<T> &) {}
362 
363  protected:
365 }; // class MoveBase<T, Virtual>
366 
369 template <typename T, typename Derived>
371 {
372  public:
373  void eval_sp(
374  std::size_t iter, std::size_t dim, SingleParticle<T> sp, double *r)
375  {
376  eval_sp_dispatch(iter, dim, sp, r, &Derived::eval_sp);
377  }
378 
379  void eval_pre(std::size_t iter, Particle<T> &particle)
380  {
381  eval_pre_dispatch(iter, particle, &Derived::eval_pre);
382  }
383 
384  void eval_post(std::size_t iter, Particle<T> &particle)
385  {
386  eval_post_dispatch(iter, particle, &Derived::eval_post);
387  }
388 
389  protected:
391 
392  private:
393  // non-static non-const
394 
395  template <typename D>
396  void eval_sp_dispatch(std::size_t iter, std::size_t dim,
397  SingleParticle<T> sp, double *r,
398  void (D::*)(std::size_t, std::size_t, SingleParticle<T>, double *))
399  {
400  static_cast<Derived *>(this)->eval_sp(iter, dim, sp, r);
401  }
402 
403  template <typename D>
404  void eval_pre_dispatch(std::size_t iter, Particle<T> &particle,
405  void (D::*)(std::size_t, Particle<T> &))
406  {
407  static_cast<Derived *>(this)->eval_pre(iter, particle);
408  }
409 
410  template <typename D>
411  void eval_post_dispatch(std::size_t iter, Particle<T> &particle,
412  void (D::*)(std::size_t, Particle<T> &))
413  {
414  static_cast<Derived *>(this)->eval_post(iter, particle);
415  }
416 
417  // non-static const
418 
419  template <typename D>
420  void eval_sp_dispatch(std::size_t iter, std::size_t dim,
421  SingleParticle<T> sp, double *r,
422  void (D::*)(std::size_t, std::size_t, SingleParticle<T>, double *)
423  const)
424  {
425  static_cast<Derived *>(this)->eval_sp(iter, dim, sp, r);
426  }
427 
428  template <typename D>
429  void eval_pre_dispatch(std::size_t iter, Particle<T> &particle,
430  void (D::*)(std::size_t, Particle<T> &) const)
431  {
432  static_cast<Derived *>(this)->eval_pre(iter, particle);
433  }
434 
435  template <typename D>
436  void eval_post_dispatch(std::size_t iter, Particle<T> &particle,
437  void (D::*)(std::size_t, Particle<T> &) const)
438  {
439  static_cast<Derived *>(this)->eval_post(iter, particle);
440  }
441 
442  // static
443 
444  void eval_sp_dispatch(std::size_t iter, std::size_t dim,
445  SingleParticle<T> sp, double *r,
446  void (*)(std::size_t, std::size_t, SingleParticle<T>, double *))
447  {
448  Derived::eval_sp(iter, dim, sp, r);
449  }
450 
451  void eval_pre_dispatch(std::size_t iter, Particle<T> &particle,
452  void (*)(std::size_t, Particle<T> &))
453  {
454  Derived::eval_pre(iter, particle);
455  }
456 
457  void eval_post_dispatch(std::size_t iter, Particle<T> &particle,
458  void (*)(std::size_t, Particle<T> &))
459  {
460  Derived::eval_post(iter, particle);
461  }
462 
463  // base
464 
465  void eval_sp_dispatch(std::size_t, std::size_t, SingleParticle<T>,
466  double *, void (MonitorEvalBase::*)(std::size_t, std::size_t,
467  SingleParticle<T>, double *))
468  {
469  }
470 
471  void eval_pre_dispatch(std::size_t, Particle<T> &,
472  void (MonitorEvalBase::*)(std::size_t, Particle<T> &))
473  {
474  }
475 
476  void eval_post_dispatch(std::size_t, Particle<T> &,
477  void (MonitorEvalBase::*)(std::size_t, Particle<T> &))
478  {
479  }
480 }; // class MonitorBase
481 
484 template <typename T>
485 class MonitorEvalBase<T, Virtual>
486 {
487  public:
488  virtual void eval_sp(std::size_t, std::size_t, SingleParticle<T>, double *)
489  {
490  }
491  virtual void eval_pre(std::size_t, Particle<T> &) {}
492  virtual void eval_post(std::size_t, Particle<T> &) {}
493 
494  protected:
496 }; // class MonitorEvalBase<T, Virtual>
497 
500 template <typename T, typename Derived>
502 {
503  public:
504  double eval_sp(std::size_t iter, SingleParticle<T> sp)
505  {
506  return eval_sp_dispatch(iter, sp, &Derived::eval_sp);
507  }
508 
509  double eval_grid(std::size_t iter, Particle<T> &particle)
510  {
511  return eval_grid_dispatch(iter, particle, &Derived::eval_grid);
512  }
513 
514  void eval_pre(std::size_t iter, Particle<T> &particle)
515  {
516  eval_pre_dispatch(iter, particle, &Derived::eval_pre);
517  }
518 
519  void eval_post(std::size_t iter, Particle<T> &particle)
520  {
521  eval_post_dispatch(iter, particle, &Derived::eval_post);
522  }
523 
524  protected:
526 
527  private:
528  // non-static non-const
529 
530  template <typename D>
531  double eval_sp_dispatch(std::size_t iter, SingleParticle<T> sp,
532  double (D::*)(std::size_t, SingleParticle<T>))
533  {
534  return static_cast<Derived *>(this)->eval_sp(iter, sp);
535  }
536 
537  template <typename D>
538  double eval_grid_dispatch(std::size_t iter, Particle<T> &particle,
539  double (D::*)(std::size_t, Particle<T> &))
540  {
541  return static_cast<Derived *>(this)->eval_grid(iter, particle);
542  }
543 
544  template <typename D>
545  void eval_pre_dispatch(std::size_t iter, Particle<T> &particle,
546  void (D::*)(std::size_t, Particle<T> &))
547  {
548  static_cast<Derived *>(this)->eval_pre(iter, particle);
549  }
550 
551  template <typename D>
552  void eval_post_dispatch(std::size_t iter, Particle<T> &particle,
553  void (D::*)(std::size_t, Particle<T> &))
554  {
555  static_cast<Derived *>(this)->eval_post(iter, particle);
556  }
557 
558  // non-static const
559 
560  template <typename D>
561  double eval_sp_dispatch(std::size_t iter, SingleParticle<T> sp,
562  double (D::*)(std::size_t, SingleParticle<T>) const)
563  {
564  return static_cast<Derived *>(this)->eval_sp(iter, sp);
565  }
566 
567  template <typename D>
568  double eval_grid_dispatch(std::size_t iter, Particle<T> &particle,
569  double (D::*)(std::size_t, Particle<T> &) const)
570  {
571  return static_cast<Derived *>(this)->eval_grid(iter, particle);
572  }
573 
574  template <typename D>
575  void eval_pre_dispatch(std::size_t iter, Particle<T> &particle,
576  void (D::*)(std::size_t, Particle<T> &) const)
577  {
578  static_cast<Derived *>(this)->eval_pre(iter, particle);
579  }
580 
581  template <typename D>
582  void eval_post_dispatch(std::size_t iter, Particle<T> &particle,
583  void (D::*)(std::size_t, Particle<T> &) const)
584  {
585  static_cast<Derived *>(this)->eval_post(iter, particle);
586  }
587 
588  // static
589 
590  double eval_sp_dispatch(std::size_t iter, SingleParticle<T> sp,
591  double (*)(std::size_t, SingleParticle<T>))
592  {
593  return Derived::eval_sp(iter, sp);
594  }
595 
596  double eval_grid_dispatch(std::size_t iter, Particle<T> &particle,
597  double (*)(std::size_t, Particle<T> &))
598  {
599  return Derived::eval_grid(iter, particle);
600  }
601 
602  void eval_pre_dispatch(std::size_t iter, Particle<T> &particle,
603  void (*)(std::size_t, Particle<T> &))
604  {
605  Derived::eval_pre(iter, particle);
606  }
607 
608  void eval_post_dispatch(std::size_t iter, Particle<T> &particle,
609  void (*)(std::size_t, Particle<T> &))
610  {
611  Derived::eval_post(iter, particle);
612  }
613 
614  // base
615 
616  double eval_sp_dispatch(std::size_t, SingleParticle<T>,
617  double (PathEvalBase::*)(std::size_t, SingleParticle<T>))
618  {
619  return 0;
620  }
621 
622  double eval_grid_dispatch(std::size_t, Particle<T> &,
623  double (PathEvalBase::*)(std::size_t, Particle<T> &))
624  {
625  return 0;
626  }
627 
628  void eval_pre_dispatch(std::size_t, Particle<T> &,
629  void (PathEvalBase::*)(std::size_t, Particle<T> &))
630  {
631  }
632 
633  void eval_post_dispatch(std::size_t, Particle<T> &,
634  void (PathEvalBase::*)(std::size_t, Particle<T> &))
635  {
636  }
637 }; // class PathEvalBase
638 
641 template <typename T>
642 class PathEvalBase<T, Virtual>
643 {
644  public:
645  virtual double eval_sp(std::size_t, SingleParticle<T>) { return 0; }
646  virtual double eval_grid(std::size_t, Particle<T> &) { return 0; }
647  virtual void eval_pre(std::size_t, Particle<T> &) {}
648  virtual void eval_post(std::size_t, Particle<T> &) {}
649 
650  protected:
652 }; // class PathEval<T, Virtual>
653 
654 } // namespace vsmc
655 
656 #endif // VSMC_SMP_BACKEND_BASE_HPP
Definition: monitor.hpp:49
Particle class representing the whole particle set.
Definition: particle.hpp:48
virtual void eval_post(std::size_t, Particle< T > &)
void eval_param(Particle< T > &particle, void *param)
virtual void eval_pre(std::size_t, Particle< T > &)
#define VSMC_DEFINE_SMP_BACKEND_BASE_SPECIAL(Name)
virtual void eval_param(Particle< T > &, void *)
std::size_t eval_sp(SingleParticle< T > sp)
virtual std::size_t eval_sp(std::size_t, SingleParticle< T >)
double eval_grid(std::size_t iter, Particle< T > &particle)
Monitor evalution base dispatch class.
void eval_pre(std::size_t iter, Particle< T > &particle)
void eval_sp(std::size_t iter, std::size_t dim, SingleParticle< T > sp, double *r)
STL namespace.
virtual double eval_sp(std::size_t, SingleParticle< T >)
virtual void eval_pre(Particle< T > &)
void eval_pre(Particle< T > &particle)
virtual double eval_grid(std::size_t, Particle< T > &)
virtual std::size_t eval_sp(SingleParticle< T >)
void eval_post(std::size_t iter, Particle< T > &particle)
virtual void eval_pre(std::size_t, Particle< T > &)
void eval_post(std::size_t iter, Particle< T > &particle)
void eval_post(std::size_t iter, Particle< T > &particle)
void eval_pre(std::size_t iter, Particle< T > &particle)
Move base dispatch class.
double eval_sp(std::size_t iter, SingleParticle< T > sp)
virtual void eval_post(Particle< T > &)
#define VSMC_DEFINE_SMP_BACKEND_BASE_SPECIAL_VIRTUAL(Name)
virtual void eval_post(std::size_t, Particle< T > &)
Path evalution base dispatch class.
virtual void eval_pre(std::size_t, Particle< T > &)
void eval_post(Particle< T > &particle)
std::size_t eval_sp(std::size_t iter, SingleParticle< T > sp)
virtual void eval_post(std::size_t, Particle< T > &)
A thin wrapper over a complete Particle.
virtual void eval_sp(std::size_t, std::size_t, SingleParticle< T >, double *)
void eval_pre(std::size_t iter, Particle< T > &particle)
Initialize base dispatch class.