Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
SimRunner Class Reference

Performs the setup of the Metapop and SimComponents and runs the simulation. More...

#include <simulation.h>

+ Inheritance diagram for SimRunner:
+ Collaboration diagram for SimRunner:

Public Member Functions

 SimRunner (Metapop *pop)
 
 ~SimRunner ()
 Dstror. More...
 
bool init ()
 Checks simulation parameters and init the FileServices with the base filename. More...
 
bool init_components (map< string, string > &simparams)
 Performs the initialization of the different components of the simulation. More...
 
void setLifeCycle ()
 Sets the list of LifeCyckeEvent's currently active. More...
 
void setForFirstGeneration ()
 Sets the population and the services ready for the first generation of a new replicate. More...
 
void init_random_seed ()
 Initialize the seed of the random generator. More...
 
void reset ()
 Resets all the parameters to the unset state, resets the services. More...
 
std::string setElapsedTime (clock_t time)
 Compute and print the simulation's elapsed time to stdout. More...
 
void register_component (SimComponent *cmpt)
 Register the different Handler's attached to a SimComponent. More...
 
void register_component_handlers ()
 Register all the Handlers of the currently active simulation components. More...
 
void reset_services ()
 Resets the FileServices and StatServices. More...
 
FileServicesget_FileServices ()
 Returns the FileServices. More...
 
StatServicesget_StatServices ()
 Returns the StatServices. More...
 
list< StatRecBase * > get_allRegisteredStats ()
 Returns the complete list of the stat recorders loaded after parameters initialization. More...
 
bool run (int ARGC, char **ARGV)
 First loop of the simulation, performs the simulations stored in the ParamManager base class. More...
 
bool run ()
 First loop of the simulation, performs the simulations stored in the ParamManager base class. More...
 
bool run_event (string &name)
 Execute one specific life cycle event, if present in the list of current events. More...
 
void step (unsigned int nb_gen)
 Iterates the life cycle. More...
 
void attach_pop (Metapop *pop)
 Attach a pop to the simulation. More...
 
Metapopget_pop ()
 Accessor to the pop ptr. More...
 
bool build_pop ()
 Calls the Metapop init procedure with current traits and LCEs. More...
 
void setCurrentGeneration (unsigned int gen)
 
unsigned int getCurrentGeneration ()
 
void setGenerations (unsigned int gen)
 
unsigned int getGenerations ()
 
void setCurrentReplicate (unsigned int repl)
 
unsigned int getCurrentReplicate ()
 
void setReplicates (unsigned int repl)
 
unsigned int getReplicates ()
 
int getCurrentRankInLifeCycle ()
 
void printLogHeader ()
 
void printLog ()
 
void runPostExec ()
 Run the post-exec script after all simulations have finished. More...
 
void runPostExecReplicateWise ()
 Run the post-exec script after each replicate, adds filename and replicate number as args. More...
 
Main loops
void Replicate_LOOP ()
 Replicate loop, iterates the life cycle _replicates times. More...
 
void Cycle (char *startTime)
 Life cycle loop, executes the list of LCEs _generations times. More...
 
- Public Member Functions inherited from SimBuilder
 SimBuilder ()
 
 SimBuilder (const SimBuilder &SB)
 copy cstor. More...
 
 ~SimBuilder ()
 
bool build_currentParams (map< string, string > &simparams)
 Builds the list of parameters from user's defined input parameters. More...
 
map< trait_t, TraitPrototype * > & build_currentTraits ()
 Selects the trait prototypes that have their parameters set. More...
 
void build_LifeCycle ()
 Selects the life cycle events that have their parameters set. More...
 
TraitPrototypeget_current_trait (trait_t type)
 Accessor to the list of current trait prototypes. More...
 
TraitPrototypeget_current_traitWithParameter (string &param)
 Accessor to the current trait prototypes conditioned on ownership of a specified parameter. More...
 
LifeCycleEventget_current_event (string &name)
 Accessor to the list of current LCEs. More...
 
LifeCycleEventget_current_eventWithParameter (string &param)
 Accessor to the current LCEs conditioned on ownership of a specified parameter. More...
 
list< ParamSet * > & get_currentParams ()
 Accessor to the list of the selected parameter sets. More...
 
age_t getFirstRequiredAgeInLifeCycle ()
 
- Public Member Functions inherited from ParamManager
 ParamManager ()
 Cstor. More...
 
 ~ParamManager ()
 
void add_paramset (ParamSet *paramset)
 Adds a ParamSet to the list of the parameter sets of the simulation. More...
 
ParamSetget_paramset (string &name)
 Looks for paramset with "name" in the list of parameter sets. More...
 
void build_allParams ()
 Clears and fills the _allParams list with the ParamSet's of the simulation components. More...
 
list< ParamSet * > & get_allParams ()
 Accessor of the whole list of the parameter sets. More...
 
bool set_parameters (map< string, string > &simparams, bool silent)
 Sets the parameters of the simulation with the argument strings given in input. More...
 
bool param_consistency_check ()
 Checks if all the mandatory parameters are set so that the simulation can be launched. More...
 
void build_records (map< string, vector< string > > &initParams)
 Builds the list of simulation parameters from the parsed input file(s). More...
 
list< map< string, string > > & get_simRecords ()
 Accessor to the simulations parameter list. More...
 
map< string, string > & get_firstRecord ()
 Accessor to the first element in the simulations parameter list. More...
 
int get_nbSims ()
 Accessor to the size of the simulations parameter list, i.e. More...
 
- Public Member Functions inherited from ComponentManager
 ComponentManager ()
 
 ~ComponentManager ()
 
void build_component_list ()
 Clears and builds the list of all components from the lists of trait prototype templates and life cycle event templates. More...
 
void add_component (SimComponent *cmpt)
 Push a component at the back of the component list. More...
 
void add_trait (TraitPrototype *trait)
 Add a trait prototype to the template and component lists. More...
 
void add_LCE (LifeCycleEvent *event)
 Add a life cycle event to the template and component lists. More...
 
TraitPrototypeget_trait (string name)
 Search for component with "name" in the trait prototype list. More...
 
LifeCycleEventget_LCE (string name)
 Search for component with "name" in the life cycle events list. More...
 

Public Attributes

FileServices _FileServices
 
StatServices _StatServices
 
UpdaterServices _ParamUpdaterManager
 

Private Attributes

MPImanager_my_mpi_manager
 
Metapop_thePop
 
std::string _logfile
 
char _startTime [20]
 
char _endTime [20]
 
std::string _simElapsedTime
 
clock_t _meanReplElapsedTime
 Clock counter, for logging. More...
 
unsigned int _meanGenLength
 Generation counter, for logging. More...
 
unsigned int _generations
 Number of generations to iterate. More...
 
unsigned int _replicates
 Number of replicates to iterate. More...
 
unsigned int _currentReplicate
 The current replicate in the replicate loop, starts at 1. More...
 
unsigned int _currentGeneration
 The current generation in the generation loop, starts at 1. More...
 
int _currentRankInLifeCycle
 The current rank in the life cycle, corresponds to the rank of the current LCE, before it executes. More...
 
unsigned long _random_seed
 The startup random seed of the random generator. More...
 
