Nemo  2.3.56
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
108 : _my_mpi_manager(0)
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

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().

+ Here is the caller graph for this function:

◆ 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.
626{
627
628 time_t t;
629 // ------------------------------ CYCLE --------------------------------
630
632
633 // -------------------------- PRINT STUFF ------------------------------
634#if !defined(LOW_VERBOSE) && !defined(USE_MPI)
635
636 if( !(_currentGeneration % 100) || _currentGeneration < 100){
637 //update timer:
638 t = time(0);
639 strftime(startTime, 10, "%H:%M:%S", localtime(&t));
640
641 message("\r replicate %i/%i [%s] %i/%i", _currentReplicate, _replicates
642 ,startTime, _currentGeneration, _generations);
643
644 fflush(stdout);
645 }
646#endif
647
648#ifdef _DEBUG_
649 message("____Generation %i/%i____\n", _currentGeneration, _generations);
650#endif
651
652 // -------------------------- STEP ONE GEN ------------------------------
654
655 // do one iteration of the life cycle:
656 if(_thePop->isAlive())
657
658 step(1);
659
660 else {
661#if !defined(LOW_VERBOSE) && !defined(USE_MPI)
662 message("\r replicate %i/%i [%s] %i/%i -> Pop extinction !\n", _currentReplicate, _replicates
663 ,startTime, _currentGeneration, _generations);
664#endif
666 break;
667 }
668
669 }
670 // --------------------------- END OF CYCLE --------------------------
671}
void setCurrentGeneration(unsigned int gen)
Definition: metapop.h:296
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:307
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:695
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().

+ Here is the caller graph for this function:

◆ 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:389

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().

+ Here is the caller graph for this function:

◆ 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().

+ Here is the caller graph for this function:

◆ getCurrentGeneration()

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

References _currentGeneration.

Referenced by SIMenv::getCurrentGeneration().

+ Here is the caller graph for this function:

◆ getCurrentRankInLifeCycle()

int SimRunner::getCurrentRankInLifeCycle ( )
inline
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().

+ Here is the caller graph for this function:

◆ getCurrentReplicate()

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

References _currentReplicate.

Referenced by SIMenv::getCurrentReplicate().

+ Here is the caller graph for this function:

◆ getGenerations()

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

References _generations.

Referenced by SIMenv::getGenerations().

+ Here is the caller graph for this function:

◆ getReplicates()

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

References _replicates.

Referenced by SIMenv::getReplicates().

+ Here is the caller graph for this function:

◆ 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:
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
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:438
void setMode(unsigned int m)
Mode setter, determines if file will get overwritten or not.
Definition: fileservices.h:120
void setRootDir(string name)
Sets the root directory of the simulation.
Definition: fileservices.cc:445
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
bool _do_postexec_replicatewise
Boolean to trigger replicate-wise execution of post script.
Definition: simulation.h:94
std::string _modeArg
The run mode ('overwrite', 'run', 'skip', 'dryrun', 'create_init').
Definition: simulation.h:84
bool _do_postexec
Boolean set when a post-exec script must be executed.
Definition: simulation.h:96
void printLogHeader()
Definition: simulation.cc:734
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().

+ Here is the caller graph for this function:

◆ 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:715
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:741
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().

+ Here is the caller graph for this function:

◆ 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
330#if defined(USE_MPI) && defined(HAS_SPRNG)
331
332 // broadcast the random seed, needs to be equal on all processes with SPRNG
333 MPI_Bcast(&_random_seed,1,MPI_LONG,0,MPI_COMM_WORLD );
334
335#else
336#endif
337
338 //initialization in any case
340
341}
MPIenv * _myenv
Definition: MPImanager.cc:36
bool isMaster() const
Definition: MPImanager.h:127
static void init(unsigned long seed)
Initialize the random generator's seed.
Definition: Uniform.h:83
unsigned long _random_seed
The startup random seed of the random generator.
Definition: simulation.h:82

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

Referenced by init_components().

+ Here is the caller graph for this function:

◆ printLog()

