#include <simulation.h>


Public Member Functions | |
| SimRunner (Metapop *pop) | |
| ~SimRunner () | |
| Dstror. | |
| bool | init () |
| Checks simulation parameters and init the FileServices with the base filename. | |
| bool | init_components (map< string, string > &simparams) |
| Performs the initialization of the different components of the simulation. | |
| void | setLifeCycle () |
| Sets the list of LifeCyckeEvent's currently active. | |
| void | init_random_seed () |
| Initialize the seed of the random generator. | |
| void | reset () |
| Resets all the parameters to the unset state, resets the services. | |
| std::string | setElapsedTime (clock_t time) |
| Compute and print the simulation's elapsed time to stdout. | |
| void | register_component (SimComponent *cmpt) |
| Register the different Handler's attached to a SimComponent. | |
| void | register_component_handlers () |
| Register all the Handlers of the currently active simulation components. | |
| void | reset_services () |
| Resets the FileServices and StatServices. | |
| FileServices * | get_FileServices () |
| Returns the FileServices. | |
| StatServices * | get_StatServices () |
| Returns the StatServices. | |
| list< StatRecBase * > | get_allRegisteredStats () |
| Returns the complete list of the stat recorders loaded after parameters initialization. | |
| bool | run (int ARGC, char **ARGV) |
| First loop of the simulation, performs the simulations stored in the ParamManager base class. | |
| bool | run () |
| First loop of the simulation, performs the simulations stored in the ParamManager base class. | |
| bool | run_event (string &name) |
| Execute one specific life cycle event, if present in the list of current events. | |
| void | step (unsigned int nb_gen) |
| Iterates the life cycle. | |
| void | attach_pop (Metapop *pop) |
| Attach a pop to the simulation. | |
| Metapop * | get_pop () |
| Accessor to the pop ptr. | |
| bool | build_pop () |
| Calls the Metapop init procedure with current traits and LCEs. | |
| 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 () |
| void | printLogHeader () |
| void | printLog () |
| void | runPostExec () |
Main loops | |
| void | Replicate_LOOP () |
| Replicate loop, iterates the life cycle _replicates times. | |
| void | Cycle (char *startTime) |
| Life cycle loop, executes the list of LCEs _generations times. | |
Public Attributes | |
| FileServices | _FileServices |
| StatServices | _StatServices |
| UpdaterServices | _ParamUpdaterManager |
Private Attributes | |
| MPImanager * | _my_mpi_manager |
| Metapop * | _thePop |
| std::string | _logfile |
| std::string | _mode |
| bool | _doRun |
| std::string | _postexec_script |
| bool | _do_postexec |
| char | _startTime [20] |
| char | _endTime [20] |
| std::string | _simElapsedTime |
| clock_t | _meanReplElapsedTime |
| Clock counter, for logging. | |
| unsigned int | _meanGenLength |
| Generation counter, for logging. | |
| unsigned int | _generations |
| Number of generations to iterate. | |
| unsigned int | _replicates |
| Number of replicates to iterate. | |
| unsigned int | _currentReplicate |
| The current replicate in the replicate loop, starts at 1. | |
| unsigned int | _currentGeneration |
| The current generation in the generation loop, starts at 1. | |
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.
Definition at line 53 of file simulation.h.
| SimRunner::SimRunner | ( | Metapop * | pop | ) | [inline] |
Definition at line 97 of file simulation.h.
00097 : _my_mpi_manager(0) 00098 { 00099 attach_pop(pop); 00100 }
| SimRunner::~SimRunner | ( | ) |
Dstror.
Definition at line 120 of file simulation.cc.
00121 { 00122 // message("SimRunner::~SimRunner\n"); 00123 reset(); 00124 }
| void SimRunner::attach_pop | ( | Metapop * | pop | ) | [inline] |
Attach a pop to the simulation.
Adds it to the components list.
| pop | ptr to the pop object |
Definition at line 155 of file simulation.h.
Referenced by SimRunner().
00155 {_thePop = pop;this->_components.push_back(_thePop);}
| bool SimRunner::build_pop | ( | ) |
Calls the Metapop init procedure with current traits and LCEs.
| void SimRunner::Cycle | ( | char * | startTime | ) |
Life cycle loop, executes the list of LCEs _generations times.
| startTime | the starting time of the current replicate. |
Definition at line 463 of file simulation.cc.
Referenced by Replicate_LOOP().
00464 { 00465 00466 // ------------------------------ CYCLE -------------------------------- 00467 00468 for(_currentGeneration = 1; !(_currentGeneration > _generations); _currentGeneration++) { 00469 00470 // -------------------------- PRINT STUFF ------------------------------ 00471 #if !defined(LOW_VERBOSE) && !defined(USE_MPI) 00472 if( !(_currentGeneration % 100) ){ 00473 message("\r replicate %i/%i [%s] %i/%i", _currentReplicate, _replicates 00474 ,startTime, _currentGeneration, _generations); 00475 fflush(stdout); 00476 } 00477 #endif 00478 00479 #ifdef _DEBUG_ 00480 message("____Generation %i/%i____\n", _currentGeneration, _generations); 00481 #endif 00482 00483 // -------------------------- STEP ONE GEN ------------------------------ 00484 _thePop->setCurrentGeneration(_currentGeneration); 00485 00486 // do one iteration of the life cycle: 00487 if(_thePop->isAlive()) 00488 00489 step(1); 00490 00491 else { 00492 #if !defined(LOW_VERBOSE) && !defined(USE_MPI) 00493 message("\r replicate %i/%i [%s] %i/%i -> Pop extinction !\n", _currentReplicate, _replicates 00494 ,startTime, _currentGeneration, _generations); 00495 #endif 00496 _currentGeneration++; 00497 break; 00498 } 00499 00500 } 00501 // --------------------------- END OF CYCLE -------------------------- 00502 }
| list<StatRecBase*> SimRunner::get_allRegisteredStats | ( | ) | [inline] |
Returns the complete list of the stat recorders loaded after parameters initialization.
Definition at line 139 of file simulation.h.
00139 {return _StatServices.getAllStats();}
| FileServices* SimRunner::get_FileServices | ( | ) | [inline] |
Returns the FileServices.
Definition at line 135 of file simulation.h.
Referenced by Metapop::loadPopFromTraitFile().
00135 {return &_FileServices;}
| Metapop* SimRunner::get_pop | ( | ) | [inline] |
Accessor to the pop ptr.
Definition at line 159 of file simulation.h.
00159 {return _thePop;}
| StatServices* SimRunner::get_StatServices | ( | ) | [inline] |
Returns the StatServices.
Definition at line 137 of file simulation.h.
00137 {return &_StatServices;}
| unsigned int SimRunner::getCurrentGeneration | ( | ) | [inline] |
Definition at line 177 of file simulation.h.
Referenced by SIMenv::getCurrentGeneration().
00177 {return _currentGeneration;}
| unsigned int SimRunner::getCurrentReplicate | ( | ) | [inline] |
Definition at line 181 of file simulation.h.
Referenced by SIMenv::getCurrentReplicate().
00181 {return _currentReplicate;}
| unsigned int SimRunner::getGenerations | ( | ) | [inline] |
Definition at line 179 of file simulation.h.
Referenced by SIMenv::getGenerations(), and StatHandlerBase::init().
00179 {return _generations;}
| unsigned int SimRunner::getReplicates | ( | ) | [inline] |
Definition at line 183 of file simulation.h.
Referenced by SIMenv::getReplicates(), and StatHandlerBase::init().
00183 {return _replicates;}
| bool SimRunner::init | ( | ) |
Checks simulation parameters and init the FileServices with the base filename.
Definition at line 58 of file simulation.cc.
Referenced by init_components(), and init_random_seed().
00059 { 00060 if( !(_paramSet.isSet("filename")) ) { 00061 error("parameter \"filename\" is not properly set!\n"); 00062 return false; 00063 } 00064 00065 _FileServices.setBasename(_paramSet.getArg("filename")); 00066 00067 if(_paramSet.isSet("root_dir")) { 00068 _FileServices.setRootDir(_paramSet.getArg("root_dir")); 00069 } 00070 00071 if(_paramSet.isSet("run_mode")) { 00072 00073 _mode = _paramSet.getArg("run_mode"); 00074 00075 if(_mode.compare("run")==0){ 00076 _FileServices.setMode(0); 00077 _doRun = true; 00078 } else if(_mode.compare("overwrite")==0) { 00079 _FileServices.setMode(1); 00080 _doRun = true; 00081 } else if(_mode.compare("skip")==0){ 00082 _FileServices.setMode(2); 00083 _doRun = true; 00084 } else if(_mode.compare("dryrun")==0){ 00085 _FileServices.setMode(3); 00086 _doRun = false; 00087 } else { 00088 error("simulation run mode \"%s\" unknown\n",_mode.c_str()); 00089 return false; 00090 } 00091 } else { 00092 _mode = "run"; 00093 _doRun = true; 00094 _FileServices.setMode(0); 00095 } 00096 00097 _replicates = (unsigned int)_paramSet.getValue("replicates"); 00098 00099 _generations = (unsigned int)_paramSet.getValue("generations"); 00100 00101 00102 if( _paramSet.isSet("logfile") ) { 00103 _logfile = _paramSet.getArg("logfile"); 00104 } else 00105 _logfile = "nemo.log"; 00106 00107 printLogHeader(); 00108 00109 if( _paramSet.isSet("postexec_script") ) { 00110 _postexec_script = _paramSet.getArg("postexec_script"); 00111 _do_postexec = true; 00112 } else 00113 _do_postexec = false; 00114 00115 return true; 00116 }
| 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.
| simparams | the hashtable containing the parameters and their arguments parsed from the init file |
Definition at line 183 of file simulation.cc.
Referenced by run().
00184 { 00185 //first reset all paramSets and services (clear the handlers' lists) 00186 reset(); 00187 00188 _FileServices.set_pop_ptr(_thePop); 00189 _StatServices.set_pop_ptr(_thePop); 00190 00191 //build the list of parameters from the record: 00192 #ifdef _DEBUG_ 00193 message("SimRunner::init_components: building current params\n"); 00194 #endif 00195 if(!this->build_currentParams(simparams)){ 00196 error("SimRunner::init_components:couldn't build current params\n"); 00197 return false; 00198 } 00199 00200 //initialize the random generator's seed: 00201 init_random_seed(); 00202 00203 //init the sim and pop 00204 if( !init() || !_thePop->init() ) return false; 00205 //temporary fix v2.0.8: 00206 _thePop->setReplicates(_replicates); 00207 _thePop->setGenerations(_generations); 00208 00209 //build the Individual prototype, and init the TTraits: 00210 _thePop->makePrototype( build_currentTraits() ); 00211 00212 //build the list of life cycle events, and init LCEs: 00213 setLifeCycle( ); 00214 00215 //load the stats, files, and updaters handlers of the simulation components: 00216 register_component_handlers(); 00217 00218 //StatServices: build the lists of stat recorders: 00219 if( !_StatServices.init() ) return false; 00220 00221 if( !_ParamUpdaterManager.init() ) return false; 00222 00223 if( _ParamUpdaterManager.hasTemporals() ) { 00224 LCE_ParamUpdaterNotifier* updater = new LCE_ParamUpdaterNotifier(); 00225 updater->setManager( &_ParamUpdaterManager ); 00226 updater->init(_thePop); 00227 _LifeCycle[ -1 ] = updater; 00228 } 00229 00230 return true; 00231 }
| void SimRunner::init_random_seed | ( | ) |
Initialize the seed of the random generator.
Definition at line 235 of file simulation.cc.
Referenced by init_components().
00236 { 00237 unsigned long seed; 00238 00239 if(this->_paramSet.isSet("random_seed")) { 00240 seed = (unsigned long) this->_paramSet.getValue("random_seed"); 00241 message( "setting random seed from input value: %i\n", seed); 00242 } else 00243 seed = 2*time(0)+1; 00244 00245 RAND::init(seed); 00246 }
| void SimRunner::printLog | ( | ) |
Definition at line 592 of file simulation.cc.
Referenced by run().
00593 { 00594 ofstream FH(_logfile.c_str(),ios::app); 00595 00596 if(!FH.is_open()){ 00597 error("could not open simulation logfile \"%s\"\n",_logfile.c_str()); 00598 return; 00599 } 00600 00601 FH<<"| "; 00602 FH.width(40); 00603 FH.setf(ios::left,ios::adjustfield); 00604 FH << _FileServices.getBaseFileName( ); 00605 00606 FH <<"| "<< _startTime <<" | "<< _endTime <<" | "; 00607 00608 FH.width(10); 00609 FH.setf(ios::right,ios::adjustfield); 00610 FH<< _simElapsedTime <<" | "; 00611 00612 FH.width(9); 00613 FH << _replicates <<" | "; 00614 00615 FH.width(10); 00616 FH << setElapsedTime( _meanReplElapsedTime ) << " | "; 00617 00618 FH.width(8); 00619 FH << _meanGenLength <<" | "; 00620 00621 FH<<" "<<MAIN_VERSION<<"."<<MINOR_VERSION<<"."<<REVISION<<RELEASE 00622 <<" "<<VERSION_DATE; 00623 00624 FH<<" | "; 00625 FH.width(20); 00626 FH.setf(ios::left,ios::adjustfield); 00627 char* host; 00628 if( (host = getenv("HOST")) != NULL ) 00629 FH << host << " |"; 00630 else if ( (host = getenv("HOSTNAME")) != NULL ) 00631 FH << host << " |"; 00632 else 00633 FH << "-" << " |"; 00634 00635 FileServices::file_it file = _FileServices.getFirstWriter(), last = _FileServices.getLastWriter() ; 00636 00637 for(;file != last; file++) 00638 FH << " \"" << (*file)->get_extension() << "\":" << (*file)->get_path(); 00639 00640 FH << std::endl; 00641 00642 FH.close(); 00643 }
| void SimRunner::printLogHeader | ( | ) |
Definition at line 564 of file simulation.cc.
Referenced by init().
00565 { 00566 ofstream FH; 00567 ifstream IF; 00568 //check is the logfile already exists: 00569 IF.open(_logfile.c_str(),ios::in); 00570 if(IF){ 00571 IF.close(); 00572 return; 00573 } 00574 IF.close(); 00575 00576 FH.open(_logfile.c_str(),ios::out); 00577 if(!FH) { 00578 error("could not create simulation logfile \"%s\"\n",_logfile.c_str()); 00579 return; 00580 } 00581 00582 FH<<"--- N E M O ---\n" 00583 <<" LOGFILE\n\n\n"; 00584 FH<<"| basename | start time | stop time | e-time CPU |" 00585 <<" repl done | rpl e-time | mean gen | version | hostname | output files \n"; 00586 00587 FH.close(); 00588 }
| void SimRunner::register_component | ( | SimComponent * | cmpt | ) |
Register the different Handler's attached to a SimComponent.
| cmpt | a SimComponent |
Definition at line 151 of file simulation.cc.
Referenced by register_component_handlers().
00152 { 00153 _FileServices.load(cmpt); 00154 _StatServices.load(cmpt); 00155 _ParamUpdaterManager.load(cmpt); 00156 }
| void SimRunner::register_component_handlers | ( | ) |
Register all the Handlers of the currently active simulation components.
Definition at line 160 of file simulation.cc.
Referenced by init_components().
00161 { 00162 register_component(_thePop); 00163 00164 for(TRAIT_ITER trait = _currentTraits.begin(); trait != _currentTraits.end(); trait++) 00165 register_component(trait->second); 00166 00167 for(LCE_ITER LCE = _LifeCycle.begin(); LCE != _LifeCycle.end(); LCE++) 00168 register_component(LCE->second); 00169 }
| void SimRunner::Replicate_LOOP | ( | ) |
Replicate loop, iterates the life cycle _replicates times.
Definition at line 376 of file simulation.cc.
Referenced by run().
00377 { 00378 00379 #ifndef USE_MPI 00380 00381 clock_t start; 00382 clock_t stop; 00383 time_t t; 00384 char t_buff[10]; 00385 00386 _meanReplElapsedTime = 0; 00387 _meanGenLength = 0; 00388 _currentGeneration = 0; 00389 00390 for(_currentReplicate = 1; !(_currentReplicate > _replicates); ++_currentReplicate) { 00391 00392 00393 // -------------------------- PRINT STUFF ------------------------------ 00394 t=time(0); 00395 //print some output: 00396 strftime(t_buff,10,"%H:%M:%S",localtime(&t)); 00397 00398 #ifdef LOW_VERBOSE 00399 message(" replicate %i/%i [%s] \n",_currentReplicate, _replicates, t_buff); 00400 #else 00401 message("\r replicate %i/%i [%s] 1/%i ",_currentReplicate, _replicates, t_buff, _generations); 00402 fflush(stdout); 00403 #endif 00404 00405 //---------------- SET POPULATION FOR FIRST GENERATION ------------------ 00406 _thePop->setCurrentGeneration(0); 00407 00408 //reset temporal parameters/components to their first generation value/state 00409 _ParamUpdaterManager.notify(0); 00410 00411 //build metapopulation for the current replicate (build first generation) 00412 _thePop->setPopulation(_currentReplicate, _replicates); 00413 00414 start = clock(); 00415 //--------------------------- GENERATION LOOP --------------------------- 00416 00417 Cycle(t_buff); 00418 00419 //----------------------------------------------------------------------- 00420 stop = clock(); 00421 00422 _meanReplElapsedTime += (stop - start); 00423 00424 _meanGenLength += _currentGeneration - 1; 00425 00426 //call the file services to print the replicate stats in case of pop extinction 00427 if( !_thePop->isAlive() && _currentGeneration-1 < _generations ) { 00428 _currentGeneration = _generations; 00429 _thePop->setCurrentGeneration(_generations); 00430 _FileServices.notify(); 00431 } 00432 00433 } //END_REPLICATE_LOOP 00434 00435 #else 00436 //else ifndef USE_MPI 00437 //------------------------------- MPI REPLICATE LOOP ------------------------------------ 00438 _currentReplicate = _my_mpi_manager->init( &_statHandler ); 00439 while ( _currentReplicate <= _replicates ) 00440 _my_mpi_manager->iterate( this, &_statHandler, &_currentGeneration, &_currentReplicate ); 00441 _my_mpi_manager->finish( &_statHandler, &_currentGeneration, _currentReplicate ); 00442 //------------------------------ /MPI REPLICATE LOOP ------------------------------------ 00443 #endif 00444 //endif USE_MPI 00445 00446 if( !_thePop->isAlive() && _currentGeneration < _generations ) { 00447 _currentGeneration = _generations; 00448 _currentReplicate = _replicates; 00449 _thePop->setCurrentGeneration(_generations); 00450 _thePop->setCurrentReplicate(_replicates); 00451 _FileServices.notify(); 00452 } 00453 00454 _meanReplElapsedTime /= _replicates; 00455 _meanGenLength /= _replicates; 00456 00457 //delete all individuals present in the population and delete the patches: 00458 _thePop->clear(); 00459 }
| void SimRunner::reset | ( | ) |
Resets all the parameters to the unset state, resets the services.
Definition at line 128 of file simulation.cc.
Referenced by init_components(), and ~SimRunner().
00129 { 00130 //reset all the parameter to the "unset" state 00131 list<ParamSet*>::iterator current_paramset = this->_allParams.begin(); 00132 while(current_paramset != this->_allParams.end()) { 00133 (*current_paramset)->reset(); 00134 current_paramset++; 00135 } 00136 00137 reset_services(); 00138 }
| void SimRunner::reset_services | ( | ) |
Resets the FileServices and StatServices.
Definition at line 142 of file simulation.cc.
Referenced by reset().
00143 { 00144 _FileServices.reset(); 00145 _StatServices.reset(); 00146 _ParamUpdaterManager.reset(); 00147 }
| bool SimRunner::run | ( | ) |
First loop of the simulation, performs the simulations stored in the ParamManager base class.
Definition at line 296 of file simulation.cc.
Referenced by run().
00297 { 00298 time_t t; 00299 unsigned int sim = 0, simnbre = _simRecords.size(); 00300 00301 list< map< string,string > >::iterator currentSim = _simRecords.begin(); 00302 00303 //first loop: perform all simulations contained in _simRecords: 00304 //--------------------------------------------------------------------------------------- 00305 while(currentSim != _simRecords.end()) { 00306 00307 sim++; 00308 00309 //clear and build the lists of traits, LCEs, stats and files handlers, etc. 00310 if(!init_components(*currentSim)) return false; 00311 00312 //output a few info: 00313 if ( _myenv->isMaster() ) { 00314 t = time(NULL); 00315 strftime(_startTime, 20, "%d-%m-%Y %H:%M:%S", localtime(&t)); 00316 message("\n--- SIMULATION %i/%i ---- [ %s ]\n\n",sim,simnbre,_FileServices.getBaseFileName().c_str()); 00317 message(" start: %s\n",_startTime); 00318 message(" mode: %s\n",_mode.c_str()); 00319 message(" traits: "); 00320 00321 map<trait_t, TraitPrototype* >::iterator trait = _currentTraits.begin(); 00322 while(trait != _currentTraits.end()) { 00323 message("%s",trait->first.c_str()); 00324 trait++; 00325 if(trait != _currentTraits.end()) message(", "); 00326 } 00327 message("\n LCEs: "); 00328 00329 for(LCE_ITER LCE = _LifeCycle.begin(); LCE != _LifeCycle.end(); LCE++) { 00330 message("%s(%i)",LCE->second->get_event_name().c_str(),LCE->first); 00331 if(LCE != _LifeCycle.end()) message(", "); 00332 } 00333 message("\n"); 00334 } 00335 00336 //init the file services: 00337 //->files check, false means the user wants to skip this simulation. 00338 //->save simparameters in log files 00339 if( !(_FileServices.init(this->_currentParams)) ) { 00340 currentSim++; 00341 continue; 00342 } 00343 message("\n"); 00344 00345 clock_t start = clock(); 00346 00347 //run the simulation 00348 //------------------------------------------------------------------------------------- 00349 if(_doRun) Replicate_LOOP( ); 00350 00351 clock_t stop = clock(); 00352 00353 t = time(NULL); 00354 00355 strftime(_endTime, 20, "%d-%m-%Y %H:%M:%S", localtime(&t)); 00356 00357 _simElapsedTime = setElapsedTime(stop - start); 00358 00359 if ( _myenv->isMaster() ) printLog(); 00360 00361 if ( _myenv->isMaster() ) { 00362 message("\n\n end: %s\n",_endTime); 00363 message("--- done (CPU time: %ss)\n",_simElapsedTime.c_str()); 00364 } 00365 00366 currentSim++; 00367 } 00368 //--------------------------------------------------------------------------------------- 00369 if( _do_postexec && _myenv->isMaster() ) runPostExec(); 00370 00371 return true; 00372 }
| bool SimRunner::run | ( | int | ARGC, | |
| char ** | ARGV | |||
| ) |
First loop of the simulation, performs the simulations stored in the ParamManager base class.
Definition at line 250 of file simulation.cc.
Referenced by main().
00251 { 00252 //initialize the MPI environment: 00253 _myenv = new MPIenv( ARGC, ARGV, _my_mpi_manager ); 00254 00255 //-------------------------------------------------------------------- 00256 if(_myenv->isMaster()) { 00257 cout<<"\n N E M O "<<MAIN_VERSION<<"."<<MINOR_VERSION<<"."<<REVISION<<RELEASE<<" "<<VERSION_DATE<<endl; 00258 message("\n Copyright (C) 2006-2009 Frederic Guillaume"); 00259 message("\n This is free software; see the source for copying"); 00260 message("\n conditions. There is NO warranty; not even for "); 00261 message("\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); 00262 message("\n http://nemo2.sourceforge.net"); 00263 message("\n------------------------------------------------\n"); 00264 } 00265 00266 //-------------------------------------------------------------------- 00267 //check for the presence of a metapop: 00268 if(_thePop == NULL) fatal("SimRunner::run: no population is attached at start up!\n"); 00269 00270 //-------------------------------------------------------------------- 00271 //build the list of params from the components list 00272 this->build_allParams(); 00273 00274 //-------------------------------------------------------------------- 00275 //get the input parameters 00276 FileParser Reader(""); 00277 if (ARGC == 1) 00278 build_records(Reader.getParsedParameters("Nemo2.ini")); 00279 else 00280 for (int i = 1; i < ARGC; ++i) 00281 build_records(Reader.getParsedParameters(ARGV[i])); 00282 00283 //-------------------------------------------------------------------- 00284 //run the simulation 00285 bool status = run(); 00286 00287 _myenv->finish(_my_mpi_manager); 00288 00289 delete _myenv; 00290 00291 return status; 00292 }
| bool SimRunner::run_event | ( | string & | name | ) |
Execute one specific life cycle event, if present in the list of current events.
| name | the name of the (paramSet of the) LifeCycleEvent to execute. |
Definition at line 506 of file simulation.cc.
00507 { 00508 //before calling that fction, first set the params and call init_components()!! 00509 00510 LifeCycleEvent* event = this->get_current_event(name); 00511 00512 if(event == NULL) { 00513 error("SimRunner::run_event:event \"%s\" not found in set events!\n",name.c_str()); 00514 return false; 00515 } 00516 00517 if( !(event->get_paramset()->isSet()) ) return false;//highly unlikely!! 00518 00519 event->execute(); 00520 00521 return true; 00522 }
| void SimRunner::runPostExec | ( | ) |
Definition at line 645 of file simulation.cc.
Referenced by run().
00646 { 00647 ifstream script(_postexec_script.c_str(),ios::in); 00648 string cmd; 00649 00650 if(!script.is_open()) { 00651 error("could not open post simulation shell script!\n"); 00652 return; 00653 } 00654 00655 message("Executing shell script \"%s\" ",_postexec_script.c_str()); 00656 fflush(stdout); 00657 00658 cmd = "sh " + _postexec_script; 00659 00660 if(system(cmd.c_str()) < 0){ 00661 error("execution of `sh %s' failed: %s\n",_postexec_script.c_str(),strerror(errno)); 00662 return; 00663 } 00664 00665 message("...done\n"); 00666 }
| void SimRunner::setCurrentGeneration | ( | unsigned int | gen | ) | [inline] |
Definition at line 176 of file simulation.h.
00176 {_currentGeneration = gen; _thePop->setCurrentGeneration(gen);}
| void SimRunner::setCurrentReplicate | ( | unsigned int | repl | ) | [inline] |
Definition at line 180 of file simulation.h.
00180 {_currentReplicate = repl; _thePop->setCurrentReplicate(repl);}
| std::string SimRunner::setElapsedTime | ( | clock_t | time | ) |
Compute and print the simulation's elapsed time to stdout.
| time | elapsed time in ticks count |
Definition at line 539 of file simulation.cc.
Referenced by printLog(), and run().
00540 { 00541 int e_time = time / CLOCKS_PER_SEC; 00542 int hour = e_time / 3600; 00543 int minute = ((e_time % 3600) / 60); 00544 int sec = (e_time % 3600) % 60; 00545 00546 std::ostringstream out(ios::out); 00547 00548 out.fill('0'); 00549 out.width(2); 00550 out<<hour<<":"; 00551 out.width(2); 00552 out<<minute<<":"; 00553 out.precision(2); 00554 out.fill('0'); 00555 out.width(2); 00556 out<<sec; 00557 00558 return(out.str()); 00559 }
| void SimRunner::setGenerations | ( | unsigned int | gen | ) | [inline] |
Definition at line 178 of file simulation.h.
00178 {_generations = gen; _thePop->setGenerations(gen);}
| void SimRunner::setLifeCycle | ( | ) |
Sets the list of LifeCyckeEvent's currently active.
Definition at line 173 of file simulation.cc.
Referenced by init_components().
00174 { 00175 build_LifeCycle(); 00176 00177 for( LCE_ITER LCE = _LifeCycle.begin(); LCE != _LifeCycle.end(); LCE++) 00178 LCE->second->init(_thePop); 00179 }
| void SimRunner::setReplicates | ( | unsigned int | repl | ) | [inline] |
Definition at line 182 of file simulation.h.
00182 {_replicates = repl; _thePop->setReplicates(repl);}
| void SimRunner::step | ( | unsigned int | nb_gen | ) |
Iterates the life cycle.
| nb_gen | number of iterations to perform |
Definition at line 526 of file simulation.cc.
Referenced by Cycle().
00527 { 00528 LCE_ITER LCE = _LifeCycle.begin(); 00529 00530 while(LCE != _LifeCycle.end()) { 00531 LCE->second->execute(); 00532 _thePop->setCurrentAge(LCE->second); 00533 LCE++; 00534 } 00535 }
unsigned int SimRunner::_currentGeneration [private] |
The current generation in the generation loop, starts at 1.
Definition at line 85 of file simulation.h.
Referenced by Cycle(), getCurrentGeneration(), Replicate_LOOP(), and setCurrentGeneration().
unsigned int SimRunner::_currentReplicate [private] |
The current replicate in the replicate loop, starts at 1.
Definition at line 83 of file simulation.h.
Referenced by Cycle(), getCurrentReplicate(), Replicate_LOOP(), and setCurrentReplicate().
bool SimRunner::_do_postexec [private] |
bool SimRunner::_doRun [private] |
char SimRunner::_endTime[20] [private] |
Definition at line 89 of file simulation.h.
Referenced by get_FileServices(), init(), init_components(), printLog(), register_component(), Replicate_LOOP(), reset_services(), and run().
unsigned int SimRunner::_generations [private] |
Number of generations to iterate.
Definition at line 79 of file simulation.h.
Referenced by Cycle(), getGenerations(), init(), init_components(), Replicate_LOOP(), and setGenerations().
std::string SimRunner::_logfile [private] |
unsigned int SimRunner::_meanGenLength [private] |
Generation counter, for logging.
Definition at line 75 of file simulation.h.
Referenced by printLog(), and Replicate_LOOP().
clock_t SimRunner::_meanReplElapsedTime [private] |
Clock counter, for logging.
Definition at line 73 of file simulation.h.
Referenced by printLog(), and Replicate_LOOP().
std::string SimRunner::_mode [private] |
MPImanager* SimRunner::_my_mpi_manager [private] |
Definition at line 93 of file simulation.h.
Referenced by init_components(), register_component(), Replicate_LOOP(), and reset_services().
std::string SimRunner::_postexec_script [private] |
unsigned int SimRunner::_replicates [private] |
Number of replicates to iterate.
Definition at line 81 of file simulation.h.
Referenced by Cycle(), getReplicates(), init(), init_components(), printLog(), Replicate_LOOP(), and setReplicates().
std::string SimRunner::_simElapsedTime [private] |
char SimRunner::_startTime[20] [private] |
Definition at line 91 of file simulation.h.
Referenced by get_allRegisteredStats(), get_StatServices(), init_components(), register_component(), and reset_services().
Metapop* SimRunner::_thePop [private] |
Definition at line 58 of file simulation.h.
Referenced by attach_pop(), Cycle(), get_pop(), init_components(), register_component_handlers(), Replicate_LOOP(), run(), setCurrentGeneration(), setCurrentReplicate(), setGenerations(), setLifeCycle(), setReplicates(), and step().
1.5.8 -- Nemo is hosted by