std::string _modeArg
 The run mode ('overwrite', 'run', 'skip', 'dryrun', 'create_init'). More...
 
unsigned int _mode
 The run mode code (0 = run, 1 = overwrite, 2 = skip, 3 = dryrun, 4 = create_init) More...
 
bool _doRun
 Boolean set when not in dryrun mode. More...
 
std::string _postexec_script
 The path to the script to be executed after last simulation. More...
 
std::string _postexec_args
 Arguments to pass to the post-exec script. More...
 
bool _do_postexec_replicatewise
 Boolean to trigger replicate-wise execution of post script. More...
 
bool _do_postexec
 Boolean set when a post-exec script must be executed. More...
 

Additional Inherited Members

- Protected Types inherited from SimBuilder
typedef map< int, LifeCycleEvent * >::const_iterator LCE_ITER
 
typedef map< trait_t, TraitPrototype * >::const_iterator TRAIT_ITER
 
- Protected Attributes inherited from SimBuilder
list< ParamSet * > _currentParams
 List of the selected simulation components from the user defined input parameters. More...
 
map< trait_t, TraitPrototype * > _currentTraits
 List of the selected trait prototypes from the user defined input parameters. More...
 
map< int, LifeCycleEvent * > _LifeCycle
 List of the selected life cycle events from the user defined input parameters. More...
 
- Protected Attributes inherited from ParamManager
list< ParamSet * > _allParams
 A list of all the parameter sets of all the simulation components loaded in the _component list of the ComponentManager. More...
 
map< string, string > _inputParams
 A map of the parameters and their arguments of the current (running) simulation. More...
 
map< unsigned int, list< pair< string, string > > > _temporalParams
 Lists of parameters to be updated during a simulation indexed by generation update time. More...
 
list< map< string, string > > _simRecords
 Sets of parameters of all the simulations to perform. More...
 
ParamSet _paramSet
 The ParamSet param set of the simulation. More...
 
- Protected Attributes inherited from ComponentManager
list< SimComponent * > _components
 List of all the simulation components. More...
 
list< TraitPrototype * > _TTrait_Templates
 List of all trait prototypes of the simulation, a subset of _components list. More...
 
list< LifeCycleEvent * > _LCE_Templates
 List of all the life-cycle events of the simulation, a subset of _components list. More...
 

Detailed Description

Performs the setup of the Metapop and SimComponents and runs the simulation.

This class implements the two main loops of a simulation, the replicate and the generation loops. The replicate loop iterates the generation loop which itself iterates the life cycle loop composed of the LCEs selected by the user. A SimRunner brings together the basic simulation components and a metapopulation on which they act. It perfoms the setups necessary to have a Metapop ready for the simulation and runs the different simulations stored in its ParamManager base class. Also hosts the file and stat services.

Constructor & Destructor Documentation

◆ SimRunner()

SimRunner::SimRunner ( Metapop pop)
inline
109  {
110  attach_pop(pop);
111  }
void attach_pop(Metapop *pop)
Attach a pop to the simulation.
Definition: simulation.h:168
MPImanager * _my_mpi_manager
Definition: simulation.h:56
bool _do_postexec_replicatewise
Boolean to trigger replicate-wise execution of post script.
Definition: simulation.h:94
bool _do_postexec
Boolean set when a post-exec script must be executed.
Definition: simulation.h:96

References attach_pop().

◆ ~SimRunner()

SimRunner::~SimRunner ( )

Dstror.

180 {
181 #ifdef _DEBUG_
182  message("SimRunner::~SimRunner\n");
183 #endif
184 
185  reset();
186 
187 }
void reset()
Resets all the parameters to the unset state, resets the services.
Definition: simulation.cc:191
void message(const char *message,...)
Definition: output.cc:40

References message(), and reset().

Member Function Documentation

◆ attach_pop()

void SimRunner::attach_pop ( Metapop pop)
inline

Attach a pop to the simulation.

Adds it to the components list.

Parameters
popptr to the pop object
168 {_thePop = pop;this->_components.push_back(_thePop);}
list< SimComponent * > _components
List of all the simulation components.
Definition: basicsimulation.h:71
Metapop * _thePop
Definition: simulation.h:58

References ComponentManager::_components, and _thePop.

Referenced by SimRunner().

◆ build_pop()

bool SimRunner::build_pop ( )

Calls the Metapop init procedure with current traits and LCEs.

◆ Cycle()

void SimRunner::Cycle ( char *  startTime)

Life cycle loop, executes the list of LCEs _generations times.

Parameters
startTimethe starting time of the current replicate.
640 {
641 
642  time_t t;
643  // ------------------------------ CYCLE --------------------------------
644 
646 
647  // -------------------------- PRINT STUFF ------------------------------
648 #if !defined(LOW_VERBOSE) && !defined(USE_MPI)
649 
650  if( !(_currentGeneration % 100) || _currentGeneration < 100){
651  //update timer:
652  t = time(0);
653  strftime(startTime, 10, "%H:%M:%S", localtime(&t));
654 
655  message("\r replicate %i/%i [%s] %i/%i", _currentReplicate, _replicates
656  ,startTime, _currentGeneration, _generations);
657 
658  fflush(stdout);
659  }
660 #endif
661 
662 #ifdef _DEBUG_
663  message("____Generation %i/%i____\n", _currentGeneration, _generations);
664 #endif
665 
666  // -------------------------- STEP ONE GEN ------------------------------
668 
669  // do one iteration of the life cycle:
670  if(_thePop->isAlive())
671 
672  step(1);
673 
674  else {
675 #if !defined(LOW_VERBOSE) && !defined(USE_MPI)
676  message("\r replicate %i/%i [%s] %i/%i -> Pop extinction !\n", _currentReplicate, _replicates
677  ,startTime, _currentGeneration, _generations);
678 #endif
680  break;
681  }
682 
683  }
684  // --------------------------- END OF CYCLE --------------------------
685 }
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:298
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:309
unsigned int _replicates
Number of replicates to iterate.
Definition: simulation.h:74
void step(unsigned int nb_gen)
Iterates the life cycle.
Definition: simulation.cc:709
unsigned int _generations
Number of generations to iterate.
Definition: simulation.h:72
unsigned int _currentReplicate
The current replicate in the replicate loop, starts at 1.
Definition: simulation.h:76
unsigned int _currentGeneration
The current generation in the generation loop, starts at 1.
Definition: simulation.h:78

References _currentGeneration, _currentReplicate, _generations, _replicates, _thePop, Metapop::isAlive(), message(), Metapop::setCurrentGeneration(), and step().

Referenced by Replicate_LOOP().

◆ get_allRegisteredStats()

list<StatRecBase*> SimRunner::get_allRegisteredStats ( )
inline

Returns the complete list of the stat recorders loaded after parameters initialization.

152 {return _StatServices.getAllStats();}
StatServices _StatServices
Definition: simulation.h:102
list< StatRecBase * > getAllStats()
Definition: statservices.cc:405

References _StatServices, and StatServices::getAllStats().

◆ get_FileServices()

FileServices* SimRunner::get_FileServices ( )
inline

Returns the FileServices.

148 {return &_FileServices;}
FileServices _FileServices
Definition: simulation.h:100

References _FileServices.

