14#ifndef SST_CORE_SIMULATION_IMPL_H
15#define SST_CORE_SIMULATION_IMPL_H
17#include "sst/core/clock.h"
18#include "sst/core/componentInfo.h"
19#include "sst/core/oneshot.h"
20#include "sst/core/output.h"
21#include "sst/core/profile/profiletool.h"
22#include "sst/core/rankInfo.h"
23#include "sst/core/simulation.h"
24#include "sst/core/sst_types.h"
25#include "sst/core/unitAlgebra.h"
32#include <unordered_map>
35extern int main(
int argc,
char** argv);
39#define _SIM_DBG(fmt, args...) __DBG(DBG_SIM, Sim, fmt, ##args)
40#define STATALLFLAG "--ALLSTATS--"
48class SimulatorHeartbeat;
52class SharedRegionManager;
53class SimulatorHeartbeat;
61class SharedRegionManager;
64class StatisticProcessingEngine;
69class StatisticProcessingEngine;
118 virtual void requireEvent(
const std::string& name)
override;
129 virtual void printStatus(
bool fullStatus)
override;
183 void exchangeLinkInfo();
201 bool isIndependentThread() {
return independent; }
203 void printProfilingInfo(FILE* fp);
205 void printPerformanceInfo();
215 const std::vector<SimTime_t>& getInterThreadLatencies()
const {
return interThreadLatencies; }
217 SimTime_t getInterThreadMinLatency()
const {
return interThreadMinLatency; }
219 static TimeConverter* getMinPartTC() {
return minPartTC; }
221 LinkMap* getComponentLinkMap(ComponentId_t
id)
const
223 ComponentInfo* info = compInfoMap.getByID(
id);
224 if (
nullptr == info ) {
return nullptr; }
226 return info->getLinkMap();
238 if (
nullptr != i ) {
return i->getComponent(); }
240 printf(
"Simulation::getComponent() couldn't find component with id = %" PRIu64
"\n",
id);
250 if (
nullptr != i ) {
return i; }
252 printf(
"Simulation::getComponentInfo() couldn't find component with id = %" PRIu64
"\n",
id);
274 uint64_t getTimeVortexMaxDepth()
const;
276 uint64_t getTimeVortexCurrentDepth()
const;
278 uint64_t getSyncQueueDataSize()
const;
308 friend int ::main(
int argc,
char** argv);
323 static void resizeBarriers(uint32_t nthr);
330 static std::mutex simulationMutex;
332 static std::map<LinkId_t, Link*> cross_thread_links;
333 bool direct_interthread;
335 Component* createComponent(ComponentId_t
id,
const std::string& name,
Params& params);
337 TimeVortex* getTimeVortex()
const {
return timeVortex; }
354 friend class SyncManager;
356 TimeVortex* timeVortex;
357 TimeConverter* threadMinPartTC;
358 Activity* current_activity;
359 static SimTime_t minPart;
360 static TimeConverter* minPartTC;
361 std::vector<SimTime_t> interThreadLatencies;
362 SimTime_t interThreadMinLatency;
363 SyncManager* syncManager;
365 ComponentInfoMap compInfoMap;
369 SimulatorHeartbeat* m_heartbeat;
372 static std::atomic<int> untimed_msg_count;
373 unsigned int untimed_phase;
374 volatile sig_atomic_t lastRecvdSignal;
375 ShutdownMode_t shutdown_mode;
387 std::map<std::string, SST::Profile::ProfileTool*> profile_tools;
389 std::map<std::string, std::vector<std::string>> profiler_map;
391 template <
typename T>
392 std::vector<T*> getProfileTool(std::string point)
396 std::vector<std::string>& profilers = profiler_map.at(point);
398 for (
auto& x : profilers ) {
402 T* tool =
dynamic_cast<T*
>(val);
405 Output::getDefaultObject().fatal(
407 "ERROR: wrong type of profiling tool found (name = %s). Check to make sure the profiling "
408 "points enabled for this tool accept the type specified\n",
413 catch ( std::out_of_range& e ) {
416 Output::getDefaultObject().fatal(
418 "INTERNAL ERROR: ProfileTool refered to in profiler_map not found in profile_tools map\n");
423 catch ( std::out_of_range& e ) {
433#if SST_PERFORMANCE_INSTRUMENTING
437#if SST_PERIODIC_PRINT
438 uint64_t periodicCounter = 0;
441#if SST_RUNTIME_PROFILING
442 uint64_t sumtime = 0;
443 uint64_t runtime = 0;
444 struct timeval start, end, diff;
445 struct timeval sumstart, sumend, sumdiff;
449#if SST_EVENT_PROFILING
450 uint64_t rankLatency = 0;
451 uint64_t messageXferSize = 0;
453 uint64_t rankExchangeBytes = 0;
454 uint64_t rankExchangeEvents = 0;
455 uint64_t rankExchangeCounter = 0;
459 void incrementSerialCounters(uint64_t count);
460 void incrementExchangeCounters(uint64_t events, uint64_t bytes);
464#if SST_SYNC_PROFILING
465 uint64_t rankSyncCounter = 0;
466 uint64_t rankSyncTime = 0;
467 uint64_t threadSyncCounter = 0;
468 uint64_t threadSyncTime = 0;
470 void incrementSyncTime(
bool rankSync, uint64_t count);
473#if SST_HIGH_RESOLUTION_CLOCK
474 uint64_t clockDivisor = 1e9;
475 std::string clockResolution =
"ns";
477 uint64_t clockDivisor = 1e6;
478 std::string clockResolution =
"us";
482 SimTime_t currentSimCycle;
483 SimTime_t endSimCycle;
488 std::string output_directory;
489 static SharedRegionManager* sharedRegionManager;
491 double run_phase_start_time;
492 double run_phase_total_time;
493 double init_phase_start_time;
494 double init_phase_total_time;
495 double complete_phase_start_time;
496 double complete_phase_total_time;
498 static std::unordered_map<std::thread::id, Simulation_impl*> instanceMap;
499 static std::vector<Simulation_impl*> instanceVec;
501 friend void wait_my_turn_start();
502 friend void wait_my_turn_end();
509 SimTime_t getNextActivityTime()
const;
517void wait_my_turn_start(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
519void wait_my_turn_end(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
An Action is a schedulable Activity which is not an Event.
Definition: action.h:27
Base class for all Activities in the SST Event Queue.
Definition: activity.h:46
Main component object for the simulation.
Definition: baseComponent.h:51
A Clock class.
Definition: clock.h:33
Definition: componentInfo.h:250
Definition: componentInfo.h:40
Main component object for the simulation.
Definition: component.h:31
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:390
Class to contain SST Simulation Configuration variables.
Definition: config.h:30
Definition: threadsafe.h:48
Exit Event Action.
Definition: exit.h:35
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:43
Link between two components.
Definition: link.h:38
A OneShot Event class.
Definition: oneshot.h:33
SSTHandlerBaseNoArgs< void > HandlerBase
Base handler for OneShot callbacks.
Definition: oneshot.h:38
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition: output.h:52
Parameter store.
Definition: params.h:56
Definition: rankInfo.h:22
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:171
Main control class for a SST Simulation.
Definition: simulation_impl.h:77
void setOutputDirectory(const std::string &outDir)
Set the output directory for this simulation.
Definition: simulation_impl.h:261
Mode_t getSimulationMode() const override
Get the run mode of the simulation (e.g.
Definition: simulation_impl.h:82
TimeConverter * minPartToTC(SimTime_t cycles) const
Get a handle to a TimeConverter.
Definition: simulation.cc:114
SimTime_t getCurrentSimCycle() const override
Return the current simulation time as a cycle count.
Definition: simulation.cc:74
void setup()
Perform the setup() and run phases of the simulation.
Definition: simulation.cc:614
std::map< std::pair< SimTime_t, int >, Clock * > clockMap_t
Definition: simulation_impl.h:137
static Output sim_output
Output.
Definition: simulation_impl.h:381
int getCurrentPriority() const override
Return the current priority.
Definition: simulation.cc:86
Exit * getExit() const
Return the exit event.
Definition: simulation_impl.h:172
virtual double getRunPhaseElapsedRealTime() const override
Get the amount of real-time spent executing the run phase of the simulation.
Definition: simulation.cc:852
const ComponentInfoMap & getComponentInfoMap(void)
Returns reference to the Component Info Map.
Definition: simulation_impl.h:231
UnitAlgebra getElapsedSimTime() const override
Return the elapsed simulation time as a time.
Definition: simulation.cc:92
void insertActivity(SimTime_t time, Activity *ev)
Insert an activity to fire at a specified time.
Definition: simulation.cc:970
static Factory * factory
Factory used to generate the simulation components.
Definition: simulation_impl.h:321
void initialize()
Perform the init() phase of simulation.
Definition: simulation.cc:533
Cycle_t getNextClockCycle(TimeConverter *tc, int priority=CLOCKPRIORITY)
Returns the next Cycle that the TImeConverter would fire.
Definition: simulation.cc:922
ComponentInfo * getComponentInfo(const ComponentId_t &id) const
returns the ComponentInfo object for the given ID
Definition: simulation_impl.h:246
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:274
BaseComponent * getComponent(const ComponentId_t &id) const
returns the component with the given ID
Definition: simulation_impl.h:234
static Simulation_impl * getSimulation()
Return a pointer to the singleton instance of the Simulation.
Definition: simulation_impl.h:145
Cycle_t reregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Reactivate an existing clock and handler.
Definition: simulation.cc:910
virtual double getCompletePhaseElapsedRealTime() const override
Get the amount of real-time spent executing the complete phase of the simulation.
Definition: simulation.cc:872
bool isWireUpFinished()
Returns true when the Wireup is finished.
Definition: simulation_impl.h:272
static TimeLord * getTimeLord(void)
Return the TimeLord associated with this Simulation.
Definition: simulation_impl.h:148
RankInfo getNumRanks() const override
Get the number of parallel ranks in the simulation.
Definition: simulation_impl.h:106
static Output & getSimulationOutput()
Return the base simulation Output class instance.
Definition: simulation_impl.h:151
virtual void printStatus(bool fullStatus) override
Causes the current status of the simulation to be printed to stderr.
Definition: simulation.cc:837
void complete()
Perform the complete() phase of simulation.
Definition: simulation.cc:578
void intializeProfileTools(const std::string &config)
Performance Tracking Information.
Definition: simulation.cc:1070
virtual void requireEvent(const std::string &name) override
Signifies that an event type is required for this simulation Causes the Factory to verify that the re...
Definition: simulation.cc:245
virtual void requireLibrary(const std::string &name) override
Signifies that a library is required for this simulation.
Definition: simulation.cc:251
TimeConverter * registerClock(const std::string &freq, Clock::HandlerBase *handler, int priority)
Register a handler to be called on a set frequency.
Definition: simulation.cc:882
UnitAlgebra getFinalSimTime() const override
Return the end simulation time as a time.
Definition: simulation.cc:104
static TimeLord timeLord
TimeLord of the simulation.
Definition: simulation_impl.h:379
static SimTime_t getLocalMinimumNextActivityTime()
Gets the minimum next activity time across all TimeVortices in the Rank.
Definition: simulation.cc:263
RankInfo getRank() const override
Get this instance's parallel rank.
Definition: simulation_impl.h:103
static void shutdown()
Used to signify the end of simulation.
Definition: simulation.cc:180
void endSimulation(void)
Normal Shutdown.
Definition: simulation.cc:779
static Simulation_impl * createSimulation(Config *config, RankInfo my_rank, RankInfo num_ranks)
Create new simulation.
Definition: simulation.cc:166
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,...
Definition: simulation.cc:944
SimTime_t getEndSimCycle() const override
Return the end simulation time as a cycle count.
Definition: simulation.cc:80
Statistics::StatisticProcessingEngine * getStatisticsProcessingEngine(void) const
Return the Statistic Processing Engine associated with this Simulation.
Definition: simulation.cc:995
void unregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Remove a clock handler from the list of active clock handlers.
Definition: simulation.cc:934
static void setSignal(int signal)
Sets an internal flag for signaling the simulation.
Definition: simulation.cc:830
void setStopAtCycle(Config *cfg)
Set cycle count, which, if reached, will cause the simulation to halt.
Definition: simulation.cc:228
UnitAlgebra getEndSimTime() const override
Return the end simulation time as a time.
Definition: simulation.cc:98
static void emergencyShutdown()
Emergency Shutdown Called when a SIGINT or SIGTERM has been seen.
Definition: simulation.cc:761
virtual double getInitPhaseElapsedRealTime() const override
Get the amount of real-time spent executing the init phase of the simulation.
Definition: simulation.cc:862
std::map< std::pair< SimTime_t, int >, OneShot * > oneShotMap_t
Definition: simulation_impl.h:138
std::string & getOutputDirectory() override
Returns the output directory of the simulation.
Definition: simulation_impl.h:112
Main control class for a SST Simulation.
Definition: simulation.h:35
Mode_t
Type of Run Modes.
Definition: simulation.h:38
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:52
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:27
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:38
Primary Event Queue.
Definition: timeVortex.h:26
Performs Unit math in full precision.
Definition: unitAlgebra.h:109