Swarm-NG  1.1
composites.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 
25 #pragma once
26 
27 #include "combine.hpp"
28 #include "stop_on_ejection.hpp"
31 
32 namespace swarm { namespace monitors {
33 
34 
46 template <class L>
48 
50  struct params {
51  typename stop_on_ejection<L> ::params ej;
54 
55  params(const config& cfg)
56  :ej(cfg), ce(cfg), co(cfg) {}
57  };
58 
61  (const params& p,ensemble::SystemRef& s,L& l)
62  : ej(p.ej,s,l), ce(p.ce,s,l), co(p.co,s,l) {}
63 
64  template<class T>
65  static GENERIC int thread_per_system(T compile_time_param){
66  return 1;
67  }
68 
69  template<class T>
70  static GENERIC int shmem_per_system(T compile_time_param) {
71  return 0;
72  }
73 
74  // GPUAPI void operator () ()
75  // { ej(); ce(); co(); }
76 
77 #if 0
78  GPUAPI void operator () (const int thread_in_system)
79  { ej(thread_in_system); ce(thread_in_system); co(thread_in_system); }
80 #endif
81 
82  GPUAPI void operator () (const int thread_in_system)
83  {
84  pass_one(thread_in_system);
85  pass_two(thread_in_system);
86  if(need_to_log_system() && (thread_in_system==0) )
87  ej.log_system();
88  }
89 
90  GPUAPI bool is_deactivate_on() { return ej.is_deactivate_on() || ce.is_deactivate_on() || co.is_deactivate_on(); }
91  GPUAPI bool is_log_on() { return ej.is_log_on() || ce.is_log_on() || co.is_log_on(); }
92  GPUAPI bool is_verbose_on() { return ej.is_verbose_on() || ce.is_verbose_on() || co.is_verbose_on(); };
93  GPUAPI bool is_any_on() { return is_deactivate_on() || is_log_on() || is_verbose_on() ; }
94 
95  GPUAPI bool is_condition_met () { return ej.is_condition_met() || ce.is_condition_met() || co.is_condition_met(); }
96  GPUAPI bool need_to_log_system ()
97  { return (ej.need_to_log_system() || ce.need_to_log_system() || co.need_to_log_system() ); }
98  GPUAPI bool need_to_deactivate ()
99  { return (ej.need_to_deactivate() || ce.need_to_deactivate() || co.need_to_deactivate() ); }
100 
102  GPUAPI bool pass_one (int thread_in_system)
103  { return ej.pass_one(thread_in_system) || ce.pass_one(thread_in_system) || co.pass_one(thread_in_system); }
104 
105 
107  GPUAPI int pass_two (int thread_in_system)
108  {
109  int s1 = ej.pass_two(thread_in_system);
110  int s2 = ce.pass_two(thread_in_system);
111  int s3 = co.pass_two(thread_in_system);
112  if((s1==0)&&(s1==0)&&(s3==0)) return 0;
113  else
114  {
115  int ret = s1;
116  if((s1<0)||(s2<0)||(s3<0))
117  {
118  if(s2<ret) ret = s2;
119  if(s3<ret) ret = s3;
120  }
121  else
122  {
123  if(s2>ret) ret = s2;
124  if(s3>ret) ret = s3;
125  }
126  return ret;
127  }
128  }
129 
130 private:
134 };
135 
136 
145 template <class L>
147 
149  struct params {
150  typename stop_on_ejection<L> ::params ej;
152 
153  params(const config& cfg)
154  :ej(cfg), ce(cfg) {}
155  };
156 
159  (const params& p,ensemble::SystemRef& s,L& l)
160  : ej(p.ej,s,l), ce(p.ce,s,l) {}
161 
162  template<class T>
163  static GENERIC int thread_per_system(T compile_time_param){
164  return 1;
165  }
166 
167  template<class T>
168  static GENERIC int shmem_per_system(T compile_time_param) {
169  return 0;
170  }
171 
172  // GPUAPI void operator () ()
173  // { ej(); ce(); }
174 
175 #if 0
176  GPUAPI void operator () (const int thread_in_system)
177  { ej(thread_in_system); ce(thread_in_system); }
178 #endif
179  GPUAPI void operator () (const int thread_in_system)
180  {
181  pass_one(thread_in_system);
182  pass_two(thread_in_system);
183  if(need_to_log_system() && (thread_in_system==0) )
184  ej.log_system();
185  }
186 
187  GPUAPI bool is_deactivate_on() { return ej.is_deactivate_on() || ce.is_deactivate_on(); }
188  GPUAPI bool is_log_on() { return ej.is_log_on() || ce.is_log_on(); }
189  GPUAPI bool is_verbose_on() { return ej.is_verbose_on() || ce.is_verbose_on(); };
190  GPUAPI bool is_any_on() { return is_deactivate_on() || is_log_on() || is_verbose_on() ; }
191 
192  GPUAPI bool is_condition_met () { return ej.is_condition_met() || ce.is_condition_met(); }
193  GPUAPI bool need_to_log_system ()
194  { return (ej.need_to_log_system() || ce.need_to_log_system() ); }
195  GPUAPI bool need_to_deactivate ()
196  { return (ej.need_to_deactivate() || ce.need_to_deactivate()); }
197 
199  GPUAPI bool pass_one (int thread_in_system)
200  { return ej.pass_one(thread_in_system) || ce.pass_one(thread_in_system); }
201 
203  GPUAPI int pass_two (int thread_in_system)
204  {
205  int s1 = ej.pass_two(thread_in_system);
206  int s2 = ce.pass_two(thread_in_system);
207  if((s1==0)&&(s1==0)) return 0;
208  else
209  {
210  int ret = s1;
211  if((s1<0)||(s2<0))
212  { if(s2<ret) ret = s2; }
213  else
214  { if(s2>ret) ret = s2; }
215  return ret;
216  }
217  }
218 
219 private:
222 };
223 
224  } } // end namespace monitors :: swarm
225 
226 
227