Referenced by Metapop::loadPopFromTraitFile().

◆ get_pop()

Metapop* SimRunner::get_pop ( )
inline

Accessor to the pop ptr.

Returns
the pop ptr
172 {return _thePop;}

References _thePop.

◆ get_StatServices()

StatServices* SimRunner::get_StatServices ( )
inline

Returns the StatServices.

150 {return &_StatServices;}

References _StatServices.

Referenced by LCE_StatServiceNotifier::LCE_StatServiceNotifier().

◆ getCurrentGeneration()

unsigned int SimRunner::getCurrentGeneration ( )
inline
190 {return _currentGeneration;}

References _currentGeneration.

Referenced by SIMenv::getCurrentGeneration().

◆ getCurrentRankInLifeCycle()

int SimRunner::getCurrentRankInLifeCycle ( )
inline
197 {return _currentRankInLifeCycle;}
int _currentRankInLifeCycle
The current rank in the life cycle, corresponds to the rank of the current LCE, before it executes.
Definition: simulation.h:80

References _currentRankInLifeCycle.

Referenced by SIMenv::getCurrentRankInLifeCycle().

◆ getCurrentReplicate()

unsigned int SimRunner::getCurrentReplicate ( )
inline
194 {return _currentReplicate;}

References _currentReplicate.

Referenced by SIMenv::getCurrentReplicate().

◆ getGenerations()

unsigned int SimRunner::getGenerations ( )
inline
192 {return _generations;}

References _generations.

Referenced by SIMenv::getGenerations().

◆ getReplicates()

unsigned int SimRunner::getReplicates ( )
inline
196 {return _replicates;}

References _replicates.

Referenced by SIMenv::getReplicates().

◆ init()

bool SimRunner::init ( )

Checks simulation parameters and init the FileServices with the base filename.

69 {
70  if( !(_paramSet.isSet("filename")) ) {
71  return error("parameter \"filename\" is not properly set!\n");
72  }
73 
75 
76  if(_paramSet.isSet("root_dir")) {
78  }
79 
80  if(_paramSet.isSet("run_mode")) {
81 
82  _modeArg = _paramSet.getArg("run_mode");
83 
84  if(_modeArg == "run"){
85 
87  _doRun = true;
88  _mode = 0;
89  SILENT_RUN = false; //declared in output.h
90 
91  } else if( _modeArg == "overwrite" ) {
92 
94  _doRun = true;
95  _mode = 1;
96  SILENT_RUN = false;
97 
98  } else if(_modeArg == "skip"){
99 
101  _doRun = true;
102  _mode = 2;
103  SILENT_RUN = false;
104 
105  } else if(_modeArg == "dryrun" || _modeArg == "dry"){
106 
108  _doRun = false;
109  _mode = 3;
110  SILENT_RUN = false;
111 
112  } else if(_modeArg == "create_init"){ //the logWriter creates an ini file, see FileServices::log_simparams()
113 
115  _doRun = false;
116  _mode = 4;
117  SILENT_RUN = false;
118 
119  } else if(_modeArg == "silent_run" || _modeArg == "silent"){
120 
121  _FileServices.setMode(2); // skip simulation if files from previous sims are found, o/w it hangs
122  _doRun = true;
123  _mode = 2;
124  SILENT_RUN = true;
125 
126  } else {
127 
128  error("simulation run mode \"%s\" unknown\n",_modeArg.c_str());
129 
130  return false;
131 
132  }
133  // else, set default run mode values (skip):
134  } else {
135  _modeArg = "skip";
136  _doRun = true;
138  SILENT_RUN = false;
139  }
140 
141  _replicates = (unsigned int)_paramSet.getValue("replicates");
142 
143  _generations = (unsigned int)_paramSet.getValue("generations");
144 
145 
146  if( _paramSet.isSet("logfile") ) {
147  _logfile = _paramSet.getArg("logfile");
148  } else {
149  _logfile = "nemo.log";
150  }
151 
152  // create the simulation logging file
153  printLogHeader();
154 
155  // set POSTEXEC options:
156  if( _paramSet.isSet("postexec_script") ) {
157  _postexec_script = _paramSet.getArg("postexec_script");
158  _do_postexec = true;
159 
160  if( _paramSet.isSet("postexec_args") )
161  _postexec_args = _paramSet.getArg("postexec_args");
162  else
163  _postexec_args = "";
164 
165  if( _paramSet.isSet("postexec_replicate_wise") )
167  else
169 
170 
171  } else
172  _do_postexec = false;
173 
174  return true;
175 }
void setBasename(string name)
Sets the base file name of the simulation.
Definition: fileservices.cc:486
void setMode(unsigned int m)
Mode setter, determines if file will get overwritten or not.
Definition: fileservices.h:117
void setRootDir(string name)
Sets the root directory of the simulation.
Definition: fileservices.cc:493
ParamSet _paramSet
The ParamSet param set of the simulation.
Definition: basicsimulation.h:151
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:300
double getValue(string name)
Accessor the parameters value.
Definition: param.h:302
bool isSet()
Accessor to the status flag.
Definition: param.h:288
std::string _postexec_args
Arguments to pass to the post-exec script.
Definition: simulation.h:92
unsigned int _mode
The run mode code (0 = run, 1 = overwrite, 2 = skip, 3 = dryrun, 4 = create_init)
Definition: simulation.h:86
std::string _logfile
Definition: simulation.h:60
bool _doRun
Boolean set when not in dryrun mode.
Definition: simulation.h:88
std::string _postexec_script
The path to the script to be executed after last simulation.
Definition: simulation.h:90
std::string _modeArg
The run mode ('overwrite', 'run', 'skip', 'dryrun', 'create_init').
Definition: simulation.h:84
void printLogHeader()
Definition: simulation.cc:751
bool SILENT_RUN
Definition: output.cc:37
int error(const char *str,...)
Definition: output.cc:77

References _do_postexec, _do_postexec_replicatewise, _doRun, _FileServices, _generations, _logfile, _mode, _modeArg, ParamManager::_paramSet, _postexec_args, _postexec_script, _replicates, error(), ParamSet::getArg(), ParamSet::getValue(), ParamSet::isSet(), printLogHeader(), FileServices::setBasename(), FileServices::setMode(), FileServices::setRootDir(), and SILENT_RUN.

Referenced by init_components().

◆ init_components()

bool SimRunner::init_components ( map< string, string > &  simparams)

Performs the initialization of the different components of the simulation.

Builds the list of the simulation parameters and load the components that have their ParamSet in the set state. Builds the population, the TraitPrototype, and life cycle, register the various services and init the StatServices and ParameterUpdaterManager.

