Swarm-NG  1.1
integrator.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  ************************************************************************/
26 #pragma once
27 
28 #include "types/ensemble.hpp"
29 #include "ensemble_alloc.hpp"
30 #include "types/config.hpp"
31 #include "log/logmanager.hpp"
32 
33 
34 namespace swarm {
35 
49 class integrator {
50  public:
51 
53  const static int _default_max_iterations;
55  const static int _default_max_attempts;
56  protected:
57 
60 
63 
65  log::Pmanager _logman;
66 
68  // WARNING: Why do we store a raw pointer here?
69  // Any reason not to just use host_log stored in _logman?
70  // Answer to WARNING: we may have different log streams and each
71  // integrator can use their own log stream
72  gpulog::host_log* _log;
73 
78 
80  virtual void launch_integrator() = 0 ;
81 
82  public:
86  integrator(const config &cfg);
87 
98  virtual void integrate();
99 
101  virtual void flush_log() {
102  _logman->flush();
103  }
104 
107  return _ens;
108  }
109 
111  virtual void set_ensemble(defaultEnsemble& ens) {
112  _ens = ens;
113  }
114 
116  virtual void set_destination_time(const double& destination_time) {
117  _destination_time = destination_time;
118  }
119 
120  virtual double get_destination_time()const{
121  return _destination_time;
122  }
123 
140  static shared_ptr<integrator> create(const config &cfg);
141 
143  virtual void set_log_manager(log::Pmanager& l);
144  virtual gpulog::host_log* get_host_log();
145 
146  virtual void set_max_iterations( const int& mi ) { _max_iterations = mi; }
147  virtual void set_max_attempts( const int& ma ) { _max_attempts = ma; }
148 
149 };
150 typedef shared_ptr<integrator> Pintegrator;
151 
152 
155 
156 
164 namespace gpu {
165 
179  typedef swarm::integrator Base;
180  protected:
186 
188  gpulog::device_log* _log;
189 
190  public:
191 
193  integrator(const config &cfg);
194 
205  virtual void integrate();
206 
214  virtual void core_integrate() {
216  flush_log();
217  }
218 
220  virtual void set_log_manager(log::Pmanager& l);
221 
223  void set_log(gpulog::device_log* log) { _log = log; }
224 
226  gpulog::device_log* get_device_log() { return _log; }
227 
234  _hens = ens;
236  }
237 
260  void set_ensemble(defaultEnsemble& host_ens, deviceEnsemble& device_ens) {
261  _hens = host_ens;
262  _dens = device_ens;
263  }
264 
267  _hens.copyTo( _dens );
268  }
269 
272  _dens.copyTo( _hens );
273  }
274 
275 };
276 typedef shared_ptr<integrator> Pintegrator;
277 
278 
279 }
280 
281 }