void SimRunner::printLog ( )
763{
764 ofstream FH(_logfile.c_str(),ios::app);
765
766 if(!FH.is_open()){
767 error("could not open simulation logfile \"%s\"\n",_logfile.c_str());
768 return;
769 }
770
771 FH<<"| ";
772 FH.width(40);
773 FH.setf(ios::left,ios::adjustfield);
775
776 FH <<"| "<< _startTime <<" | "<< _endTime <<" | ";
777
778 FH.width(10);
779 FH.setf(ios::right,ios::adjustfield);
780 FH<< _simElapsedTime <<" | ";
781
782 FH.width(9);
783 FH << _replicates <<" | ";
784
785 FH.width(10);
786 FH << setElapsedTime( _meanReplElapsedTime ) << " | ";
787
788 FH.width(8);
789 FH << _meanGenLength <<" | ";
790
791 FH<<" "<<MAIN_VERSION<<"."<<MINOR_VERSION<<"."<<REVISION<<RELEASE
792 <<" "<<VERSION_DATE;
793
794 FH<<" | ";
795 FH.width(20);
796 FH.setf(ios::left,ios::adjustfield);
797 char* host;
798 if( (host = getenv("HOST")) != NULL )
799 FH << host << " |";
800 else if ( (host = getenv("HOSTNAME")) != NULL )
801 FH << host << " |";
802 else
803 FH << "-" << " |";
804
806
807 for(;file != last; file++)
808 FH << " \"" << (*file)->get_extension() << "\":" << (*file)->get_path();
809
810 FH << std::endl;
811
812 FH.close();
813}
file_it getFirstWriter()
Accessor to first element of the list of output FileHandlers.
Definition: fileservices.h:141
file_it getLastWriter()
Accessor to last element of the list of output FileHandlers.
Definition: fileservices.h:144
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:398
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:709
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:31
#define MINOR_VERSION
Definition: version.h:28
#define RELEASE
Definition: version.h:30
#define MAIN_VERSION
Definition: version.h:27
#define REVISION
Definition: version.h:29

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().

+ Here is the caller graph for this function:

◆ printLogHeader()

void SimRunner::printLogHeader ( )
735{
736 ofstream FH;
737 ifstream IF;
738 //check is the logfile already exists:
739 IF.open(_logfile.c_str(),ios::in);
740 if(IF){
741 IF.close();
742 return;
743 }
744 IF.close();
745
746 FH.open(_logfile.c_str(),ios::out);
747 if(!FH) {
748 error("could not create simulation logfile \"%s\"\n",_logfile.c_str());
749 return;
750 }
751
752 FH<<"--- N E M O ---\n"
753 <<" LOGFILE\n\n\n";
754 FH<<"| basename | start time | stop time | e-time CPU |"
755 <<" repl done | rpl e-time | mean gen | version | hostname | output files \n";
756
757 FH.close();
758}

References _logfile, and error().

Referenced by init().

+ Here is the caller graph for this function:

◆ 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:81
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().

+ Here is the caller graph for this function:

◆ 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< int, LifeCycleEvent * >::const_iterator LCE_ITER
Definition: basicsimulation.h:226
map< trait_t, TraitPrototype * > _currentTraits
List of the selected trait prototypes from the user defined input parameters.
Definition: basicsimulation.h:222
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().

+ Here is the caller graph for this function:

◆ Replicate_LOOP()

void SimRunner::Replicate_LOOP ( )

Replicate loop, iterates the life cycle _replicates times.