Parameters
simparamsthe hashtable containing the parameters and their arguments parsed from the init file
253 {
254 #ifdef _DEBUG_
255  message("SimRunner::init_components\n");
256 #endif
257  //first reset all paramSets and services (clear the handlers' lists)
258  reset();
259 
262 
263 #ifdef _DEBUG_
264  message("SimRunner::init_components: building current params\n");
265 #endif
266 
267  //build the list of active component parameters from the simulation record:
268  if(!this->build_currentParams(simparams)){
269  error("SimRunner::init_components:couldn't build current params\n");
270  return false;
271  }
272 
273  //initialize the random generator's seed:
274  //if(_myenv->isMaster()) // in MPI context, all processes must initialize the generator
276 
277  //init the sim and pop (set parameters from input values)
278  if( !init() || !_thePop->init() ) return false;
279 
280  //propagate replicate and generation numbers to metapop, often used by LCEs
283 
284  //the traits and LCEs components are set only after the simulation and
285  //population parameters are set
286 
287  //build the Individual prototype, and init the TTraits
288  //---> SimComponents::setParameters() is called here, this will also build the genetic map
290 
291  //build the list of life cycle events, and init LCEs
292  //---> SimComponent::setParameters() is called here
293  setLifeCycle( );
294 
295  //load the stat-, file-, and updater-handlers of the simulation components:
297 
298  //StatServices: build the lists of stat recorders:
299  if( !_StatServices.init() ) return false;
300 
301  if( !_ParamUpdaterManager.init() ) return false;
302 
305  updater->setManager( &_ParamUpdaterManager );
306  updater->init(_thePop);
307  _LifeCycle[ -1 ] = updater; //this is never destroyed...
308  }
309 
310  return true;
311 }
virtual void set_pop_ptr(Metapop *pop)
Sets the Metapop reference.
Definition: fileservices.h:114
void makePrototype(map< trait_t, TraitPrototype * > TTlist)
Creates the individuals prototype from the selected trait prototypes.
Definition: indfactory.cc:50
Calls the UpdaterServices to notify its components of a generation change.
Definition: servicenotifiers.h:41
void setManager(UpdaterServices *mng)
Definition: servicenotifiers.h:51
virtual void init(Metapop *popPtr)
Sets the pointer to the current Metapop and the trait link if applicable.
Definition: lifecycleevent.h:114
void setReplicates(unsigned int repl)
Definition: metapop.h:274
bool init()
Inits the population parameters from the ParamSet and builds the pop (adds patches),...
Definition: metapop.cc:97
void setGenerations(unsigned int gen)
Definition: metapop.h:272
bool build_currentParams(map< string, string > &simparams)
Builds the list of parameters from user's defined input parameters.
Definition: basicsimulation.cc:720
map< int, LifeCycleEvent * > _LifeCycle
List of the selected life cycle events from the user defined input parameters.
Definition: basicsimulation.h:224
map< trait_t, TraitPrototype * > & build_currentTraits()
Selects the trait prototypes that have their parameters set.
Definition: basicsimulation.cc:746
UpdaterServices _ParamUpdaterManager
Definition: simulation.h:104
bool init()
Checks simulation parameters and init the FileServices with the base filename.
Definition: simulation.cc:68
void setLifeCycle()
Sets the list of LifeCyckeEvent's currently active.
Definition: simulation.cc:242
void init_random_seed()
Initialize the seed of the random generator.
Definition: simulation.cc:315
void register_component_handlers()
Register all the Handlers of the currently active simulation components.
Definition: simulation.cc:229
virtual bool init()
Definition: statservices.cc:47
void set_pop_ptr(Metapop *pop)
Definition: statservices.h:108
bool hasTemporals()
Checks if any updater has been uploaded.
Definition: updaterservices.h:92
virtual bool init()
Definition: updaterservices.cc:39

References _FileServices, _generations, SimBuilder::_LifeCycle, _ParamUpdaterManager, _replicates, _StatServices, _thePop, SimBuilder::build_currentParams(), SimBuilder::build_currentTraits(), error(), UpdaterServices::hasTemporals(), Metapop::init(), init(), StatServices::init(), UpdaterServices::init(), LifeCycleEvent::init(), init_random_seed(), IndFactory::makePrototype(), message(), register_component_handlers(), reset(), FileServices::set_pop_ptr(), StatServices::set_pop_ptr(), Metapop::setGenerations(), setLifeCycle(), LCE_ParamUpdaterNotifier::setManager(), and Metapop::setReplicates().

Referenced by run().

◆ init_random_seed()

void SimRunner::init_random_seed ( )

Initialize the seed of the random generator.

316 {
317  if(_myenv->isMaster()) {
318 
319  if(this->_paramSet.isSet("random_seed")) {
320 
321  _random_seed = (unsigned long) this->_paramSet.getValue("random_seed");
322 
323  message( "setting random seed from input value: %i\n", _random_seed);
324 
325  } else {
326  //set the random seed from the current time
327  _random_seed = 2*time(0)+1;
328 
329  message( "setting random seed from current time: %i\n", _random_seed);
330  }
331  }
332 
333 #if defined(USE_MPI) && defined(HAS_SPRNG)
334 
335  // broadcast the random seed, needs to be equal on all processes with SPRNG
336  MPI_Bcast(&_random_seed,1,MPI_LONG,0,MPI_COMM_WORLD );
337 
338 #else
339 #endif
340 
341  //initialization in any case
343 
344 }
bool isMaster() const
Definition: MPImanager.h:128
static void init(unsigned long seed)
Initialize the random generator's seed.
Definition: Uniform.h:82
unsigned long _random_seed
The startup random seed of the random generator.
Definition: simulation.h:82
MPIenv * _myenv
Definition: MPImanager.cc:36

References _myenv, ParamManager::_paramSet, _random_seed, ParamSet::getValue(), RAND::init(), MPIenv::isMaster(), ParamSet::isSet(), and message().

Referenced by init_components().

◆ printLog()

void SimRunner::printLog ( )
780 {
781  ofstream FH(_logfile.c_str(),ios::app);
782 
783  if(!FH.is_open()){
784  error("could not open simulation logfile \"%s\"\n",_logfile.c_str());
785  return;
786  }
787 
788  FH<<"| ";
789  FH.width(40);
790  FH.setf(ios::left,ios::adjustfield);
792 
793  FH <<"| "<< _startTime <<" | "<< _endTime <<" | ";
794 
795  FH.width(10);
796  FH.setf(ios::right,ios::adjustfield);
797  FH<< _simElapsedTime <<" | ";
798 
799  FH.width(9);
800  FH << _replicates <<" | ";
801 
802  FH.width(10);
803  FH << setElapsedTime( _meanReplElapsedTime ) << " | ";
804 
805  FH.width(8);
806  FH << _meanGenLength <<" | ";
807 
808  FH<<" "<<MAIN_VERSION<<"."<<MINOR_VERSION<<"."<<REVISION<<RELEASE
809  <<" "<<VERSION_DATE;
810 
811  FH<<" | ";
812  FH.width(20);
813  FH.setf(ios::left,ios::adjustfield);
814  char* host;
815  if( (host = getenv("HOST")) != NULL )
816  FH << host << " |";
817  else if ( (host = getenv("HOSTNAME")) != NULL )
818  FH << host << " |";
819  else
820  FH << "-" << " |";
821 
823 
824  for(;file != last; file++)
825  FH << " \"" << (*file)->get_extension() << "\":" << (*file)->get_path();
826 
827  FH << std::endl;
828 
829  FH.close();
830 }
file_it getFirstWriter()
Accessor to first element of the list of output FileHandlers.
Definition: fileservices.h:138
file_it getLastWriter()
Accessor to last element of the list of output FileHandlers.
Definition: fileservices.h:141
std::list< FileHandler * >::const_iterator file_it
Definition: fileservices.h:93
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:446
clock_t _meanReplElapsedTime
Clock counter, for logging.
Definition: simulation.h:66
char _startTime[20]
Definition: simulation.h:62
std::string setElapsedTime(clock_t time)
Compute and print the simulation's elapsed time to stdout.
Definition: simulation.cc:726
unsigned int _meanGenLength
Generation counter, for logging.
Definition: simulation.h:68
char _endTime[20]
Definition: simulation.h:62
std::string _simElapsedTime
Definition: simulation.h:64
#define VERSION_DATE
Definition: version.h:30
#define MINOR_VERSION
Definition: version.h:27
#define RELEASE
Definition: version.h:29
#define MAIN_VERSION
Definition: version.h:26
#define REVISION
Definition: version.h:28

