14 #ifndef SST_CORE_SIMULATION_H
15 #define SST_CORE_SIMULATION_H
17 #include "sst/core/sst_types.h"
24 #include <unordered_map>
26 #include <sst/core/output.h>
27 #include <sst/core/clock.h>
28 #include <sst/core/oneshot.h>
29 #include <sst/core/unitAlgebra.h>
30 #include <sst/core/rankInfo.h>
32 #include <sst/core/componentInfo.h>
35 extern int main(
int argc,
char **argv);
40 #define _SIM_DBG( fmt, args...) __DBG( DBG_SIM, Sim, fmt, ## args )
41 #define STATALLFLAG "--ALLSTATS--"
49 class SimulatorHeartbeat;
61 class SharedRegionManager;
62 namespace Statistics {
63 class StatisticOutput;
64 class StatisticProcessingEngine;
68 typedef std::map<std::string, Introspector* > IntroMap_t;
132 bool isIndependentThread() {
return independent;}
175 const std::vector<SimTime_t>& getInterThreadLatencies() {
return interThreadLatencies; }
176 const SimTime_t getInterThreadMinLatency() {
return interThreadMinLatency; }
177 static TimeConverter* getMinPartTC() {
return minPartTC; }
185 static void signalStatisticsBegin();
186 static void signalStatisticsEnd();
188 uint64_t getTimeVortexMaxDepth()
const;
189 uint64_t getTimeVortexCurrentDepth()
const;
190 uint64_t getSyncQueueDataSize()
const;
199 if ( NULL == info ) {
202 return info->getLinkMap();
219 return i->getComponent();
221 printf(
"Simulation::getComponent() couldn't find component with name = %s\n",
233 return i->getComponent();
235 printf(
"Simulation::getComponent() couldn't find component with id = %lu\n",
id);
240 ComponentInfo* getComponentInfo(
const std::string& name)
const
246 printf(
"Simulation::getComponentInfo() couldn't find component with name = %s\n",
252 ComponentInfo* getComponentInfo(
const ComponentId_t &
id)
const
254 ComponentInfo* i = compInfoMap.getByID(
id);
259 printf(
"Simulation::getComponentInfo() couldn't find component with id = %lu\n",
id);
264 statEnableList_t* getComponentStatisticEnableList(
const ComponentId_t &
id)
const
266 statEnableMap_t::const_iterator i = statisticEnableMap.find(
id);
267 if (i != statisticEnableMap.end()) {
270 printf(
"Simulation::getComponentStatisticEnableList() couldn't find component with id = %lu\n",
id);
276 statParamsList_t* getComponentStatisticParamsList(
const ComponentId_t &
id)
const
278 statParamsMap_t::const_iterator i = statisticParamsMap.find(
id);
279 if (i != statisticParamsMap.end()) {
282 printf(
"Simulation::getComponentStatisticParamsList() couldn't find component with id = %lu\n",
id);
292 IntroMap_t::const_iterator i = introMap.find(name);
293 if (i != introMap.end()) {
296 printf(
"Simulation::getIntrospector() couldn't find introspector with name = %s\n",
307 output_directory = outDir;
315 return output_directory;
351 friend int ::main(
int argc,
char **argv);
366 static Factory *factory;
368 static TimeLord timeLord;
370 static Statistics::StatisticOutput* statisticsOutput;
372 static Output sim_output;
373 static Core::ThreadSafe::Barrier barrier;
374 static Core::ThreadSafe::Barrier exit_barrier;
375 static std::mutex simulationMutex;
379 Component* createComponent(ComponentId_t
id, std::string &name,
381 Introspector* createIntrospector(std::string &name,
384 TimeVortex* getTimeVortex()
const {
return timeVortex; }
389 static void emergencyShutdown();
392 void endSimulation(
void) { endSimulation(currentSimCycle); }
393 void endSimulation(SimTime_t end);
401 friend class SyncManager;
404 TimeVortex* timeVortex;
405 TimeConverter* threadMinPartTC;
406 Activity* current_activity;
407 static SyncBase* sync;
408 static SimTime_t minPart;
409 static TimeConverter* minPartTC;
410 std::vector<SimTime_t> interThreadLatencies;
411 SimTime_t interThreadMinLatency;
412 SyncManager* syncManager;
413 ThreadSync* threadSync;
414 ComponentInfoMap compInfoMap;
417 statEnableMap_t statisticEnableMap;
418 statParamsMap_t statisticParamsMap;
419 oneShotMap_t oneShotMap;
420 SimTime_t currentSimCycle;
421 SimTime_t endSimCycle;
424 SimulatorHeartbeat* m_heartbeat;
429 static std::atomic<int> init_msg_count;
430 unsigned int init_phase;
431 volatile sig_atomic_t lastRecvdSignal;
432 ShutdownMode_t shutdown_mode;
434 std::string output_directory;
435 static SharedRegionManager* sharedRegionManager;
438 Statistics::StatisticProcessingEngine* statisticsEngine;
440 static std::unordered_map<std::thread::id, Simulation*> instanceMap;
441 static std::vector<Simulation*> instanceVec;
443 friend void wait_my_turn_start();
444 friend void wait_my_turn_end();
453 void wait_my_turn_start(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
456 void wait_my_turn_start();
458 void wait_my_turn_end(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
461 void wait_my_turn_end();
466 #endif //SST_CORE_SIMULATION_H
Output object provides consistant method for outputing data to stdout, stderr and/or sst debug file...
Definition: output.h:54
Exit * getExit() const
Return the exit event.
Definition: simulation.h:173
An Action is a schedulable Activity which is not an Event.
Definition: action.h:30
static SimTime_t getLocalMinimumNextActivityTime()
Gets the minimum next activity time across all TimeVortices in the Rank.
Definition: simulation.cc:222
TimeConverter * registerOneShot(std::string timeDelay, OneShot::HandlerBase *handler)
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:960
UnitAlgebra getFinalSimTime() const
Return the end simulation time as a time.
Definition: simulation.cc:871
Component * getComponent(const ComponentId_t &id) const
returns the component with the given ID
Definition: simulation.h:228
std::map< SimTime_t, Clock * > clockMap_t
Definition: simulation.h:85
Main control class for a SST Simulation.
Definition: simulation.h:75
Base class for all Activities in the SST Event Queue.
Definition: activity.h:53
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:180
RankInfo getNumRanks() const
Get the number of parallel ranks in the simulation.
Definition: simulation.h:149
std::vector< std::string > statEnableList_t
Definition: simulation.h:87
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:47
const SimTime_t & getCurrentSimCycle() const
Return the current simulation time as a cycle count.
Definition: simulation.cc:830
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:25
Mode_t getSimulationMode() const
Get the run mode of the simulation (e.g.
Definition: simulation.h:135
Main component object for the simulation.
Definition: component.h:56
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:202
TimeConverter * registerClock(std::string freq, Clock::HandlerBase *handler)
Register a handler to be called on a set frequency.
Definition: simulation.cc:898
static Simulation * createSimulation(Config *config, RankInfo my_rank, RankInfo num_ranks, SimTime_t min_part)
Create new simulation.
Definition: simulation.cc:120
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:216
std::string & getOutputDirectory()
Returns the output directory of the simulation.
Definition: simulation.h:314
std::map< SimTime_t, OneShot * > oneShotMap_t
Definition: simulation.h:86
void insertActivity(SimTime_t time, Activity *ev)
Insert an activity to fire at a specified time.
Definition: simulation.cc:983
Definition: simulation.h:80
void setOutputDirectory(std::string &outDir)
Set the output directory for this simulation.
Definition: simulation.h:306
Cycle_t reregisterClock(TimeConverter *tc, Clock::HandlerBase *handler)
Reactivate an existing clock and handler.
Definition: simulation.cc:930
Definition: simulation.h:79
static void setSignal(int signal)
Sets an internal flag for signaling the simulation.
Definition: simulation.cc:876
void setStopAtCycle(Config *cfg)
Set cycle count, which, if reached, will cause the simulation to halt.
Definition: simulation.cc:180
Statistics::StatisticProcessingEngine * getStatisticsProcessingEngine(void) const
Return the Statistic Processing Engine associated with this Simulation.
Definition: simulation.h:194
void initialize()
Perform the init() phase of simulation.
Definition: simulation.cc:618
Exit Event Action.
Definition: exit.h:34
Definition: componentInfo.h:108
static Output & getSimulationOutput()
Return the base simulation Output class instance.
Definition: simulation.h:182
int getCurrentPriority() const
Return the current priority.
Definition: simulation.cc:842
void setup()
Perform the setup() and run phases of the simulation.
Definition: simulation.cc:665
Cycle_t getNextClockCycle(TimeConverter *tc)
Returns the next Cycle that the TImeConverter would fire.
Definition: simulation.cc:941
std::vector< Params > statParamsList_t
Definition: simulation.h:88
Main introspector object for the simulation.
Definition: introspector.h:36
static void shutdown()
Used to signify the end of simulation.
Definition: simulation.cc:133
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:318
void requireEvent(std::string name)
Signifies that an event type is required for this simulation Causes to Factory to verify that the req...
Definition: simulation.cc:210
LinkMap * getComponentLinkMap(ComponentId_t id) const
Return pointer to map of links for a given component id.
Definition: simulation.h:197
RankInfo getRank() const
Get this instance's parallel rank.
Definition: simulation.h:147
UnitAlgebra getElapsedSimTime() const
Return the elapsed simulation time as a time.
Definition: simulation.cc:866
Definition: rankInfo.h:21
Functor classes for Clock handling.
Definition: clock.h:44
Component * getComponent(const std::string &name) const
Returns the component with a given name.
Definition: simulation.h:215
void unregisterClock(TimeConverter *tc, Clock::HandlerBase *handler)
Remove a clock handler from the list of active clock handlers.
Definition: simulation.cc:950
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:36
std::map< ComponentId_t, statParamsList_t * > statParamsMap_t
Definition: simulation.h:90
static SharedRegionManager * getSharedRegionManager()
Returns the Simulation's SharedRegionManager.
Definition: simulation.h:339
bool isWireUpFinished()
Returns true when the Wireup is finished.
Definition: simulation.h:344
Definition: simulation.h:81
void printStatus(bool fullStatus)
Causes the current status of the simulation to be printed to stderr.
Definition: simulation.cc:882
SimTime_t getEndSimCycle() const
Return the end simulation time as a cycle count.
Definition: simulation.cc:836
Definition: simulation.h:82
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:33
Mode_t
Type of Run Modes.
Definition: simulation.h:78
Performs Unit math in full precision.
Definition: unitAlgebra.h:112
Introspector * getIntrospector(const std::string &name) const
Returns the Introspector with the given name.
Definition: simulation.h:290
Definition: threadsafe.h:42
Definition: componentInfo.h:36
Link between two components.
Definition: link.h:33
const ComponentInfoMap & getComponentInfoMap(void)
Returns reference to the Component Map.
Definition: simulation.h:211
std::map< ComponentId_t, statEnableList_t * > statEnableMap_t
Definition: simulation.h:89
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:236
static Simulation * getSimulation()
Return a pointer to the singleton instance of the Simulation.
Definition: simulation.h:106
Definition: sharedRegion.h:56
Functor classes for OneShot handling.
Definition: oneshot.h:39