Swarm-NG  1.1
combine.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2011 by Saleh Dindar and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
19 
27 #pragma once
28 
29 #include <limits>
30 
31 namespace swarm {
32 namespace monitors {
33 
34 template<class T>
35 GENERIC const T& max2(const T& a, const T& b){
36  return b > a ? b : a;
37 }
38 
39 
40 template< class Param1, class Param2 >
43  Param1 p1;
44  Param2 p2;
46  combine_monitors_params(const config &cfg): p1(cfg), p2(cfg)
47  {
48  }
49 };
50 
67 template< class log_t, class Monitor1, class Monitor2 >
68 struct combine {
69 
70  typedef Monitor1 monitor1_t;
71  typedef Monitor2 monitor2_t;
72 
73 
74 
75  public:
77 
78  params _params;
79 
80  private:
81  monitor1_t _monitor1;
82  monitor2_t _monitor2;
83 
84  public:
85  template<class T>
87  static GENERIC int thread_per_system(T compile_time_param){
88  return max2(monitor1_t::thread_per_system(compile_time_param)
89  ,monitor2_t::thread_per_system(compile_time_param));
90  }
91 
93  template<class T>
94  static GENERIC int shmem_per_system(T compile_time_param) {
95  return max2(monitor1_t::shmem_per_system(compile_time_param)
96  ,monitor2_t::shmem_per_system(compile_time_param));
97  }
98  GPUAPI bool is_deactivate_on() { return _monitor1.is_deactivate_on() || _monitor2.is_deactivate_on(); }
99  GPUAPI bool is_log_on() { return _monitor1.is_log_on() || _monitor2.is_log_on(); }
100  GPUAPI bool is_verbose_on() { return _monitor1.is_verbose_on() || _monitor2.is_verbose_on(); };
101  GPUAPI bool is_any_on() { return is_deactivate_on() || is_log_on() || is_verbose_on() ; }
102  GPUAPI bool is_condition_met () { return _monitor1.is_condition_met() || _monitor2.is_condition_met(); }
103 
104  GPUAPI bool need_to_log_system ()
105  { return (_monitor1.need_to_log_system() || _monitor2.need_to_log_system() ); }
106  GPUAPI bool need_to_deactivate ()
107  { return (_monitor1.need_to_deactivate() || _monitor2.need_to_deactivate() ); }
108 
109 
110  GPUAPI bool pass_one (int thread_in_system)
111  { return _monitor1.pass_one(thread_in_system) || _monitor2.pass_one(thread_in_system); }
112 
113 
114  GPUAPI int pass_two (int thread_in_system)
115  {
116  int s1 = _monitor1.pass_two(thread_in_system);
117  int s2 = _monitor2.pass_two(thread_in_system);
118  if((s1==0)&&(s1==0)) return 0;
119  else if((s1<0)||(s2<0)) return (s1<s2) ? s1 : s2;
120  else return (s1>s2) ? s1 : s2;
121  }
122 
123  GPUAPI void operator () () {
124  _monitor1();
125  _monitor2();
126  }
127 
128 #if 0
129  GPUAPI void operator () (const int thread_in_system) {
130  _monitor1(thread_in_system);
131  _monitor2(thread_in_system);
132  }
133 #endif
134  GPUAPI void operator () (const int thread_in_system)
135  {
136  pass_one(thread_in_system);
137  pass_two(thread_in_system);
138  if(need_to_log_system() && (thread_in_system==0) )
139  _monitor1.log_system();
140  }
141 
142  GPUAPI combine(const params& p,ensemble::SystemRef& s,log_t& l)
143  :_params(p),_monitor1(p.p1,s,l),_monitor2(p.p2,s,l){}
144 
145 };
146 
147 }
148 
149 }