References _endTime, _FileServices, _logfile, _meanGenLength, _meanReplElapsedTime, _replicates, _simElapsedTime, _startTime, error(), FileServices::getBaseFileName(), FileServices::getFirstWriter(), FileServices::getLastWriter(), MAIN_VERSION, MINOR_VERSION, RELEASE, REVISION, setElapsedTime(), and VERSION_DATE.

Referenced by run().

◆ printLogHeader()

void SimRunner::printLogHeader ( )
752 {
753  ofstream FH;
754  ifstream IF;
755  //check is the logfile already exists:
756  IF.open(_logfile.c_str(),ios::in);
757  if(IF){
758  IF.close();
759  return;
760  }
761  IF.close();
762 
763  FH.open(_logfile.c_str(),ios::out);
764  if(!FH) {
765  error("could not create simulation logfile \"%s\"\n",_logfile.c_str());
766  return;
767  }
768 
769  FH<<"--- N E M O ---\n"
770  <<" LOGFILE\n\n\n";
771  FH<<"| basename | start time | stop time | e-time CPU |"
772  <<" repl done | rpl e-time | mean gen | version | hostname | output files \n";
773 
774  FH.close();
775 }

References _logfile, and error().

Referenced by init().

◆ register_component()

void SimRunner::register_component ( SimComponent cmpt)

Register the different Handler's attached to a SimComponent.

Parameters
cmpta SimComponent
221 {
222  _FileServices.load(cmpt);
223  _StatServices.load(cmpt);
225 }
virtual void load(SimComponent *sc)
Tells the SimComponent to load its file handlers.
Definition: fileservices.cc:82
virtual void load(SimComponent *sc)
tell the SimComponent to load its stat handlers
Definition: statservices.cc:170
virtual void load(SimComponent *sc)
Loads the updaters in case a component's parameter has temporal arguments.
Definition: updaterservices.cc:82

References _FileServices, _ParamUpdaterManager, _StatServices, FileServices::load(), StatServices::load(), and UpdaterServices::load().

Referenced by register_component_handlers().

◆ register_component_handlers()

void SimRunner::register_component_handlers ( )

Register all the Handlers of the currently active simulation components.

230 {
232 
233  for(TRAIT_ITER trait = _currentTraits.begin(); trait != _currentTraits.end(); trait++)
234  register_component(trait->second);
235 
236  for(LCE_ITER LCE = _LifeCycle.begin(); LCE != _LifeCycle.end(); LCE++)
237  register_component(LCE->second);
238 }
map< trait_t, TraitPrototype * > _currentTraits
List of the selected trait prototypes from the user defined input parameters.
Definition: basicsimulation.h:222
map< int, LifeCycleEvent * >::const_iterator LCE_ITER
Definition: basicsimulation.h:226
map< trait_t, TraitPrototype * >::const_iterator TRAIT_ITER
Definition: basicsimulation.h:227
void register_component(SimComponent *cmpt)
Register the different Handler's attached to a SimComponent.
Definition: simulation.cc:220

References SimBuilder::_currentTraits, SimBuilder::_LifeCycle, _thePop, and register_component().

Referenced by init_components().

◆ Replicate_LOOP()

void SimRunner::Replicate_LOOP ( )

Replicate loop, iterates the life cycle _replicates times.


520 {
521 
522 #ifndef USE_MPI
523 
524  clock_t start;
525  clock_t stop;
526  time_t t;
527  char t_buff[10];
528 
530  _meanGenLength = 0;
531  _currentGeneration = 0;
532 
533  //---------------------------------- REPLICATE LOOP -------------------------------------
535 
536 
537  // -------------------------- PRINT STUFF ------------------------------
538  t=time(0);
539  //print some output:
540  strftime(t_buff,10,"%H:%M:%S",localtime(&t));
541 
542 #ifdef LOW_VERBOSE
543  message(" replicate %i/%i [%s] \n",_currentReplicate, _replicates, t_buff);
544 #else
545  message("\r replicate %i/%i [%s] 1/%i ",_currentReplicate, _replicates, t_buff, _generations);
546  fflush(stdout);
547 #endif
548 
549  //---------------- SET POPULATION FOR FIRST GENERATION ------------------
550 
552 
553  //--------------------------- GENERATION LOOP ---------------------------
554  start = clock();
555 
556  Cycle(t_buff);
557 
558  stop = clock();
559  //-----------------------------------------------------------------------
560 
561  _meanReplElapsedTime += (stop - start);
562 
564 
565  //call the file services to print the replicate stats in case of pop extinction
566  if( !_thePop->isAlive() && _currentGeneration-1 <= _generations ) {
570  }
571 
572  if( _do_postexec_replicatewise ) runPostExecReplicateWise(); //will execute on each node
573  }
574  //--------------------------------- /REPLICATE LOOP -------------------------------------
575 
582  }
583 
586 
587 #else
588  //else ifndef USE_MPI
589  //------------------------------- MPI REPLICATE LOOP ------------------------------------
591 
592  while ( _currentReplicate <= _replicates )
594 
596 
597  if( _myenv->isMaster() ) {
602 
603  //write the stat files, only if "save_stats" LCE is part of the life cycle
604  if(get_LCE("save_stats")->get_paramset()->isSet()) {
605  FileHandler& statWriter = dynamic_cast<LCE_StatServiceNotifier*> ( get_LCE("save_stats") )->getFH();
606  for (unsigned int i = 1; i <= _replicates; ++i) {
607  _currentReplicate = i;
608  statWriter.FHwrite();
609  }
610  }
611  }
612  //------------------------------ /MPI REPLICATE LOOP ------------------------------------
613 #endif
614  //endif USE_MPI
615 
616  //delete all individuals present in the population and delete the patches:
617  _thePop->clear();
618 }
LifeCycleEvent * get_LCE(string name)
Search for component with "name" in the life cycle events list.
Definition: basicsimulation.cc:76
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:53
virtual void FHwrite()=0
Default behavior of the class, called by Handler::update().
virtual void notify()
Definition: fileservices.cc:189
Initiates the StatServices' parameters (log time) when registering, calls StatServices::notify() when...
Definition: servicenotifiers.h:163
virtual unsigned int init(StatServices *StatManager)=0
virtual void iterate(SimRunner *_sim, StatServices *StatManager, unsigned int *_gen, unsigned int *_repl)=0
virtual void finish(StatServices *StatManager, unsigned int *_gen, unsigned int _repl)
void setCurrentReplicate(unsigned int repl)
Definition: metapop.h:297
void clear()
Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are ...
Definition: metapop.cc:1192
ParamSet * get_paramset(string &name)
Looks for paramset with "name" in the list of parameter sets.
Definition: basicsimulation.cc:231
void setForFirstGeneration()
Sets the population and the services ready for the first generation of a new replicate.
Definition: simulation.cc:622
void Cycle(char *startTime)
Life cycle loop, executes the list of LCEs _generations times.
Definition: simulation.cc:639
void runPostExecReplicateWise()
Run the post-exec script after each replicate, adds filename and replicate number as args.
Definition: simulation.cc:859

