integrator.hpp

Go to the documentation of this file.
00001 /*************************************************************************
00002  * Copyright (C) 2011 by Saleh Dindar and the Swarm-NG Development Team  *
00003  *                                                                       *
00004  * This program is free software; you can redistribute it and/or modify  *
00005  * it under the terms of the GNU General Public License as published by  *
00006  * the Free Software Foundation; either version 3 of the License.        *
00007  *                                                                       *
00008  * This program is distributed in the hope that it will be useful,       *
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00011  * GNU General Public License for more details.                          *
00012  *                                                                       *
00013  * You should have received a copy of the GNU General Public License     *
00014  * along with this program; if not, write to the                         *
00015  * Free Software Foundation, Inc.,                                       *
00016  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00017  ************************************************************************/
00026 #pragma once
00027 
00028 #include "types/ensemble.hpp"
00029 #include "types/config.hpp"
00030 #include "log/logmanager.hpp"
00031 
00032 
00033 namespace swarm {
00034 
00048 class integrator {      
00049         public:
00050         
00052         const static int _default_max_iterations;
00054         const static int _default_max_attempts;
00055         protected:
00056 
00058         defaultEnsemble _ens;          
00059 
00061         double _destination_time;
00062 
00064         log::Pmanager _logman;
00065 
00067         //  WARNING: Why do we store a raw pointer here?  
00068         // Any reason not to just use host_log stored in _logman?
00069         // Answer to WARNING: we may have different log streams and each
00070         // integrator can use their own log stream
00071         gpulog::host_log* _log;
00072 
00074         int _max_iterations;
00076         int _max_attempts;
00077 
00079         virtual void launch_integrator() = 0 ;
00080 
00081         public:
00085         integrator(const config &cfg);
00086 
00097         virtual void integrate();
00098 
00100         virtual void flush_log() {
00101           _logman->flush();       
00102         }
00103 
00105         virtual defaultEnsemble& get_ensemble() {
00106                 return _ens;
00107         }
00108 
00110         virtual void set_ensemble(defaultEnsemble& ens) {
00111                 _ens = ens;
00112         }
00113 
00115         virtual void set_destination_time(const double& destination_time) {
00116                 _destination_time = destination_time;
00117         }
00118 
00119         virtual double get_destination_time()const{
00120                 return _destination_time;
00121         }
00122 
00139         static shared_ptr<integrator> create(const config &cfg);
00140 
00142         virtual void set_log_manager(log::Pmanager& l);
00143         virtual gpulog::host_log* get_host_log();
00144 
00145         virtual void set_max_iterations( const int& mi ) { _max_iterations = mi; }
00146         virtual void set_max_attempts( const int& ma ) { _max_attempts = ma; }
00147 
00148 };
00149 typedef shared_ptr<integrator> Pintegrator;
00150 
00151 
00153 int number_of_active_systems(defaultEnsemble ens) ;
00154 
00155 
00163 namespace gpu {
00164 
00177 class integrator : public swarm::integrator {
00178         typedef swarm::integrator Base;
00179         protected:
00181         hostEnsemble& _hens;
00184         deviceEnsemble _dens;
00185 
00187         gpulog::device_log* _log;
00188 
00189         public: 
00190 
00192         integrator(const config &cfg);
00193 
00204         virtual void integrate();
00205 
00213         virtual void core_integrate() {
00214                 launch_integrator();
00215                 flush_log();
00216         }
00217 
00219         virtual void set_log_manager(log::Pmanager& l);
00220 
00222         void set_log(gpulog::device_log* log) { _log = log; }
00223 
00225         gpulog::device_log* get_device_log() { return _log; }
00226 
00232         void set_ensemble(defaultEnsemble& ens) {
00233                 _hens = ens;
00234                 _dens = _hens.cloneTo<deviceEnsemble>();
00235         }
00236 
00259         void set_ensemble(defaultEnsemble& host_ens, deviceEnsemble& device_ens) {
00260                 _hens = host_ens;
00261                 _dens = device_ens;
00262         }
00263 
00265         void upload_ensemble() {
00266                 _hens.copyTo( _dens );
00267         }
00268                 
00270         void download_ensemble() {
00271                 _dens.copyTo( _hens );
00272         }
00273 
00274 };
00275 typedef shared_ptr<integrator> Pintegrator;
00276 
00277 
00278 }
00279 
00280 }

doxygen