51 #include "../basecode/header.h"
53 #include "../utility/numutil.h"
54 #include "../utility/print_function.hpp"
56 #if PARALLELIZE_CLOCK_USING_CPP11_ASYNC
75 "Signal for completion of run"
83 vector< SrcFinfo1< ProcPtr >* > vec;
90 ss2 << name <<
" for Tick " << i;
100 static vector< SrcFinfo1< ProcPtr >* >
processVec =
107 static vector< SrcFinfo1< ProcPtr >* >
reinitVec =
114 static vector< SharedFinfo* > vec;
115 if ( vec.size() == 0 )
126 "Shared process/reinit message",
140 "Base timestep for simulation. This is the smallest dt out "
141 "of all the clock ticks. By definition all other timesteps "
142 "are integral multiples of this, and are rounded to "
143 "ensure that this is the case . ",
149 "Duration to run the simulation",
154 "Current simulation time",
159 "Number of steps to advance the simulation, in units of the smallest timestep on the clock ticks",
164 "Number of clock ticks",
169 "Number by which the simulation advances the current step on each cycle. stride = smallest active timestep/smallest defined timestep.",
174 "Current simulation step",
180 "Utility function returning the dt (timestep) of all ticks.",
186 "Utility function to report if simulation is in progress.",
193 "Step size of specified Tick, as integral multiple of dt_"
194 " A zero step size means that the Tick is inactive",
201 "Timestep dt of specified Tick. Always integral multiple of "
202 "dt_. If you assign a non-integer multiple it will round off. "
203 " A zero timestep means that the Tick is inactive",
210 "Looks up the default Tick to use for the specified class. "
211 "If no tick is assigned, as for classes without a process "
212 "operation or zombie classes, the tick is ~0U. "
213 "If nothing can be found returns 0 and emits a warning.",
225 "Sets off the simulation for the specified duration",
230 "Sets off the simulation for the specified # of steps. "
231 "Here each step advances the simulation by the timestep of the "
232 "smallest tick that is actually in use. ",
237 "Halts the simulation, with option to restart seamlessly",
242 "Zeroes out all ticks, starts at t = 0",
246 static Finfo* clockControlFinfos[] =
248 &start, &step, &
stop, &reinit,
254 "Controls all scheduling aspects of Clock, usually from Shell",
256 sizeof( clockControlFinfos ) /
sizeof(
Finfo* )
259 static Finfo* clockFinfos[] =
310 static string doc[] =
313 "Author",
"Upinder S. Bhalla, Nov 2013, NCBS",
316 "Every object scheduled for operations in MOOSE is connected to one"
317 "of the 'Tick' entries on the Clock.\n"
318 "The Clock manages 32 'Ticks', each of which has its own dt,"
319 "which is an integral multiple of the clock baseDt_. "
320 "On every clock step the ticks are examined to see which of them"
321 "is due for updating. When a tick is updated, the 'process' call "
322 "of all the objects scheduled on that tick is called. "
323 "Order of execution: If a subset of ticks are scheduled for "
324 "execution at a given timestep, then they will be executed in "
325 "numerical order, lowest tick first and highest last. "
326 "There is no guarantee of execution order for objects within "
328 "The clock provides default scheduling for all objects which "
329 "can be accessed using Clock::lookupDefaultTick( className ). "
330 "Specific items of note are that the output/file dump objects are "
331 "second-last, and the postmaster is last on the order of Ticks. "
332 "The clock also starts up with some default timesteps for each "
333 "of these ticks, and this can be overridden using the shell "
334 "command setClock, or by directly assigning tickStep values on the "
336 "Which objects use which tick? As a rule of thumb, try this: \n"
337 "Electrical/compartmental model calculations: Ticks 0-7 \n"
338 "Tables and output objects for electrical output: Tick 8 \n"
339 "Diffusion solver: Tick 10 \n"
340 "Chemical/compartmental model calculations: Ticks 11-17\n"
341 "Tables and output objects for chemical output: Tick 18 \n"
342 "Unassigned: Ticks 20-29 \n"
344 "Data output is a bit special, since you may want to store data "
345 "at different rates for electrical and chemical processes in the "
346 "same model. Here you will have to specifically assign distinct "
347 "clock ticks for the tables/fileIO objects handling output at "
348 "different time-resolutions. Typically one uses tick 8 and 18.\n"
349 "Here are the detailed mappings of class to tick.\n"
352 " Interpol 0 50e-6\n"
353 " PIDController 0 50e-6\n"
354 " PulseGen 0 50e-6\n"
355 " StimulusTable 0 50e-6\n"
356 " testSched 0 50e-6\n"
358 " SynHandlerBase 1 50e-6\n"
359 " SimpleSynHandler 1 50e-6\n"
360 " STDPSynHandler 1 50e-6\n"
361 " GraupnerBrunel2012CaPlasticitySynHandler 1 50e-6\n"
362 " SeqSynHandler 1 50e-6\n"
364 " CaConcBase 1 50e-6\n"
365 " DifShell 1 50e-6\n"
366 " DifShellBase 1 50e-6\n"
368 " DifBuffer 1 50e-6\n"
369 " DifBufferBase 1 50e-6\n"
372 " RandSpike 1 50e-6\n"
373 " ChanBase 2 50e-6\n"
375 " IntFireBase 2 50e-6\n"
380 " AdThreshIF 2 50e-6\n"
382 " IzhikevichNrn 2 50e-6\n"
384 " NMDAChan 2 50e-6\n"
385 " GapJunction 2 50e-6\n"
386 " HHChannel 2 50e-6\n"
387 " HHChannel2D 2 50e-6\n"
389 " MarkovChannel 2 50e-6\n"
390 " MarkovGslSolver 2 50e-6\n"
391 " MarkovRateTable 2 50e-6\n"
392 " MarkovSolver 2 50e-6\n"
393 " MarkovSolverBase 2 50e-6\n"
395 " Compartment (init) 3 50e-6\n"
396 " CompartmentBase (init ) 3 50e-6\n"
397 " SymCompartment (init) 3 50e-6\n"
398 " Compartment 4 50e-6\n"
399 " CompartmentBase 4 50e-6\n"
400 " SymCompartment 4 50e-6\n"
401 " SpikeGen 5 50e-6\n"
403 " SpikeStats 7 50e-6\n"
405 " TimeTable 8 0.1e-3\n"
415 " CplxEnzBase 14 0.1\n"
421 " Gsolve (init) 15 0.1\n"
422 " Ksolve (init) 15 0.1\n"
429 " HDF5DataWriter 30 1\n"
430 " HDF5WriterBase 30 1\n"
433 " PostMaster 31 0.01\n"
435 " Note that the other classes are not scheduled at all.",
444 sizeof(clockFinfos)/
sizeof(
Finfo *),
447 sizeof(doc)/
sizeof(
string)
466 doingReinit_( false ),
468 ticks_(
Clock::numTicks, 0 )
497 cout <<
"Warning: Clock::setDt: Cannot change dt while simulation is running\n";
539 vector< double > ret;
540 for (
unsigned int i = 0; i <
ticks_.size(); ++i )
561 cout <<
"Warning: Clock::" << funcName <<
562 ": Cannot change dt while simulation is running\n";
567 cout <<
"Warning: Clock::" << funcName <<
568 "( " << i <<
" ): Clock has only " <<
593 unsigned int numUsed = 0;
596 cout <<
"Warning: Clock::setTickDt: " << v <<
597 " is smaller than minimum allowed timestep " <<
599 cout <<
"dt not set\n";
602 for (
unsigned int j = 0; j <
numTicks; ++j )
603 numUsed += (
ticks_[j] != 0 );
611 for (
unsigned int j = 0; j <
numTicks; ++j )
659 cout <<
"reporting Clock: runTime= " <<
runTime_ <<
663 for (
unsigned int i = 0; i <
ticks_.size(); ++i )
665 cout <<
"tick[" << i <<
"] = " <<
ticks_[i] <<
" " <<
680 for (
unsigned int i = 0; i <
ticks_.size(); ++i )
705 unsigned long n = round( runtime / (
stride_ *
dt_ ) );
716 cout <<
"Clock::handleStart: Warning: simulation already in progress.\n Command ignored\n";
721 struct tm * timeinfo;
736 #if PARALLELIZE_CLOCK_USING_CPP11_ASYNC
745 unsigned int numThreads_ = 3;
746 unsigned int blockSize = 1 + (nTasks / numThreads_);
748 for(
unsigned int i = 0; i < numThreads_; ++i )
750 std::async( std::launch::async
751 , [
this,blockSize,i,nTasks,endStep,e]
753 unsigned int mapI = i * blockSize;
755 for(
unsigned int ii = i * blockSize; ii < min((i+1) * blockSize, nTasks); ii++ )
758 if( endStep % j == 0 )
770 for ( vector< unsigned int>::iterator j =
773 if ( endStep % *j == 0 )
789 timeinfo = localtime( &rawtime );
790 strftime(now, 80,
"%c", timeinfo);
792 <<
"% of total " <<
runTime_ <<
" seconds is over." << endl;
812 cout <<
"Clock::handleReinit: Warning: simulation already in progress.\n Command ignored\n";
823 for ( vector< unsigned int>::iterator j =
882 defaultTick_[
"GraupnerBrunel2012CaPlasticitySynHandler"] = 1;
1037 map< string, unsigned int >::const_iterator i =
1041 cout <<
"Warning: unknown className: '" << className <<
"'.\n" <<
1042 "Advisable to update the defaultTick table in the Clock class.\n";
static vector< SrcFinfo1< ProcPtr > * > & processVec()
bool isRunning_
The minimum dt. All ticks are a multiple of this.
static vector< SrcFinfo1< ProcPtr > * > & reinitVec()
static const unsigned int numTicks
void handleReinit(const Eref &e)
dest function for message to trigger reinit.
double getCurrentTime() const
bool notify_
When set to true, notify user about the status of simulation by emitting message whenever 10% of simu...
static const Cinfo * initCinfo()
unsigned int getStride() const
unsigned int getTickStep(unsigned int i) const
unsigned int getNumTicks() const
bool isDoingReinit() const
vector< double > getDts() const
static vector< SrcFinfo1< ProcPtr > * > buildProcessVec(const string &name)
double getTickDt(unsigned int i) const
Element * element() const
void handleStart(const Eref &e, double runtime, bool notify)
dest function for message to run simulation for specified time
vector< unsigned int > activeTicksMap_
const double minimumDt
minimumDt is smaller than any known event on the scales MOOSE handles.
vector< unsigned int > activeTicks_
unsigned long currentStep_
bool checkTickNum(const string &funcName, unsigned int i) const
Utility func to range-check when Ticks are being changed.
unsigned long getCurrentStep() const
void handleStep(const Eref &e, unsigned long steps)
dest function for message to run simulation for specified steps
bool hasMsgs(BindIndex b) const
static vector< double > defaultDt_
static bool isLastTrump()
True when MOOSE has been terminated and is being cleaned up.
void buildTicks(const Eref &e)
vector< unsigned int > ticks_
static unsigned int lookupDefaultTick(const string &className)
double getRunTime() const
void setTickStep(unsigned int i, unsigned int v)
void setTickDt(unsigned int i, double v)
static void buildDefaultTick()
Builds the default scheduling map of classes to ticks.
static SrcFinfo0 * finished()
static const Cinfo * clockCinfo
static void reportClock()
Static function.
void innerReportClock() const
void send(const Eref &e) const
unsigned int getDefaultTick(string className) const
static vector< SharedFinfo * > & sharedProcVec()
static const Cinfo * initCinfo()
static map< string, unsigned int > defaultTick_
unsigned long getNsteps() const