References _currentGeneration, _currentReplicate, _do_postexec_replicatewise, _FileServices, _generations, _meanGenLength, _meanReplElapsedTime, _my_mpi_manager, _myenv, _replicates, _StatServices, _thePop, Metapop::clear(), Cycle(), FileHandler::FHwrite(), MPImanager::finish(), ComponentManager::get_LCE(), ParamManager::get_paramset(), MPImanager::init(), Metapop::isAlive(), MPIenv::isMaster(), MPImanager::iterate(), message(), FileServices::notify(), runPostExecReplicateWise(), Metapop::setCurrentGeneration(), Metapop::setCurrentReplicate(), and setForFirstGeneration().

Referenced by run().

◆ reset()

void SimRunner::reset ( )

Resets all the parameters to the unset state, resets the services.

192 {
193 #ifdef _DEBUG_
194  message("SimRunner::reset\n");
195 #endif
196  //reset all the parameter to the "unset" state
197  list<ParamSet*>::iterator current_paramset = this->_allParams.begin();
198  while(current_paramset != this->_allParams.end()) {
199  (*current_paramset)->reset();
200  current_paramset++;
201  }
202 
203  reset_services();
204 }
list< ParamSet * > _allParams
A list of all the parameter sets of all the simulation components loaded in the _component list of th...
Definition: basicsimulation.h:143
void reset_services()
Resets the FileServices and StatServices.
Definition: simulation.cc:208

References ParamManager::_allParams, message(), and reset_services().

Referenced by init_components(), and ~SimRunner().

◆ reset_services()

void SimRunner::reset_services ( )

Resets the FileServices and StatServices.

209 {
213 #ifdef _DEBUG_
214  message("SimRunner::reset_services::done\n");
215 #endif
216 }
virtual void reset()
Clears the list of FileHandlers.
Definition: fileservices.cc:374
virtual void reset()
clear the list of StatHandler
Definition: statservices.cc:208
virtual void reset()
Clears the containers.
Definition: updaterservices.cc:61

References _FileServices, _ParamUpdaterManager, _StatServices, message(), FileServices::reset(), StatServices::reset(), and UpdaterServices::reset().

Referenced by reset().

◆ run() [1/2]

bool SimRunner::run ( )

First loop of the simulation, performs the simulations stored in the ParamManager base class.

400 {
401  time_t t;
402  unsigned int sim = 0, simnbre = _simRecords.size();
403 
404  list< map< string,string > >::iterator currentSim = _simRecords.begin();
405 
406  //first loop: perform all simulations contained in _simRecords:
407  //---------------------------------------------------------------------------------------
408  while(currentSim != _simRecords.end()) {
409 
410  sim++;
411 
412  //clear and build the lists of traits, LCEs, stats and files handlers, random seed
413  //create trait prototypes and the genetic map within IndFactory::makePrototype
414  if(!init_components(*currentSim)) return false;
415 
416  //output a few info:
417  if ( _myenv->isMaster() ) {
418 
419  t = time(NULL);
420 
421  strftime(_startTime, 20, "%d-%m-%Y %H:%M:%S", localtime(&t));
422 
423  message("\n--- SIMULATION %i/%i ---- [ %s ]\n\n",sim,simnbre,_FileServices.getBaseFileName().c_str());
424  message(" start: %s\n",_startTime);
425  message(" mode: %s\n",_modeArg.c_str());
426  message(" population: 2 stages, %i patch%s",
427  _thePop->getPatchNbr(), (_thePop->getPatchNbr() > 1 ? "es" : ""));
428 
429  // Wright-Fisher population?
430  if(get_LCE("breed")->get_parameter("mating_isWrightFisher")->isSet() ||
431  get_LCE("breed_selection")->get_parameter("mating_isWrightFisher")->isSet())
432  message(", Wright-Fisher\n");
433  else
434  message(", non Wright-Fisher\n");
435 
436  message(" traits: ");
437 
438  map<trait_t, TraitPrototype* >::iterator trait = _currentTraits.begin();
439 
440  while(trait != _currentTraits.end()) {
441  message("%s",trait->first.c_str());
442  message("(%i)", _thePop->getTraitIndex(trait->first.c_str()));
443  trait++;
444  if(trait != _currentTraits.end()) message(", ");
445  }
446 
447  message("\n LCEs: ");
448 
449  LCE_ITER LCE = _LifeCycle.begin();
450  while( LCE != _LifeCycle.end()) {
451  message("%s(%i)",LCE->second->get_event_name().c_str(),LCE->first);
452  LCE++;
453  if(LCE != _LifeCycle.end()) message(", ");
454  }
455 
456  message("\n");
457  }
458 
459  //init the file services:
460  //->files check, false means the user wants to skip this simulation.
461  if( !(_FileServices.init(this->_currentParams)) ) {
462  currentSim++;
464  continue;
465  }
466 
467  // Load the population from a source file?
468  if(_thePop->isSourceLoad()) {
469  message(" loading population from: %s (%s)\n",_thePop->getSourceName().c_str(),
470  _thePop->getSourceFileType().c_str());
471  } // endif isSourceLoad
472 
473  if ( _myenv->isMaster() ) message("\n");
474 
475  //->save simulation parameters in log files, add the current random seed
476  // this is where ini files are created in `run_mode create_init' (mode == 4)
478  _FileServices.log("#random_seed "+tstring::ulong2str( _random_seed ));
479 
480  clock_t start = clock();
481 
482  //run the simulation
483  //-------------------------------------------------------------------------------------
484  if(_doRun) Replicate_LOOP( );
485 
486  clock_t stop = clock();
487 
488  t = time(NULL);
489 
490  strftime(_endTime, 20, "%d-%m-%Y %H:%M:%S", localtime(&t));
491 
492  _simElapsedTime = setElapsedTime(stop - start);
493 
494  if ( _myenv->isMaster() && _mode != 3 && _mode != 4) {
495  printLog();
496  message("\n\n end: %s\n",_endTime);
497  message("--- done (CPU time: %ss)\n",_simElapsedTime.c_str());
498  //don't log this when in 'dryrun' or 'create_init' mode:
499  _FileServices.log("\n# simulation finished " + string(_endTime));
500  _FileServices.log("# CPU time used: " + _simElapsedTime + "s");
501  }
502 
504 
505  // free all allocated memory of the random number generator
506  // it will be re-allocated in `init_components -> ini_random_seed'
507  RAND::free();
508 
509  currentSim++;
510  }
511  //---------------------------------------------------------------------------------------
512  if( _do_postexec && _myenv->isMaster() ) runPostExec();
513 
514  return true;
515 }
void log(string message)
Write to the parameter logfile.
Definition: fileservices.cc:407
virtual bool init()
Definition: fileservices.h:99
void log_simparams()
Saves the current simulation parameters to the default parameter logfile.
Definition: fileservices.cc:397
int getTraitIndex(trait_t type)
Gives the index of trait with type.
Definition: indfactory.cc:128
void clearPrototype()
Reset the trait prototypes, mostly done to unregister the genetic maps.
Definition: indfactory.cc:103
bool isSourceLoad()
Definition: metapop.h:282
unsigned int getPatchNbr()
Definition: metapop.h:276
string getSourceFileType()
Definition: metapop.h:284
string getSourceName()
Definition: metapop.h:283
list< map< string, string > > _simRecords
Sets of parameters of all the simulations to perform.
Definition: basicsimulation.h:149
static void free()
Memory de-allocation.
Definition: Uniform.h:108
void runPostExec()
Run the post-exec script after all simulations have finished.
Definition: simulation.cc:834
bool init_components(map< string, string > &simparams)
Performs the initialization of the different components of the simulation.
Definition: simulation.cc:252
void printLog()
Definition: simulation.cc:779
void Replicate_LOOP()
Replicate loop, iterates the life cycle _replicates times.
Definition: simulation.cc:519
static string ulong2str(const unsigned long i)
Writes an integer value into a string.
Definition: tstring.h:105

