Swarm-NG  1.1
log_time_interval.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 
25 #pragma once
26 
27 namespace swarm {
28  namespace monitors {
29 
36  double time_interval;
37  // bool log_on;
40  {
41  time_interval = cfg.require("log_interval", 0.0);
42  // log_on = cfg.optional("log_on_interval",true);
43  }
44 };
45 
54 template<class log_t>
56  public:
58 
59  private:
60  params _params;
61  bool condition_met;
62 
63  ensemble::SystemRef& _sys;
64  double _next_log_time;
65  log_t& _log;
66 
67  public:
68  template<class T>
69  static GENERIC int thread_per_system(T compile_time_param){
70  return 1;
71  }
72 
73  template<class T>
74  static GENERIC int shmem_per_system(T compile_time_param) {
75  return 0;
76  }
77  GPUAPI bool is_deactivate_on() { return false; };
78  // GPUAPI bool is_log_on() { return _params.log_on; };
79  GPUAPI bool is_log_on() { return _params.time_interval!=0.; };
80  GPUAPI bool is_verbose_on() { return false; };
81  GPUAPI bool is_any_on() { return is_deactivate_on() || is_log_on() || is_verbose_on() ; }
82  GPUAPI bool is_condition_met () { return ( condition_met ); }
83  GPUAPI bool need_to_log_system ()
84  { return (is_log_on() && is_condition_met() ); }
85  GPUAPI bool need_to_deactivate ()
86  { return ( is_deactivate_on() && is_condition_met() ); }
87 
88  GPUAPI void log_system() { log::system(_log, _sys); }
89 
90  GPUAPI void operator () (const int thread_in_system)
91  {
92  pass_one(thread_in_system);
93  pass_two(thread_in_system);
94  if(need_to_log_system() && (thread_in_system==0) )
95  log_system();
96  }
97 
98  GPUAPI bool pass_one (int thread_in_system)
99  {
100  condition_met = false;
101  if(is_log_on())
102  {
103  if(thread_in_system == 0 && _sys.time() >= _next_log_time )
104  {
105  condition_met = true;
106  _next_log_time += _params.time_interval;
107  //lprintf(_log,"Logging at %lg\n",_sys.time());
108  }
109  }
110  return condition_met;
111  }
112 
113 
114  GPUAPI int pass_two (int thread_in_system)
115  { return _sys.state(); }
116 
117 
118  GPUAPI log_time_interval(const params& p,ensemble::SystemRef& s,log_t& l)
119  :_params(p),_sys(s),_log(l),_next_log_time(s.time()){}
120 
121 };
122 
123 }
124 
125 
126 }