14 #ifndef SST_CORE_SIMULATION_H
15 #define SST_CORE_SIMULATION_H
18 #include "sst/core/sst_types.h"
25 #include <unordered_map>
27 #include "sst/core/output.h"
28 #include "sst/core/clock.h"
29 #include "sst/core/oneshot.h"
30 #include "sst/core/unitAlgebra.h"
31 #include "sst/core/rankInfo.h"
33 #include "sst/core/componentInfo.h"
36 extern int main(
int argc,
char **argv);
41 #define _SIM_DBG( fmt, args...) __DBG( DBG_SIM, Sim, fmt, ## args )
42 #define STATALLFLAG "--ALLSTATS--"
50 class SimulatorHeartbeat;
61 class SharedRegionManager;
62 namespace Statistics {
63 class StatisticOutput;
64 class StatisticProcessingEngine;
96 #if !SST_BUILDING_CORE
105 #if !SST_BUILDING_CORE
106 static void shutdown() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
112 #if !SST_BUILDING_CORE
113 static void setSignal(
int signal) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
188 #if !SST_BUILDING_CORE
189 void processGraphInfo(
ConfigGraph& graph,
const RankInfo &myRank, SimTime_t min_part ) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
195 #if !SST_BUILDING_CORE
196 int performWireUp(
ConfigGraph& graph,
const RankInfo &myRank, SimTime_t min_part ) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
202 #if !SST_BUILDING_CORE
203 void setStopAtCycle(
Config* cfg ) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
209 #if !SST_BUILDING_CORE
210 void initialize() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
216 #if !SST_BUILDING_CORE
217 void complete() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
223 #if !SST_BUILDING_CORE
224 void setup() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
229 #if !SST_BUILDING_CORE
230 void run() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
235 #if !SST_BUILDING_CORE
236 void finish() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
241 #if !SST_BUILDING_CORE
242 bool isIndependentThread() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
return independent;}
244 bool isIndependentThread() {
return independent;}
251 #if !SST_BUILDING_CORE
252 TimeConverter*
registerOneShot(
const std::string& timeDelay, OneShot::HandlerBase* handler,
int priority) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
254 TimeConverter*
registerOneShot(
const std::string& timeDelay, OneShot::HandlerBase* handler,
int priority);
257 #if !SST_BUILDING_CORE
258 TimeConverter*
registerOneShot(
const UnitAlgebra& timeDelay, OneShot::HandlerBase* handler,
int priority) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
260 TimeConverter*
registerOneShot(
const UnitAlgebra& timeDelay, OneShot::HandlerBase* handler,
int priority);
263 #if !SST_BUILDING_CORE
264 const std::vector<SimTime_t>& getInterThreadLatencies() const __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
return interThreadLatencies; }
266 const std::vector<SimTime_t>& getInterThreadLatencies()
const {
return interThreadLatencies; }
269 #if !SST_BUILDING_CORE
270 SimTime_t getInterThreadMinLatency() const __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
return interThreadMinLatency; }
272 SimTime_t getInterThreadMinLatency()
const {
return interThreadMinLatency; }
275 #if !SST_BUILDING_CORE
276 static TimeConverter* getMinPartTC() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
return minPartTC; }
278 static TimeConverter* getMinPartTC() {
return minPartTC; }
282 #if !SST_BUILDING_CORE
283 LinkMap*
getComponentLinkMap(ComponentId_t
id)
const __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
288 if (
nullptr == info ) {
291 return info->getLinkMap();
296 #if !SST_BUILDING_CORE
297 const ComponentInfoMap&
getComponentInfoMap(
void) __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
return compInfoMap; }
303 #if !SST_BUILDING_CORE
304 BaseComponent*
getComponent(
const ComponentId_t &
id)
const __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
310 if (
nullptr != i ) {
311 return i->getComponent();
313 printf(
"Simulation::getComponent() couldn't find component with id = %" PRIu64
"\n",
id);
320 #if !SST_BUILDING_CORE
321 ComponentInfo*
getComponentInfo(
const ComponentId_t &
id)
const __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
327 if (
nullptr != i ) {
330 printf(
"Simulation::getComponentInfo() couldn't find component with id = %" PRIu64
"\n",
id);
340 #if !SST_BUILDING_CORE
341 void setOutputDirectory(
const std::string& outDir) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
345 output_directory = outDir;
352 #if !SST_BUILDING_CORE
353 std::string&
getOutputDirectory() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
357 return output_directory;
364 #if !SST_BUILDING_CORE
365 SimTime_t
getNextActivityTime()
const __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
374 #if !SST_BUILDING_CORE
375 static SimTime_t
getLocalMinimumNextActivityTime() __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
383 #if !SST_BUILDING_CORE
384 bool isWireUpFinished() __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11."))) {
return wireUpFinished; }
391 #if !SST_BUILDING_CORE
392 uint64_t getTimeVortexMaxDepth() const __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
394 uint64_t getTimeVortexMaxDepth()
const;
397 #if !SST_BUILDING_CORE
398 uint64_t getTimeVortexCurrentDepth() const __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
400 uint64_t getTimeVortexCurrentDepth()
const;
403 #if !SST_BUILDING_CORE
404 uint64_t getSyncQueueDataSize() const __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
406 uint64_t getSyncQueueDataSize()
const;
414 #if !SST_BUILDING_CORE
415 TimeConverter*
registerClock(
const std::string& freq, Clock::HandlerBase* handler,
int priority) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
417 TimeConverter*
registerClock(
const std::string& freq, Clock::HandlerBase* handler,
int priority);
420 #if !SST_BUILDING_CORE
421 TimeConverter*
registerClock(
const UnitAlgebra& freq, Clock::HandlerBase* handler,
int priority) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
423 TimeConverter*
registerClock(
const UnitAlgebra& freq, Clock::HandlerBase* handler,
int priority);
426 #if !SST_BUILDING_CORE
427 TimeConverter*
registerClock(TimeConverter *tcFreq, Clock::HandlerBase* handler,
int priority) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
429 TimeConverter*
registerClock(TimeConverter *tcFreq, Clock::HandlerBase* handler,
int priority);
433 #if !SST_BUILDING_CORE
434 void unregisterClock(TimeConverter *tc, Clock::HandlerBase* handler,
int priority) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
436 void unregisterClock(TimeConverter *tc, Clock::HandlerBase* handler,
int priority);
442 #if !SST_BUILDING_CORE
443 Cycle_t
reregisterClock(TimeConverter *tc, Clock::HandlerBase* handler,
int priority) __attribute__ ((deprecated(
"this function was not intended to be used outside of SST core and will be removed in SST 11.")));
445 Cycle_t
reregisterClock(TimeConverter *tc, Clock::HandlerBase* handler,
int priority);
449 #if !SST_BUILDING_CORE
450 Cycle_t
getNextClockCycle(TimeConverter* tc,
int priority = CLOCKPRIORITY) __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
456 #if !SST_BUILDING_CORE
457 Statistics::StatisticProcessingEngine*
getStatisticsProcessingEngine(
void) const __attribute__ ((deprecated("this function was not intended to be used outside of SST core and will be removed in SST 11.")));
470 friend int ::main(
int argc,
char **argv);
473 Simulation(Config* config, RankInfo my_rank, RankInfo num_ranks, SimTime_t min_part);
474 Simulation(Simulation
const&);
475 void operator=(Simulation
const&);
481 TimeConverter* minPartToTC(SimTime_t cycles)
const;
484 static Factory *factory;
486 static TimeLord timeLord;
488 static Output sim_output;
489 static void resizeBarriers(uint32_t nthr);
490 static Core::ThreadSafe::Barrier initBarrier;
491 static Core::ThreadSafe::Barrier completeBarrier;
492 static Core::ThreadSafe::Barrier setupBarrier;
493 static Core::ThreadSafe::Barrier runBarrier;
494 static Core::ThreadSafe::Barrier exitBarrier;
495 static Core::ThreadSafe::Barrier finishBarrier;
496 static std::mutex simulationMutex;
500 Component* createComponent(ComponentId_t
id,
const std::string& name,
503 TimeVortex* getTimeVortex()
const {
return timeVortex; }
508 static void emergencyShutdown();
511 void endSimulation(
void) { endSimulation(currentSimCycle); }
512 void endSimulation(SimTime_t end);
520 friend class SyncManager;
523 TimeVortex* timeVortex;
524 TimeConverter* threadMinPartTC;
525 Activity* current_activity;
526 static SimTime_t minPart;
527 static TimeConverter* minPartTC;
528 std::vector<SimTime_t> interThreadLatencies;
529 SimTime_t interThreadMinLatency;
530 SyncManager* syncManager;
531 ThreadSync* threadSync;
532 ComponentInfoMap compInfoMap;
535 SimTime_t currentSimCycle;
536 SimTime_t endSimCycle;
539 SimulatorHeartbeat* m_heartbeat;
544 static std::atomic<int> untimed_msg_count;
545 unsigned int untimed_phase;
546 volatile sig_atomic_t lastRecvdSignal;
547 ShutdownMode_t shutdown_mode;
548 std::string output_directory;
549 static SharedRegionManager* sharedRegionManager;
552 static std::unordered_map<std::thread::id, Simulation*> instanceMap;
553 static std::vector<Simulation*> instanceVec;
555 friend void wait_my_turn_start();
556 friend void wait_my_turn_end();
565 void wait_my_turn_start(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
567 void wait_my_turn_end(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
572 #endif //SST_CORE_SIMULATION_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
Cycle_t getNextClockCycle(TimeConverter *tc, int priority=CLOCKPRIORITY)
Returns the next Cycle that the TImeConverter would fire.
Definition: simulation.cc:745
Exit * getExit() const
Return the exit event.
Definition: simulation.h:166
static SimTime_t getLocalMinimumNextActivityTime()
Gets the minimum next activity time across all TimeVortices in the Rank.
Definition: simulation.cc:194
UnitAlgebra getFinalSimTime() const
Return the end simulation time as a time.
Definition: simulation.cc:681
Main control class for a SST Simulation.
Definition: simulation.h:73
Base class for all Activities in the SST Event Queue.
Definition: activity.h:52
Maps port names to the Links that are connected to it.
Definition: linkMap.h:28
Class to contain SST Simulation Configuration variables.
Definition: config.h:31
static TimeLord * getTimeLord(void)
Return the TimeLord associated with this Simulation.
Definition: simulation.h:130
RankInfo getNumRanks() const
Get the number of parallel ranks in the simulation.
Definition: simulation.h:160
Cycle_t reregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Reactivate an existing clock and handler.
Definition: simulation.cc:734
const SimTime_t & getCurrentSimCycle() const
Return the current simulation time as a cycle count.
Definition: simulation.cc:640
Mode_t getSimulationMode() const
Get the run mode of the simulation (e.g.
Definition: simulation.h:139
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:316
static Simulation * createSimulation(Config *config, RankInfo my_rank, RankInfo num_ranks, SimTime_t min_part)
Create new simulation.
Definition: simulation.cc:99
SimTime_t getNextActivityTime() const
Returns the time of the next item to be executed that is in the TImeVortex of the Simulation...
Definition: simulation.cc:188
std::string & getOutputDirectory()
Returns the output directory of the simulation.
Definition: simulation.h:353
void requireEvent(const std::string &name)
Signifies that an event type is required for this simulation Causes the Factory to verify that the re...
Definition: simulation.cc:182
void insertActivity(SimTime_t time, Activity *ev)
Insert an activity to fire at a specified time.
Definition: simulation.cc:787
Definition: simulation.h:78
ComponentInfo * getComponentInfo(const ComponentId_t &id) const
returns the ComponentInfo object for the given ID
Definition: simulation.h:321
Definition: simulation.h:77
static void setSignal(int signal)
Sets an internal flag for signaling the simulation.
Definition: simulation.cc:686
void setStopAtCycle(Config *cfg)
Set cycle count, which, if reached, will cause the simulation to halt.
Definition: simulation.cc:157
void initialize()
Perform the init() phase of simulation.
Definition: simulation.cc:416
Exit Event Action.
Definition: exit.h:34
std::map< std::pair< SimTime_t, int >, OneShot * > oneShotMap_t
Definition: simulation.h:84
Definition: componentInfo.h:250
static Output & getSimulationOutput()
Return the base simulation Output class instance.
Definition: simulation.h:133
int getCurrentPriority() const
Return the current priority.
Definition: simulation.cc:652
void setup()
Perform the setup() and run phases of the simulation.
Definition: simulation.cc:493
A Clock class.
Definition: clock.h:32
BaseComponent * getComponent(const ComponentId_t &id) const
returns the component with the given ID
Definition: simulation.h:304
static void shutdown()
Used to signify the end of simulation.
Definition: simulation.cc:112
int performWireUp(ConfigGraph &graph, const RankInfo &myRank, SimTime_t min_part)
Converts a ConfigGraph graph into actual set of links and components.
Definition: simulation.cc:282
LinkMap * getComponentLinkMap(ComponentId_t id) const
Return pointer to map of links for a given component id.
Definition: simulation.h:283
RankInfo getRank() const
Get this instance's parallel rank.
Definition: simulation.h:157
UnitAlgebra getElapsedSimTime() const
Return the elapsed simulation time as a time.
Definition: simulation.cc:676
Definition: rankInfo.h:21
Main component object for the simulation.
Definition: baseComponent.h:52
TimeConverter * registerOneShot(const std::string &timeDelay, OneShot::HandlerBase *handler, int priority)
Register a OneShot event to be called after a time delay Note: OneShot cannot be canceled, and will always callback after the timedelay.
Definition: simulation.cc:763
void setOutputDirectory(const std::string &outDir)
Set the output directory for this simulation.
Definition: simulation.h:341
static Simulation * getSimulation()
Return a pointer to the singleton instance of the Simulation.
Definition: simulation.h:122
A OneShot Event class.
Definition: oneshot.h:33
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:36
TimeConverter * registerClock(const std::string &freq, Clock::HandlerBase *handler, int priority)
Register a handler to be called on a set frequency.
Definition: simulation.cc:708
static SharedRegionManager * getSharedRegionManager()
Returns the Simulation's SharedRegionManager.
Definition: simulation.h:127
bool isWireUpFinished()
Returns true when the Wireup is finished.
Definition: simulation.h:384
Definition: simulation.h:79
void printStatus(bool fullStatus)
Causes the current status of the simulation to be printed to stderr.
Definition: simulation.cc:692
Definition: componentInfo.h:36
SimTime_t getEndSimCycle() const
Return the end simulation time as a cycle count.
Definition: simulation.cc:646
Statistics::StatisticProcessingEngine * getStatisticsProcessingEngine(void) const
Return the Statistic Processing Engine associated with this Simulation.
Definition: simulation.cc:805
Definition: simulation.h:80
void unregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Remove a clock handler from the list of active clock handlers.
Definition: simulation.cc:755
Mode_t
Type of Run Modes.
Definition: simulation.h:76
Performs Unit math in full precision.
Definition: unitAlgebra.h:107
std::map< std::pair< SimTime_t, int >, Clock * > clockMap_t
Definition: simulation.h:83
const ComponentInfoMap & getComponentInfoMap(void)
Returns reference to the Component Info Map.
Definition: simulation.h:297
void complete()
Perform the complete() phase of simulation.
Definition: simulation.cc:458
void processGraphInfo(ConfigGraph &graph, const RankInfo &myRank, SimTime_t min_part)
Processes the ConfigGraph to pull out any need information about relationships among the threads...
Definition: simulation.cc:208
Definition: sharedRegion.h:60