References SimBuilder::_currentTraits, _do_postexec, _doRun, _endTime, _FileServices, SimBuilder::_LifeCycle, _mode, _modeArg, _myenv, _random_seed, _simElapsedTime, ParamManager::_simRecords, _startTime, _thePop, IndFactory::clearPrototype(), RAND::free(), ComponentManager::get_LCE(), FileServices::getBaseFileName(), Metapop::getPatchNbr(), Metapop::getSourceFileType(), Metapop::getSourceName(), IndFactory::getTraitIndex(), FileServices::init(), init_components(), MPIenv::isMaster(), Metapop::isSourceLoad(), FileServices::log(), FileServices::log_simparams(), message(), printLog(), Replicate_LOOP(), runPostExec(), setElapsedTime(), and tstring::ulong2str().

Referenced by run().

◆ run() [2/2]

bool SimRunner::run ( int  ARGC,
char **  ARGV 
)

First loop of the simulation, performs the simulations stored in the ParamManager base class.

349 {
350 
351  //initialize the MPI environment:
352  _myenv = new MPIenv( &ARGC, &ARGV, _my_mpi_manager );
353 
354 
355  // initialize the random number generator with default seed
356  // it will be reinitialized later with user-provided seed, if any
357  RAND::init(time(0));
358 
359  //--------------------------------------------------------------------
360  if(_myenv->isMaster()) {
361 
362  START_MESSAGE();
363 
364  }
365 
366  //--------------------------------------------------------------------
367  //check for the presence of a metapop:
368  if(_thePop == NULL) fatal("SimRunner::run: no population is attached at startup!\n");
369 
370  //--------------------------------------------------------------------
371  //build the list of params from the components list
372  this->build_allParams();
373 
374  //--------------------------------------------------------------------
375  //get the input parameters from the input parameter file
376 
377  // create a stream parser attached to the file reader
378  FileParser Reader("");
379 
380  if (ARGC == 1)
381  build_records(Reader.getParsedParameters("Nemo2.ini")); // this calls StreamParser::ParamParser::getParsedParameters
382  else
383  for (int i = 1; i < ARGC; ++i)
384  build_records(Reader.getParsedParameters(ARGV[i]));
385 
386  //--------------------------------------------------------------------
387  //run the simulation
388  bool status = run();
389 
391 
392  delete _myenv;
393 
394  return status;
395 }
Text input parameter file parser.
Definition: fileparser.h:37
MPI environment setup.
Definition: MPImanager.h:122
static void finish(MPImanager *p)
Definition: MPImanager.cc:90
void build_records(map< string, vector< string > > &initParams)
Builds the list of simulation parameters from the parsed input file(s).
Definition: basicsimulation.cc:249
void build_allParams()
Clears and fills the _allParams list with the ParamSet's of the simulation components.
Definition: basicsimulation.cc:115
bool run()
First loop of the simulation, performs the simulations stored in the ParamManager base class.
Definition: simulation.cc:399
void fatal(const char *str,...)
Definition: output.cc:96
void START_MESSAGE()
Definition: version.h:33

References _my_mpi_manager, _myenv, _thePop, ParamManager::build_allParams(), ParamManager::build_records(), fatal(), MPIenv::finish(), ParamsParser::getParsedParameters(), RAND::init(), MPIenv::isMaster(), run(), and START_MESSAGE().

Referenced by main().

◆ run_event()

bool SimRunner::run_event ( string &  name)

Execute one specific life cycle event, if present in the list of current events.

Parameters
namethe name of the (paramSet of the) LifeCycleEvent to execute.
690 {
691  //before calling that fction, first set the params and call init_components()!!
692 
693  LifeCycleEvent* event = this->get_current_event(name);
694 
695  if(event == NULL) {
696  error("SimRunner::run_event:event \"%s\" not found in set events!\n",name.c_str());
697  return false;
698  }
699 
700  if( !(event->get_paramset()->isSet()) ) return false;//highly unlikely!!
701 
702  event->execute();
703 
704  return true;
705 }
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73
LifeCycleEvent * get_current_event(string &name)
Accessor to the list of current LCEs.
Definition: basicsimulation.cc:688

References error(), and SimBuilder::get_current_event().

◆ runPostExec()

void SimRunner::runPostExec ( )

Run the post-exec script after all simulations have finished.

835 {
836  ifstream script(_postexec_script.c_str(),ios::in);
837  string cmd;
838 
839  if(!script.is_open()) {
840  error("could not open post simulation shell script!\n");
841  return;
842  }
843 
844  message("Executing shell script \"%s\" ",_postexec_script.c_str());
845  fflush(stdout);
846 
847  cmd = "sh " + _postexec_script + " " + _postexec_args;
848 
849  if(system(cmd.c_str()) < 0){
850  error("execution of `sh %s %s' failed: %s\n",_postexec_script.c_str(), _postexec_args.c_str(),strerror(errno));
851  return;
852  }
853 
854  message("...done\n");
855 }

References _postexec_args, _postexec_script, error(), and message().

Referenced by run().

◆ runPostExecReplicateWise()

void SimRunner::runPostExecReplicateWise ( )

Run the post-exec script after each replicate, adds filename and replicate number as args.

860 {
861  ifstream script(_postexec_script.c_str(),ios::in);
862  string cmd;
863 
864  if(!script.is_open()) {
865  error("could not open post simulation shell script!\n");
866  return;
867  }
868 
869  message("Executing shell script \"%s\" ",_postexec_script.c_str());
870  fflush(stdout);
871 
872  // runs the script with base sim filename and replicate number as two first arguments
874 
875  if(system(cmd.c_str()) < 0){
876  error("execution of `sh %s %s' failed: %s\n",_postexec_script.c_str(), _postexec_args.c_str(),strerror(errno));
877  return;
878  }
879 
880  message("...done\n");
881 }
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:95

