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 void reportClock(SimTime_t factor,
int priority);
387 friend int ::main(
int argc,
char** argv);
398 static void writeCheckpointConfigGraph(
ConfigGraph* graph);
399 void scheduleCheckpoint();
400 void scheduleInteractiveConsole(
const std::string& msg);
405 void checkpoint(
const std::string& checkpoint_filename);
417 const std::string& registry_filename,
const std::string& globals_filename);
420 void discoverRemoteLinks();
425 std::vector<std::pair<LinkId_t, RankInfo>>* xfer_vec =
nullptr;
427 void discoverRemoteLinksMoveData(
428 std::vector<std::pair<LinkId_t, RankInfo>>& send_vec, std::vector<std::pair<LinkId_t, RankInfo>>& recv_vec);
440 if ( serial_restart_ )
return RankInfo(0, 0);
441 return RankInfo(rank.rank, rank.thread);
444 void initialize_interactive_console(
const std::string& type);
455 static void resizeBarriers(uint32_t nthr);
462 static std::mutex simulationMutex;
468 static std::map<LinkId_t, Link*> cross_thread_links;
469 bool direct_interthread;
471 Component* createComponent(ComponentId_t
id,
const std::string& name,
Params& params);
473 TimeVortex* getTimeVortex()
const {
return timeVortex; }
503 void checkIndependent();
505 enum ShutdownMode_t {
511 friend class SyncManager;
525 TimeVortex* timeVortex =
nullptr;
526 std::string timeVortexType;
527 TimeConverter threadMinPartTC;
528 Activity* current_activity;
529 static SimTime_t minPart;
530 static TimeConverter minPartTC;
531 std::vector<SimTime_t> interThreadLatencies;
532 SimTime_t interThreadMinLatency = MAX_SIMTIME_T;
533 SyncManager* syncManager;
534 ComponentInfoMap compInfoMap;
537 SimulatorHeartbeat* m_heartbeat =
nullptr;
538 CheckpointAction* checkpoint_action_;
539 static std::string checkpoint_directory_;
540 static std::string checkpoint_configgraph_;
543 static std::atomic<int> untimed_msg_count;
544 unsigned int untimed_phase;
545 volatile sig_atomic_t signal_arrived_;
546 ShutdownMode_t shutdown_mode_;
547 bool enter_shutdown_ =
false;
548 bool wireUpFinished_;
549 RealTimeManager* real_time_;
550 std::string interactive_type_ =
"";
551 std::string interactive_start_ =
"";
552 std::string replay_file_ =
"";
553 InteractiveConsole* interactive_ =
nullptr;
554 bool enter_interactive_ =
false;
555 std::string interactive_msg_;
556 SimTime_t stop_at_ = 0;
558 uint32_t next_link_order_tag_ = 1;
589 std::map<std::string, SST::Profile::ProfileTool*> profile_tools;
591 std::map<std::string, std::vector<std::string>> profiler_map;
593 template <
typename T>
594 std::vector<T*> getProfileTool(std::string point)
598 std::vector<std::string>& profilers = profiler_map.at(point);
600 for (
auto& x : profilers ) {
604 T* tool =
dynamic_cast<T*
>(val);
607 Output::getDefaultObject().fatal(CALL_INFO_LONG, 1,
608 "ERROR: wrong type of profiling tool found (name = %s). Check to make sure the profiling "
609 "points enabled for this tool accept the type specified\n",
614 catch (
const std::out_of_range& e ) {
617 Output::getDefaultObject().fatal(CALL_INFO_LONG, 1,
618 "INTERNAL ERROR: ProfileTool refered to in profiler_map not found in profile_tools map\n");
623 catch (
const std::out_of_range& e ) {
633#if SST_PERFORMANCE_INSTRUMENTING
637#if SST_PERIODIC_PRINT
638 uint64_t periodicCounter = 0;
641#if SST_RUNTIME_PROFILING
642 uint64_t sumtime = 0;
643 uint64_t runtime = 0;
644 struct timeval start, end, diff;
645 struct timeval sumstart, sumend, sumdiff;
649#if SST_EVENT_PROFILING
650 uint64_t rankLatency = 0;
651 uint64_t messageXferSize = 0;
653 uint64_t rankExchangeCounter = 0;
657 void incrementSerialCounters(uint64_t count);
661#if SST_HIGH_RESOLUTION_CLOCK
662 uint64_t clockDivisor = 1e9;
663 std::string clockResolution =
"ns";
665 uint64_t clockDivisor = 1e6;
666 std::string clockResolution =
"us";
670 SimulationRunMode runMode;
673 SimTime_t currentSimCycle = 0;
674 int currentPriority = 0;
675 SimTime_t endSimCycle = 0;
681 std::string output_directory;
683 double run_phase_start_time_;
684 double run_phase_total_time_;
685 double init_phase_start_time_;
686 double init_phase_total_time_;
687 double complete_phase_start_time_;
688 double complete_phase_total_time_;
690 static std::unordered_map<std::thread::id, Simulation*> instanceMap;
691 static std::vector<Simulation*> instanceVec_;
694 std::map<LinkId_t, Link*> link_restart_tracking;
695 std::map<uintptr_t, uintptr_t> event_handler_restart_tracking;
696 uint32_t checkpoint_id_ = 0;
697 std::string checkpoint_prefix_ =
"";
698 std::string globalOutputFileName =
"";
699 std::string version_ =
"";
700 std::string arch_ =
"";
701 std::string os_ =
"";
702 bool serial_restart_ =
false;
705 static Config config;
706 static StatsConfig* stats_config_;
708 void printSimulationState();
710 friend void wait_my_turn_start();
711 friend void wait_my_turn_end();
718 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:67
A recurring event to trigger checkpoint generation.
Definition checkpointAction.h:69
A Clock class.
Definition clock.h:35
SSTHandlerBase< bool, Cycle_t > HandlerBase
Base handler for clock functions.
Definition clock.h:44
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:188
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:46
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:1452
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:453
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:579
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:1440
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:1800
std::vector< std::pair< ComponentId_t, uint64_t > > component_blob_offsets_
vector to hold offsets of component blobs in checkpoint files
Definition simulation.h:572
SST::Statistics::StatisticProcessingEngine stat_engine
Statistics Engine.
Definition simulation.h:583
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:1487
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:1476
static Factory * factory
Factory used to generate the simulation components.
Definition simulation.h:447
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:1464
uint32_t getNextLinkOrderTag()
Gets the next value for the order field of the link.
Definition simulation.h:564
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:1980
static TimeLord timeLord
TimeLord of the simulation.
Definition simulation.h:577
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
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:1572
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:1512
void checkpoint_append_registry(const std::string ®istry_name, const std::string &blob_name)
Append partitions registry information.
Definition simulation.cc:1958
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:438
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