507{
508
509#ifndef USE_MPI
510
511 clock_t start;
512 clock_t stop;
513 time_t t;
514 char t_buff[10];
515
517 _meanGenLength = 0;
519
520 //---------------------------------- REPLICATE LOOP -------------------------------------
522
523
524 // -------------------------- PRINT STUFF ------------------------------
525 t=time(0);
526 //print some output:
527 strftime(t_buff,10,"%H:%M:%S",localtime(&t));
528
529#ifdef LOW_VERBOSE
530 message(" replicate %i/%i [%s] \n",_currentReplicate, _replicates, t_buff);
531#else
532 message("\r replicate %i/%i [%s] 1/%i ",_currentReplicate, _replicates, t_buff, _generations);
533 fflush(stdout);
534#endif
535
536 //---------------- SET POPULATION FOR FIRST GENERATION ------------------
537
539
540 //--------------------------- GENERATION LOOP ---------------------------
541 start = clock();
542
543 Cycle(t_buff);
544
545 stop = clock();
546 //-----------------------------------------------------------------------
547
548 _meanReplElapsedTime += (stop - start);
549
551
552 //call the file services to print the replicate stats in case of pop extinction
557 }
558
559 if( _do_postexec_replicatewise ) runPostExecReplicateWise(); //will execute on each node
560 }
561 //--------------------------------- /REPLICATE LOOP -------------------------------------
562
569 }
570
573
574#else
575 //else ifndef USE_MPI
576 //------------------------------- MPI REPLICATE LOOP ------------------------------------
578
579 while ( _currentReplicate <= _replicates )
581
583
584 if( _myenv->isMaster() ) {
589
590 //write the stat files, only if "save_stats" LCE is part of the life cycle
591 if(get_LCE("save_stats")->get_paramset()->isSet()) {
592 FileHandler& statWriter = dynamic_cast<LCE_StatServiceNotifier*> ( get_LCE("save_stats") )->getFH();
593 for (unsigned int i = 1; i <= _replicates; ++i) {
595 statWriter.FHwrite();
596 }
597 }
598 }
599 //------------------------------ /MPI REPLICATE LOOP ------------------------------------
600#endif
601 //endif USE_MPI
602
603 //delete all individuals present in the population and delete the patches:
604 _thePop->clear();
605}
LifeCycleEvent * get_LCE(string name)
Search for component with "name" in the life cycle events list.
Definition: basicsimulation.cc:77
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:188
Initiates the StatServices' parameters (log time) when registering, calls StatServices::notify() when...
Definition: servicenotifiers.h:161
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:295
void clear()
Called at the end of each simulation, empties the pop and the garbage collector; the Individuals are ...
Definition: metapop.cc:1193
ParamSet * get_paramset(string &name)
Looks for paramset with "name" in the list of parameter sets.
Definition: basicsimulation.cc:232
void setForFirstGeneration()
Sets the population and the services ready for the first generation of a new replicate.
Definition: simulation.cc:609
void Cycle(char *startTime)
Life cycle loop, executes the list of LCEs _generations times.
Definition: simulation.cc:625
void runPostExecReplicateWise()
Run the post-exec script after each replicate, adds filename and replicate number as args.
Definition: simulation.cc:842

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().

+ Here is the caller graph for this function:

◆ 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
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().

+ Here is the caller graph for this function:

◆ 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:340
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().

+ Here is the caller graph for this function:

◆ run() [1/2]

bool SimRunner::run ( )

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