References _currentReplicate, _FileServices, _postexec_args, _postexec_script, error(), FileServices::getBaseFileName(), tstring::int2str(), and message().

Referenced by Replicate_LOOP().

◆ setCurrentGeneration()

void SimRunner::setCurrentGeneration ( unsigned int  gen)
inline

◆ setCurrentReplicate()

void SimRunner::setCurrentReplicate ( unsigned int  repl)
inline

◆ setElapsedTime()

std::string SimRunner::setElapsedTime ( clock_t  time)

Compute and print the simulation's elapsed time to stdout.

Parameters
timeelapsed time in ticks count
727 {
728  int e_time = time / CLOCKS_PER_SEC;
729  int hour = e_time / 3600;
730  int minute = ((e_time % 3600) / 60);
731  int sec = (e_time % 3600) % 60;
732 
733  std::ostringstream out(ios::out);
734 
735  out.fill('0');
736  out.width(2);
737  out<<hour<<":";
738  out.width(2);
739  out<<minute<<":";
740  out.precision(2);
741  out.fill('0');
742  out.width(2);
743  out<<sec;
744 
745  return(out.str());
746 }

Referenced by printLog(), and run().

◆ setForFirstGeneration()

void SimRunner::setForFirstGeneration ( )

Sets the population and the services ready for the first generation of a new replicate.

623 {
625 
626  //reset temporal parameters/components to their first generation value/state
628 
629  //reset stat recording iterator to first occurrence
631 
632  //build metapopulation for the current replicate (build first generation)
634 
635 }
void setPopulation(unsigned int currentReplicate, unsigned int replicates)
Sets the population for the first generation of each replicates.
Definition: metapop.cc:708
void resetCurrentOccurrence()
Resets the occurrence iterator to the beginning of the list of generation occurrences.
Definition: statservices.h:138
virtual void notify()
Definition: updaterservices.h:78

References _currentReplicate, _ParamUpdaterManager, _replicates, _StatServices, _thePop, UpdaterServices::notify(), StatServices::resetCurrentOccurrence(), Metapop::setCurrentGeneration(), and Metapop::setPopulation().

Referenced by Replicate_LOOP().

◆ setGenerations()

void SimRunner::setGenerations ( unsigned int  gen)
inline

◆ setLifeCycle()

void SimRunner::setLifeCycle ( )

Sets the list of LifeCyckeEvent's currently active.

243 {
244  build_LifeCycle();
245 
246  for( LCE_ITER LCE = _LifeCycle.begin(); LCE != _LifeCycle.end(); LCE++)
247  LCE->second->init(_thePop);
248 }
void build_LifeCycle()
Selects the life cycle events that have their parameters set.
Definition: basicsimulation.cc:767

References SimBuilder::_LifeCycle, _thePop, and SimBuilder::build_LifeCycle().

Referenced by init_components().

◆ setReplicates()

void SimRunner::setReplicates ( unsigned int  repl)
inline

◆ step()

void SimRunner::step ( unsigned int  nb_gen)

Iterates the life cycle.

Parameters
nb_gennumber of iterations to perform.
710 {
711  LCE_ITER LCE = _LifeCycle.begin();
712 
713  while(LCE != _LifeCycle.end()) {
714  _currentRankInLifeCycle = LCE->second->get_rank();
715 #ifdef _DEBUG_
716  message("LCE rank %i: %s\n", _currentRankInLifeCycle, LCE->second->get_event_name().c_str());
717 #endif
718  LCE->second->execute();
719  _thePop->setCurrentAge(LCE->second);
720  LCE++;
721  }
722 }
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:303

References _currentRankInLifeCycle, SimBuilder::_LifeCycle, _thePop, message(), and Metapop::setCurrentAge().

Referenced by Cycle().

Member Data Documentation

◆ _currentGeneration

unsigned int SimRunner::_currentGeneration
private

The current generation in the generation loop, starts at 1.

Referenced by Cycle(), getCurrentGeneration(), Replicate_LOOP(), and setCurrentGeneration().

◆ _currentRankInLifeCycle

int SimRunner::_currentRankInLifeCycle
private

The current rank in the life cycle, corresponds to the rank of the current LCE, before it executes.

Referenced by getCurrentRankInLifeCycle(), and step().

◆ _currentReplicate

unsigned int SimRunner::_currentReplicate
private

The current replicate in the replicate loop, starts at 1.

Referenced by Cycle(), getCurrentReplicate(), Replicate_LOOP(), runPostExecReplicateWise(), setCurrentReplicate(), and setForFirstGeneration().

◆ _do_postexec

bool SimRunner::_do_postexec
private

Boolean set when a post-exec script must be executed.

Referenced by init(), and run().

◆ _do_postexec_replicatewise

bool SimRunner::_do_postexec_replicatewise
private

Boolean to trigger replicate-wise execution of post script.

Referenced by init(), and Replicate_LOOP().

◆ _doRun

bool SimRunner::_doRun
private

Boolean set when not in dryrun mode.

Referenced by init(), and run().

◆ _endTime

char SimRunner::_endTime[20]
private

Referenced by printLog(), and run().

◆ _FileServices

◆ _generations

unsigned int SimRunner::_generations
private

Number of generations to iterate.

Referenced by Cycle(), getGenerations(), init(), init_components(), Replicate_LOOP(), and setGenerations().

◆ _logfile

std::string SimRunner::_logfile
private

Referenced by init(), printLog(), and printLogHeader().

◆ _meanGenLength

unsigned int SimRunner::_meanGenLength
private

Generation counter, for logging.

Referenced by printLog(), and Replicate_LOOP().

◆ _meanReplElapsedTime

clock_t SimRunner::_meanReplElapsedTime
private

Clock counter, for logging.

Referenced by printLog(), and Replicate_LOOP().

◆ _mode

unsigned int SimRunner::_mode
private

The run mode code (0 = run, 1 = overwrite, 2 = skip, 3 = dryrun, 4 = create_init)

Referenced by init(), and run().

◆ _modeArg

std::string SimRunner::_modeArg
private

The run mode ('overwrite', 'run', 'skip', 'dryrun', 'create_init').

Referenced by init(), and run().

◆ _my_mpi_manager

MPImanager* SimRunner::_my_mpi_manager
private

Referenced by Replicate_LOOP(), and run().

◆ _ParamUpdaterManager

◆ _postexec_args

std::string SimRunner::_postexec_args
private

Arguments to pass to the post-exec script.

Referenced by init(), runPostExec(), and runPostExecReplicateWise().

◆ _postexec_script

std::string SimRunner::_postexec_script
private

The path to the script to be executed after last simulation.

Referenced by init(), runPostExec(), and runPostExecReplicateWise().

◆ _random_seed

unsigned long SimRunner::_random_seed
private

The startup random seed of the random generator.

Referenced by init_random_seed(), and run().

◆ _replicates

unsigned int SimRunner::_replicates
private

◆ _simElapsedTime

std::string SimRunner::_simElapsedTime
private

Referenced by printLog(), and run().

◆ _startTime

char SimRunner::_startTime[20]
private

Referenced by printLog(), and run().

◆ _StatServices

◆ _thePop


The documentation for this class was generated from the following files:

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR