Swarm-NG  1.1
integrator.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2008-2010 by Mario Juric & 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 
24 #include "common.hpp"
25 #include "integrator.hpp"
26 #include "log/logmanager.hpp"
27 #include "plugin.hpp"
28 #include "gpu/utilities.hpp"
29 #include "gpu/device_settings.hpp"
30 
31 namespace swarm {
32 
33  const int integrator::_default_max_iterations = 10000000;
34  const int integrator::_default_max_attempts = 1000000;
35 
36  void integrator::set_log_manager(log::Pmanager& l){
37  _logman = l;
38  _log = l->get_hostlog();
39  }
40 
41  gpulog::host_log* integrator::get_host_log(){
42  return _log;
43  }
44 
45  void gpu::integrator::set_log_manager(log::Pmanager& l){
47  set_log(l->get_gpulog());
48  }
49 
52  _max_iterations = cfg.optional("max_iterations", _default_max_iterations );
53  _max_attempts = cfg.optional("max_attempts", _default_max_attempts );
54  }
55 
57  : Base(cfg), _hens(Base::_ens) {
59  }
60 
62  int count_running = 0;
63  for(int i = 0; i < ens.nsys() ; i++)
64  if( ens[i].is_active() ) count_running++;
65  return count_running;
66  }
67 
68  int number_of_not_disabled_systems(defaultEnsemble ens) {
69  int count_running = 0;
70  for(int i = 0; i < ens.nsys() ; i++)
71  if( !ens[i].is_disabled() ) count_running++;
72  return count_running;
73  }
74 
75  void activate_all_systems(defaultEnsemble& ens) {
76  for(int i = 0; i < ens.nsys() ; i++)
77  {
78  if(!ens[i].is_active())
79  ens[i].set_active();
80  }
81  }
82 
83  void activate_inactive_systems(defaultEnsemble& ens) {
84  for(int i = 0; i < ens.nsys() ; i++)
85  {
86  if(ens[i].is_inactive())
87  ens[i].set_active();
88  }
89  }
90 
92  activate_inactive_systems(_ens);
93  for(int i = 0; i < _max_attempts; i++)
94  {
96  _logman->flush();
97  if( number_of_active_systems(_ens) == 0 )
98  break;
99  }
100  };
101 
103 
104 
105 
106  activate_inactive_systems(_ens);
107 
108  upload_ensemble();
109  for(int i = 0; i < _max_attempts; i++)
110  {
111  launch_integrator();
112  _logman->flush();
113  if( number_of_active_systems(_dens) == 0 )
114  break;
115  }
116  download_ensemble();
117  };
118 
119 
129 Pintegrator integrator::create(const config &cfg)
130 {
131  Pintegrator integ;
132 
133  if(!cfg.count("integrator")) ERROR("Integrator type has to be chosen with 'integrator=xxx' keyword");
134 
135  std::string name = cfg.at("integrator");
136  std::string plugin_name = "integrator_" + name;
137 
138  try {
139  integ.reset( (integrator*) plugin::instance(plugin_name,cfg) );
140  }catch(plugin_not_found& e){
141  ERROR("Integrator " + name + " not found.");
142  }
143 
144  return integ;
145 }
146 
147 
148 }