391{
392 time_t t;
393 unsigned int sim = 0, simnbre = _simRecords.size();
394
395 list< map< string,string > >::iterator currentSim = _simRecords.begin();
396
397 //first loop: perform all simulations contained in _simRecords:
398 //---------------------------------------------------------------------------------------
399 while(currentSim != _simRecords.end()) {
400
401 sim++;
402
403 //clear and build the lists of traits, LCEs, stats and files handlers, random seed
404 //create trait prototypes and the genetic map within IndFactory::makePrototype
405 if(!init_components(*currentSim)) return false;
406
407 //output a few info:
408 if ( _myenv->isMaster() ) {
409
410 t = time(NULL);
411
412 strftime(_startTime, 20, "%d-%m-%Y %H:%M:%S", localtime(&t));
413
414 message("\n--- SIMULATION %i/%i ---- [ %s ]\n\n",sim,simnbre,_FileServices.getBaseFileName().c_str());
415 message(" start: %s\n",_startTime);
416 message(" mode: %s\n",_modeArg.c_str());
417 message(" traits: ");
418
419 map<trait_t, TraitPrototype* >::iterator trait = _currentTraits.begin();
420
421 while(trait != _currentTraits.end()) {
422 message("%s",trait->first.c_str());
423 message("(%i)", _thePop->getTraitIndex(trait->first.c_str()));
424 trait++;
425 if(trait != _currentTraits.end()) message(", ");
426 }
427
428 message("\n LCEs: ");
429
430 for(LCE_ITER LCE = _LifeCycle.begin(); LCE != _LifeCycle.end(); LCE++) {
431 message("%s(%i)",LCE->second->get_event_name().c_str(),LCE->first);
432 if(LCE != _LifeCycle.end()) message(", ");
433 }
434
435 message("\n");
436 }
437
438 //init the file services:
439 //->files check, false means the user wants to skip this simulation.
440 if( !(_FileServices.init(this->_currentParams)) ) {
441 currentSim++;
443 continue;
444 }
445
446 // Load the population from a source file?
447 if(_thePop->isSourceLoad()) {
448 message(" loading population from: %s (%s)\n",_thePop->getSourceName().c_str(),
449 _thePop->getSourceFileType().c_str());
450
452 {
453 warning("be aware that the locus map positions saved\n\
454 in a binary file used to source a population are\n\
455 ignored, check init files for possible mismatch\n");
456//>>>> WARNING::
457 }
458 } // endif isSourceLoad
459
460 if ( _myenv->isMaster() ) message("\n");
461
462 //->save simulation parameters in log files, add the current random seed
463 // this is where ini files are created in `run_mode create_init' (mode == 4)
466
467 clock_t start = clock();
468
469 //run the simulation
470 //-------------------------------------------------------------------------------------
471 if(_doRun) Replicate_LOOP( );
472
473 clock_t stop = clock();
474
475 t = time(NULL);
476
477 strftime(_endTime, 20, "%d-%m-%Y %H:%M:%S", localtime(&t));
478
479 _simElapsedTime = setElapsedTime(stop - start);
480
481 if ( _myenv->isMaster() && _mode != 3 && _mode != 4) {
482 printLog();
483 message("\n\n end: %s\n",_endTime);
484 message("--- done (CPU time: %ss)\n",_simElapsedTime.c_str());
485 //don't log this when in 'dryrun' or 'create_init' mode:
486 _FileServices.log("\n# simulation finished " + string(_endTime));
487 _FileServices.log("# CPU time used: " + _simElapsedTime + "s");
488 }
489
491
492 // free all allocated memory of the random number generator
493 // it will be re-allocated in `init_components -> ini_random_seed'
494 RAND::free();
495
496 currentSim++;
497 }
498 //---------------------------------------------------------------------------------------
500
501 return true;
502}
void log(string message)
Write to the parameter logfile.
Definition: fileservices.cc:359
virtual bool init()
Definition: fileservices.h:99
void log_simparams()
Saves the current simulation parameters to the default parameter logfile.
Definition: fileservices.cc:349
Individual * getIndividualProtoype()
Individual prototype accessor.
Definition: indfactory.h:109
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
unsigned int getTraitNumber()
Accessor to the size of the traits table.
Definition: individual.h:247
bool isSourceLoad()
Definition: metapop.h:282
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:109
void runPostExec()
Run the post-exec script after all simulations have finished.
Definition: simulation.cc:817
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:762
void Replicate_LOOP()
Replicate loop, iterates the life cycle _replicates times.
Definition: simulation.cc:506
static string ulong2str(const unsigned long i)
Writes an integer value into a string.
Definition: tstring.h:105
void warning(const char *str,...)
Definition: output.cc:58

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

Referenced by run().

+ Here is the caller graph for this function:

◆ run() [2/2]

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

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

346{
347 //initialize the MPI environment:
348 _myenv = new MPIenv( ARGC, ARGV, _my_mpi_manager );
349
350 //--------------------------------------------------------------------
351 if(_myenv->isMaster()) {
352
354
355 }
356
357 //--------------------------------------------------------------------
358 //check for the presence of a metapop:
359 if(_thePop == NULL) fatal("SimRunner::run: no population is attached at startup!\n");
360
361 //--------------------------------------------------------------------
362 //build the list of params from the components list
363 this->build_allParams();
364
365 //--------------------------------------------------------------------
366 //get the input parameters from the input parameter file
367
368 // create a stream parser attached to the file reader
369 FileParser Reader("");
370
371 if (ARGC == 1)
372 build_records(Reader.getParsedParameters("Nemo2.ini")); // this calls StreamParser::ParamParser::getParsedParameters
373 else
374 for (int i = 1; i < ARGC; ++i)
375 build_records(Reader.getParsedParameters(ARGV[i]));
376
377 //--------------------------------------------------------------------
378 //run the simulation
379 bool status = run();
380
382
383 delete _myenv;
384
385 return status;
386}
Text input parameter file parser.
Definition: fileparser.h:37
MPI environment setup.
Definition: MPImanager.h:121
static void finish(MPImanager *p)
Definition: MPImanager.cc:68
void build_records(map< string, vector< string > > &initParams)
Builds the list of simulation parameters from the parsed input file(s).
Definition: basicsimulation.cc:250
void build_allParams()
Clears and fills the _allParams list with the ParamSet's of the simulation components.
Definition: basicsimulation.cc:116
bool run()
First loop of the simulation, performs the simulations stored in the ParamManager base class.
Definition: simulation.cc:390
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(), MPIenv::isMaster(), run(), and START_MESSAGE().

