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/exit.h"
20#include "sst/core/impl/oneshotManager.h"
21#include "sst/core/output.h"
22#include "sst/core/profile/profiletool.h"
23#include "sst/core/rankInfo.h"
24#include "sst/core/sst_types.h"
25#include "sst/core/statapi/statengine.h"
26#include "sst/core/timeConverter.h"
27#include "sst/core/unitAlgebra.h"
28#include "sst/core/util/basicPerf.h"
29#include "sst/core/util/filesystem.h"
41#include <unordered_map>
46extern int main(
int argc,
char** argv);
52void SST_Exit(
int exit_code);
54#define _SIM_DBG(fmt, args...) __DBG(DBG_SIM, Sim, fmt, ##args)
98 std::vector<Activity*> data;
100 using iterator = std::vector<Activity*>::iterator;
103 iterator action_start;
105 TimeVortexSort() =
default;
109 std::pair<iterator, iterator> getEventsForHandler(uintptr_t handler);
111 std::pair<iterator, iterator> getActions();
168 double getRunPhaseElapsedRealTime()
const;
169 double getInitPhaseElapsedRealTime()
const;
170 double getCompletePhaseElapsedRealTime()
const;
182 static Simulation*
getSimulation() {
return instanceMap.at(std::this_thread::get_id()); }
196 RankInfo my_rank,
RankInfo num_ranks,
bool restart, SimTime_t currentSimCycle,
int currentPriority);
221 int initializeStatisticEngine(
StatsConfig* stats_config);
224 void exchangeLinkInfo();
228 void findThreadSyncInterval();
229 void updateSyncMinPart();
246 void prepare_for_run();
248 void setup_interactive_mode();
254 void updateSyncInterval();
261 bool isIndependentThread() {
return independent; }
263 void printProfilingInfo(Util::PerfReporter* reporter);
265 void printPerformanceInfo();
268 const std::vector<SimTime_t>& getInterThreadLatencies()
const {
return interThreadLatencies; }
270 SimTime_t getInterThreadMinLatency()
const {
return interThreadMinLatency; }
272 static TimeConverter getMinPartTC() {
return minPartTC; }
274 LinkMap* getComponentLinkMap(ComponentId_t
id)
const
276 ComponentInfo* info = compInfoMap.getByID(
id);
277 if (
nullptr == info ) {
281 return info->getLinkMap();
292 if (
nullptr != i ) {
293 return i->getComponent();
296 printf(
"Simulation::getComponent() couldn't find component with id = %" PRIu64
"\n",
id);
305 if (
nullptr != i ) {
309 printf(
"Simulation::getComponentInfo() couldn't find component with id = %" PRIu64
"\n",
id);
331 uint64_t getTimeVortexMaxDepth()
const;
333 uint64_t getTimeVortexCurrentDepth()
const;
335 uint64_t getSyncQueueDataSize()
const;
341 std::pair<pvt::TimeVortexSort::iterator, pvt::TimeVortexSort::iterator> getEventsForHandler(uintptr_t handler);
356 Clock* reportClock(SimTime_t factor,
int priority);
384 void registerClockGroup(
TimeConverter tc, Clock::Group* group);
385 void registerClockGroup(SimTime_t factor, Clock::Group* group);
395 friend int ::main(
int argc,
char** argv);
406 static void writeCheckpointConfigGraph(
ConfigGraph* graph);
407 void scheduleCheckpoint();
408 void scheduleInteractiveConsole(
const std::string& msg);
413 void checkpoint(
const std::string& checkpoint_filename);
425 const std::string& registry_filename,
const std::string& globals_filename);
428 void discoverRemoteLinks();
433 std::vector<std::pair<LinkId_t, RankInfo>>* xfer_vec =
nullptr;
435 void discoverRemoteLinksMoveData(
436 std::vector<std::pair<LinkId_t, RankInfo>>& send_vec, std::vector<std::pair<LinkId_t, RankInfo>>& recv_vec);
448 if ( serial_restart_ )
return RankInfo(0, 0);
449 return RankInfo(rank.rank, rank.thread);
452 void initialize_interactive_console(
const std::string& type);
463 static void resizeBarriers(uint32_t nthr);
470 static std::mutex simulationMutex;
476 static std::map<LinkId_t, Link*> cross_thread_links;
477 bool direct_interthread;
479 Component* createComponent(ComponentId_t
id,
const std::string& name,
Params& params);
481 TimeVortex* getTimeVortex()
const {
return timeVortex; }
511 void checkIndependent();
513 enum ShutdownMode_t {
519 friend class SyncManager;
533 TimeVortex* timeVortex =
nullptr;
534 std::string timeVortexType;
535 TimeConverter threadMinPartTC;
536 Activity* current_activity;
537 static SimTime_t minPart;
538 static TimeConverter minPartTC;
539 std::vector<SimTime_t> interThreadLatencies;
540 SimTime_t interThreadMinLatency = MAX_SIMTIME_T;
541 SyncManager* syncManager;
542 ComponentInfoMap compInfoMap;
545 SimulatorHeartbeat* m_heartbeat =
nullptr;
546 CheckpointAction* checkpoint_action_;
547 static std::string checkpoint_directory_;
548 static std::string checkpoint_configgraph_;
551 static std::atomic<int> untimed_msg_count;
552 unsigned int untimed_phase;
553 volatile sig_atomic_t signal_arrived_;
554 ShutdownMode_t shutdown_mode_;
555 bool enter_shutdown_ =
false;
556 bool wireUpFinished_;
557 RealTimeManager* real_time_;
558 std::string interactive_type_ =
"";
559 std::string interactive_start_ =
"";
560 std::string replay_file_ =
"";
561 InteractiveConsole* interactive_ =
nullptr;
562 bool enter_interactive_ =
false;
563 std::string interactive_msg_;
564 SimTime_t stop_at_ = 0;
566 uint32_t next_link_order_tag_ = 1;
597 std::map<std::string, SST::Profile::ProfileTool*> profile_tools;
599 std::map<std::string, std::vector<std::string>> profiler_map;
601 template <
typename T>
602 std::vector<T*> getProfileTool(std::string point)
606 std::vector<std::string>& profilers = profiler_map.at(point);
608 for (
auto& x : profilers ) {
612 T* tool =
dynamic_cast<T*
>(val);
615 Output::getDefaultObject().fatal(CALL_INFO_LONG, 1,
616 "ERROR: wrong type of profiling tool found (name = %s). Check to make sure the profiling "
617 "points enabled for this tool accept the type specified\n",
622 catch (
const std::out_of_range& e ) {
625 Output::getDefaultObject().fatal(CALL_INFO_LONG, 1,
626 "INTERNAL ERROR: ProfileTool referred to in profiler_map not found in profile_tools map\n");
631 catch (
const std::out_of_range& e ) {
641#if SST_PERFORMANCE_INSTRUMENTING
645#if SST_PERIODIC_PRINT
646 uint64_t periodicCounter = 0;
649#if SST_RUNTIME_PROFILING
650 uint64_t sumtime = 0;
651 uint64_t runtime = 0;
652 struct timeval start, end, diff;
653 struct timeval sumstart, sumend, sumdiff;
657#if SST_EVENT_PROFILING
658 uint64_t rankLatency = 0;
659 uint64_t messageXferSize = 0;
661 uint64_t rankExchangeCounter = 0;
665 void incrementSerialCounters(uint64_t count);
669#if SST_HIGH_RESOLUTION_CLOCK
670 uint64_t clockDivisor = 1e9;
671 std::string clockResolution =
"ns";
673 uint64_t clockDivisor = 1e6;
674 std::string clockResolution =
"us";
678 SimulationRunMode runMode;
681 SimTime_t currentSimCycle = 0;
682 int currentPriority = 0;
683 SimTime_t endSimCycle = 0;
689 std::string output_directory;
691 double run_phase_start_time_;
692 double run_phase_total_time_;
693 double init_phase_start_time_;
694 double init_phase_total_time_;
695 double complete_phase_start_time_;
696 double complete_phase_total_time_;
698 static std::unordered_map<std::thread::id, Simulation*> instanceMap;
699 static std::vector<Simulation*> instanceVec_;
702 std::map<LinkId_t, Link*> link_restart_tracking;
703 std::map<uintptr_t, uintptr_t> event_handler_restart_tracking;
704 uint32_t checkpoint_id_ = 0;
705 std::string checkpoint_prefix_ =
"";
706 std::string globalOutputFileName =
"";
707 std::string version_ =
"";
708 std::string arch_ =
"";
709 std::string os_ =
"";
710 bool serial_restart_ =
false;
713 static Config config;
714 static StatsConfig* stats_config_;
716 void printSimulationState();
718 friend void wait_my_turn_start();
719 friend void wait_my_turn_end();
726 SimTime_t getNextActivityTime()
const;
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:48
Main component object for the simulation.
Definition baseComponent.h:98
A recurring event to trigger checkpoint generation.
Definition checkpointAction.h:69
Base classes for clock handlers.
Definition clock.h:146
A Clock class.
Definition clock.h:40
Definition componentInfo.h:285
Definition componentInfo.h:45
Main component object for the simulation.
Definition component.h:32
A Configuration Graph A graph representing Components and Links.
Definition configGraph.h:76
Class to contain SST Simulation Configuration variables.
Definition config.h:52
Manages the OneShot actions for the core.
Definition oneshotManager.h:100
Base class for objects created by the serializer mapping mode used to map the variables for objects.
Definition objectMap.h:189
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Definition threadsafe.h:50
Definition threadsafe.h:169
Definition threadsafe.h:138
Exit Action.
Definition exit.h:35
Class for instantiating Components, Links and the like out of element libraries.
Definition factory.h:56
Definition interactiveConsole.h:47
Maps port names to the Links that are connected to it.
Definition linkMap.h:30
Link between two components.
Definition link.h:57
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition output.h:58
Parameter store.
Definition params.h:65
Class to manage real-time events (signals and alarms).
Definition realtime.h:175
Main control class for a SST Simulation.
Definition simulation.h:121
static Simulation * getSimulation()
Return a pointer to the singleton instance of the Simulation.
Definition simulation.h:182
void setupSimActions()
Setup external control actions (forced stops, signal handling.
Definition simulation.cc:420
bool isWireUpFinished()
Returns true when the Wireup is finished.
Definition simulation.h:329
void setEndSim()
Set EndSim Called by SyncMgr when interactive console ready to shutdown.
Definition simulation.cc:1245
Cycle_t getNextClockCycle(TimeConverter tc, int priority=CLOCKPRIORITY)
Returns the next Cycle that the TimeConverter would fire.
Definition simulation.cc:1460
static Output & getSimulationOutput()
Return the base simulation Output class instance.
Definition simulation.h:188
static SST::Util::Filesystem filesystem
Filesystem object that will be used to ensure all core-created files end up in the directory specifie...
Definition simulation.h:461
static TimeLord * getTimeLord()
Return the TimeLord associated with this Simulation.
Definition simulation.h:185
static Simulation * createSimulation(RankInfo my_rank, RankInfo num_ranks, bool restart, SimTime_t currentSimCycle, int currentPriority)
Create new simulation.
Definition simulation.cc:244
static Output sim_output
Output.
Definition simulation.h:587
void signalShutdown(bool abnormal)
Signal Shutdown Called when a signal needs to terminate SST E.g., SIGINT or SIGTERM has been seen abn...
Definition simulation.cc:1212
TimeConverter minPartToTC(SimTime_t cycles) const
Get a handle to a TimeConverter.
Definition simulation.cc:188
void requireLibrary(const std::string &name)
Signifies that a library is required for this simulation.
Definition simulation.cc:548
RankInfo getNumRanks() const
Get the number of parallel ranks in the simulation.
Definition simulation.h:149
std::map< std::pair< SimTime_t, int >, Clock * > clockMap_t
Definition simulation.h:174
bool parseSignalString(std::string &arg, std::string &name, Params ¶ms)
Helper for signal string parsing.
Definition simulation.cc:490
ComponentInfo * getComponentInfo(const ComponentId_t &id) const
returns the ComponentInfo object for the given ID
Definition simulation.h:302
Cycle_t reregisterClock(TimeConverter tc, Clock::HandlerBase *handler, int priority)
Reactivate an existing clock and handler.
Definition simulation.cc:1441
void checkpoint_write_globals(int checkpoint_id, const std::string &checkpoint_filename, const std::string ®istry_filename, const std::string &globals_filename)
Write the global data to a binary file and create the registry and write the header info.
Definition simulation.cc:1837
std::vector< std::pair< ComponentId_t, uint64_t > > component_blob_offsets_
vector to hold offsets of component blobs in checkpoint files
Definition simulation.h:580
SST::Statistics::StatisticProcessingEngine stat_engine
Statistics Engine.
Definition simulation.h:591
void setOutputDirectory(const std::string &outDir)
Set the output directory for this simulation.
Definition simulation.h:318
SimTime_t getCurrentSimCycle() const
Return the current simulation time as a cycle count.
Definition simulation.cc:156
void insertActivity(SimTime_t time, Activity *ev)
Insert an activity to fire at a specified time.
Definition simulation.cc:1522
SimTime_t getEndSimCycle() const
Return the end simulation time as a cycle count.
Definition simulation.cc:162
void unregisterClock(TimeConverter tc, Clock::HandlerBase *handler, int priority)
Remove a clock handler from the list of active clock handlers.
Definition simulation.cc:1484
static Factory * factory
Factory used to generate the simulation components.
Definition simulation.h:455
int getCurrentPriority() const
Return the current priority.
Definition simulation.cc:168
SimTime_t getClockForHandler(Clock::HandlerBase *handler)
Gets the clock the handler is registered with, represented by it's factor.
Definition simulation.cc:1472
uint32_t getNextLinkOrderTag()
Gets the next value for the order field of the link.
Definition simulation.h:572
static SimTime_t getLocalMinimumNextActivityTime()
Gets the minimum next activity time across all TimeVortices in the Rank.
Definition simulation.cc:560
void endSimulation()
Normal Shutdown.
Definition simulation.cc:1254
CheckpointAction * getCheckpointAction() const
Return the checkpoint event.
Definition simulation.h:338
static void shutdown()
Used to signify the end of simulation.
Definition simulation.cc:265
BaseComponent * getComponent(const ComponentId_t &id) const
returns the component with the given ID
Definition simulation.h:289
std::string & getOutputDirectory()
Returns the output directory of the simulation.
Definition simulation.h:155
void checkpoint(const std::string &checkpoint_filename)
Write the partition specific checkpoint data.
Definition simulation.cc:2017
static TimeLord timeLord
TimeLord of the simulation.
Definition simulation.h:585
void printStatus(bool fullStatus)
Causes the current status of the simulation to be printed to stderr.
Definition simulation.cc:1338
void consoleShutdown(bool abnormal)
Console Shutdown Called when a shutdown command or watchpoint shutdown action trigger needs to termin...
Definition simulation.cc:1225
void registerClock_restart(SimTime_t factor, Clock::HandlerBase *handler, int priority)
Register a clock on a restart.
Definition simulation.cc:1453
const ComponentInfoMap & getComponentInfoMap() const
Returns reference to the Component Info Map.
Definition simulation.h:286
UnitAlgebra getElapsedSimTime() const
Return the elapsed simulation time as a time.
Definition simulation.cc:174
Exit * getExit() const
Return the exit event.
Definition simulation.h:214
void setup()
Perform the setup() and run phases of the simulation.
Definition simulation.cc:969
static void notifySignal()
Sets an internal flag for signaling the simulation.
Definition simulation.cc:1326
UnitAlgebra getEndSimTime() const
Return the end simulation time as a time.
Definition simulation.cc:180
void findRankSyncInterval()
Functions to compute the current rank and thread sync intervals.
Definition simulation.cc:868
void complete()
Perform the complete() phase of simulation.
Definition simulation.cc:934
void initializeProfileTools(const std::string &config)
Performance Tracking Information.
Definition simulation.cc:1607
RankInfo getRank() const
Get this instance's parallel rank.
Definition simulation.h:146
void initialize()
Perform the init() phase of simulation.
Definition simulation.cc:886
Statistics::StatisticProcessingEngine * getStatisticsProcessingEngine()
Return the Statistic Processing Engine associated with this Simulation.
Definition simulation.cc:1547
void checkpoint_append_registry(const std::string ®istry_name, const std::string &blob_name)
Append partitions registry information.
Definition simulation.cc:1995
SimulationRunMode getSimulationMode() const
Get the run mode of the simulation (e.g.
Definition simulation.h:128
RankInfo getRankForLinkOnRestart(RankInfo rank, LinkId_t UNUSED(id))
Function used to get the rank for a link on restart.
Definition simulation.h:446
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:573
static void emergencyShutdown()
Emergency Shutdown Called when a fatal event has occurred.
Definition simulation.cc:1196
void adjustTimeAtSimEnd()
Adjust clocks and time to reflect precise simulation end time which may differ in parallel simulation...
Definition simulation.cc:1276
TimeConverter registerClock(const std::string &freq, Clock::HandlerBase *handler, int priority)
Register a handler to be called on a set frequency.
Definition simulation.cc:1389
An optional heartbeat to show progress in a simulation.
Definition heartbeat.h:34
Forms the base class for statistics output generation within the SST core.
Definition statoutput.h:54
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition statengine.h:55
Definition syncManager.h:192
Definition syncManager.h:121
A class to convert between a component's view of time and the core's view of time.
Definition timeConverter.h:31
Class for creating and managing TimeConverter objects.
Definition timeLord.h:41
Primary Event Queue.
Definition timeVortex.h:32
Performs Unit math in full precision.
Definition unitAlgebra.h:107
Class used to track various performance data during simulation execution.
Definition basicPerf.h:100
Class used to manage files and directories.
Definition filesystem.h:35
Definition perfReporter.h:97
Definition configStatistic.h:143
Definition simulation.h:94
Class to sort the contents of the TimeVortex in preparation for checkpointing.
Definition simulation.h:92