Referenced by main().

+ Here is the caller graph for this function:

◆ 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.
676{
677 //before calling that fction, first set the params and call init_components()!!
678
679 LifeCycleEvent* event = this->get_current_event(name);
680
681 if(event == NULL) {
682 error("SimRunner::run_event:event \"%s\" not found in set events!\n",name.c_str());
683 return false;
684 }
685
686 if( !(event->get_paramset()->isSet()) ) return false;//highly unlikely!!
687
688 event->execute();
689
690 return true;
691}
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:683

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

◆ runPostExec()

void SimRunner::runPostExec ( )

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

818{
819 ifstream script(_postexec_script.c_str(),ios::in);
820 string cmd;
821
822 if(!script.is_open()) {
823 error("could not open post simulation shell script!\n");
824 return;
825 }
826
827 message("Executing shell script \"%s\" ",_postexec_script.c_str());
828 fflush(stdout);
829
830 cmd = "sh " + _postexec_script + " " + _postexec_args;
831
832 if(system(cmd.c_str()) < 0){
833 error("execution of `sh %s %s' failed: %s\n",_postexec_script.c_str(), _postexec_args.c_str(),strerror(errno));
834 return;
835 }
836
837 message("...done\n");
838}

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

Referenced by run().

+ Here is the caller graph for this function:

◆ runPostExecReplicateWise()

void SimRunner::runPostExecReplicateWise ( )

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

843{
844 ifstream script(_postexec_script.c_str(),ios::in);
845 string cmd;
846
847 if(!script.is_open()) {
848 error("could not open post simulation shell script!\n");
849 return;
850 }
851
852 message("Executing shell script \"%s\" ",_postexec_script.c_str());
853 fflush(stdout);
854
855 // runs the script with base sim filename and replicate number as two first arguments
857
858 if(system(cmd.c_str()) < 0){
859 error("execution of `sh %s %s' failed: %s\n",_postexec_script.c_str(), _postexec_args.c_str(),strerror(errno));
860 return;
861 }
862
863 message("...done\n");
864}
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().

+ Here is the caller graph for this function:

◆ 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
710{
711 int e_time = time / CLOCKS_PER_SEC;
712 int hour = e_time / 3600;
713 int minute = ((e_time % 3600) / 60);
714 int sec = (e_time % 3600) % 60;
715
716 std::ostringstream out(ios::out);
717
718 out.fill('0');
719 out.width(2);
720 out<<hour<<":";
721 out.width(2);
722 out<<minute<<":";
723 out.precision(2);
724 out.fill('0');
725 out.width(2);
726 out<<sec;
727
728 return(out.str());
729}

Referenced by printLog(), and run().

+ Here is the caller graph for this function:

◆ setForFirstGeneration()

void SimRunner::setForFirstGeneration ( )

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

610{
612
613 //reset temporal parameters/components to their first generation value/state
615
616 //reset stat recording iterator to first occurrence
618
619 //build metapopulation for the current replicate (build first generation)
621}
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().

+ Here is the caller graph for this function:

◆ setGenerations()

void SimRunner::setGenerations ( unsigned int  gen)
inline

◆ setLifeCycle()

void SimRunner::setLifeCycle ( )

Sets the list of LifeCyckeEvent's currently active.

243{
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:762

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

Referenced by init_components().

+ Here is the caller graph for this function:

◆ 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.
696{
697 LCE_ITER LCE = _LifeCycle.begin();
698
699 while(LCE != _LifeCycle.end()) {
700 _currentRankInLifeCycle = LCE->second->get_rank();
701 LCE->second->execute();
702 _thePop->setCurrentAge(LCE->second);
703 LCE++;
704 }
705}
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:301

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

Referenced by Cycle().

+ Here is the caller graph for this function:

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.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR