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/oneshot.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/unitAlgebra.h"
27#include "sst/core/util/filesystem.h"
37#include <unordered_map>
41extern int main(
int argc,
char** argv);
47void SST_Exit(
int exit_code);
49#define _SIM_DBG(fmt, args...) __DBG(DBG_SIM, Sim, fmt, ##args)
50#define STATALLFLAG "--ALLSTATS--"
78namespace Serialization {
134 double getRunPhaseElapsedRealTime()
const;
135 double getInitPhaseElapsedRealTime()
const;
136 double getCompletePhaseElapsedRealTime()
const;
148 static Simulation_impl*
getSimulation() {
return instanceMap.at(std::this_thread::get_id()); }
188 void exchangeLinkInfo();
205 void prepare_for_run();
216 bool isIndependentThread() {
return independent; }
218 void printProfilingInfo(FILE* fp);
220 void printPerformanceInfo();
230 const std::vector<SimTime_t>& getInterThreadLatencies()
const {
return interThreadLatencies; }
232 SimTime_t getInterThreadMinLatency()
const {
return interThreadMinLatency; }
234 static TimeConverter getMinPartTC() {
return minPartTC; }
236 LinkMap* getComponentLinkMap(ComponentId_t
id)
const
238 ComponentInfo* info = compInfoMap.getByID(
id);
239 if (
nullptr == info ) {
243 return info->getLinkMap();
255 if (
nullptr != i ) {
256 return i->getComponent();
259 printf(
"Simulation::getComponent() couldn't find component with id = %" PRIu64
"\n",
id);
269 if (
nullptr != i ) {
273 printf(
"Simulation::getComponentInfo() couldn't find component with id = %" PRIu64
"\n",
id);
295 uint64_t getTimeVortexMaxDepth()
const;
297 uint64_t getTimeVortexCurrentDepth()
const;
299 uint64_t getSyncQueueDataSize()
const;
349 friend int ::main(
int argc,
char** argv);
360 std::string initializeCheckpointInfrastructure(
const std::string& prefix);
361 void scheduleCheckpoint();
366 void checkpoint(
const std::string& checkpoint_filename);
378 int checkpoint_id,
const std::string& registry_filename,
const std::string& globals_filename);
379 void restart(
Config* config);
381 void initialize_interactive_console(
const std::string& type);
392 static void resizeBarriers(uint32_t nthr);
399 static std::mutex simulationMutex;
403 static std::map<LinkId_t, Link*> cross_thread_links;
404 bool direct_interthread;
406 Component* createComponent(ComponentId_t
id,
const std::string& name,
Params& params);
408 TimeVortex* getTimeVortex()
const {
return timeVortex; }
427 enum ShutdownMode_t {
433 friend class SyncManager;
435 TimeVortex* timeVortex;
436 std::string timeVortexType;
437 TimeConverter threadMinPartTC;
438 Activity* current_activity;
439 static SimTime_t minPart;
440 static TimeConverter minPartTC;
441 std::vector<SimTime_t> interThreadLatencies;
442 SimTime_t interThreadMinLatency;
443 SyncManager* syncManager;
445 ComponentInfoMap compInfoMap;
449 SimulatorHeartbeat* m_heartbeat =
nullptr;
450 CheckpointAction* checkpoint_action_;
451 static std::string checkpoint_directory_;
454 static std::atomic<int> untimed_msg_count;
455 unsigned int untimed_phase;
456 volatile sig_atomic_t signal_arrived_;
457 ShutdownMode_t shutdown_mode_;
458 bool wireUpFinished_;
459 RealTimeManager* real_time_;
460 std::string interactive_type_ =
"";
461 std::string interactive_start_ =
"";
462 InteractiveConsole* interactive_ =
nullptr;
463 bool enter_interactive_ =
false;
464 std::string interactive_msg_;
484 std::map<std::string, SST::Profile::ProfileTool*> profile_tools;
486 std::map<std::string, std::vector<std::string>> profiler_map;
488 template <
typename T>
489 std::vector<T*> getProfileTool(std::string point)
493 std::vector<std::string>& profilers = profiler_map.at(point);
495 for (
auto& x : profilers ) {
499 T* tool =
dynamic_cast<T*
>(val);
502 Output::getDefaultObject().fatal(CALL_INFO_LONG, 1,
503 "ERROR: wrong type of profiling tool found (name = %s). Check to make sure the profiling "
504 "points enabled for this tool accept the type specified\n",
509 catch ( std::out_of_range& e ) {
512 Output::getDefaultObject().fatal(CALL_INFO_LONG, 1,
513 "INTERNAL ERROR: ProfileTool refered to in profiler_map not found in profile_tools map\n");
518 catch ( std::out_of_range& e ) {
528#if SST_PERFORMANCE_INSTRUMENTING
532#if SST_PERIODIC_PRINT
533 uint64_t periodicCounter = 0;
536#if SST_RUNTIME_PROFILING
537 uint64_t sumtime = 0;
538 uint64_t runtime = 0;
539 struct timeval start, end, diff;
540 struct timeval sumstart, sumend, sumdiff;
544#if SST_EVENT_PROFILING
545 uint64_t rankLatency = 0;
546 uint64_t messageXferSize = 0;
548 uint64_t rankExchangeBytes = 0;
549 uint64_t rankExchangeEvents = 0;
550 uint64_t rankExchangeCounter = 0;
554 void incrementSerialCounters(uint64_t count);
555 void incrementExchangeCounters(uint64_t events, uint64_t bytes);
559#if SST_SYNC_PROFILING
560 uint64_t rankSyncCounter = 0;
561 uint64_t rankSyncTime = 0;
562 uint64_t threadSyncCounter = 0;
563 uint64_t threadSyncTime = 0;
565 void incrementSyncTime(
bool rankSync, uint64_t count);
568#if SST_HIGH_RESOLUTION_CLOCK
569 uint64_t clockDivisor = 1e9;
570 std::string clockResolution =
"ns";
572 uint64_t clockDivisor = 1e6;
573 std::string clockResolution =
"us";
577 SimulationRunMode runMode;
580 SimTime_t currentSimCycle;
582 SimTime_t endSimCycle;
588 std::string output_directory;
590 double run_phase_start_time_;
591 double run_phase_total_time_;
592 double init_phase_start_time_;
593 double init_phase_total_time_;
594 double complete_phase_start_time_;
595 double complete_phase_total_time_;
597 static std::unordered_map<std::thread::id, Simulation_impl*> instanceMap;
598 static std::vector<Simulation_impl*> instanceVec_;
601 std::map<uintptr_t, Link*> link_restart_tracking;
602 std::map<uintptr_t, uintptr_t> event_handler_restart_tracking;
603 uint32_t checkpoint_id_ = 0;
604 std::string checkpoint_prefix_ =
"";
605 std::string globalOutputFileName =
"";
607 void printSimulationState();
609 friend void wait_my_turn_start();
610 friend void wait_my_turn_end();
617 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:46
Main component object for the simulation.
Definition baseComponent.h:62
A recurring event to trigger checkpoint generation.
Definition checkpointAction.h:63
A Clock class.
Definition clock.h:34
SSTHandlerBase< bool, Cycle_t > HandlerBase
Base handler for clock functions.
Definition clock.h:43
Definition componentInfo.h:282
Definition componentInfo.h:42
Main component object for the simulation.
Definition component.h:31
A Configuration Graph A graph representing Components and Links.
Definition configGraph.h:450
Class to contain SST Simulation Configuration variables.
Definition config.h:41
Base class for objects created by the serializer mapping mode used to map the variables for objects.
Definition objectMap.h:112
Definition threadsafe.h:46
Definition threadsafe.h:132
Exit Event Action.
Definition exit.h:36
Class for instantiating Components, Links and the like out of element libraries.
Definition factory.h:48
Definition interactiveConsole.h:46
Maps port names to the Links that are connected to it.
Definition linkMap.h:29
Link between two components.
Definition link.h:55
A OneShot Event class.
Definition oneshot.h:36
SSTHandlerBaseNoArgs< void > HandlerBase
Base handler for OneShot callbacks.
Definition oneshot.h:41
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition output.h:54
Parameter store.
Definition params.h:58
Class to manage real-time events (signals and alarms)
Definition realtime.h:170
Main control class for a SST Simulation.
Definition simulation_impl.h:87
void setOutputDirectory(const std::string &outDir)
Set the output directory for this simulation.
Definition simulation_impl.h:282
void setup()
Perform the setup() and run phases of the simulation.
Definition simulation.cc:769
SimulationRunMode getSimulationMode() const
Get the run mode of the simulation (e.g.
Definition simulation_impl.h:94
static Output sim_output
Output.
Definition simulation_impl.h:474
UnitAlgebra getElapsedSimTime() const
Return the elapsed simulation time as a time.
Definition simulation.cc:83
static void notifySignal()
Sets an internal flag for signaling the simulation.
Definition simulation.cc:1068
Exit * getExit() const
Return the exit event.
Definition simulation_impl.h:176
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:994
bool parseSignalString(std::string &arg, std::string &name, Params ¶ms)
Helper for signal string parsing.
Definition simulation.cc:318
void checkpoint_write_globals(int checkpoint_id, 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:1572
static Simulation_impl * createSimulation(Config *config, RankInfo my_rank, RankInfo num_ranks, bool restart)
Create new simulation.
Definition simulation.cc:156
void insertActivity(SimTime_t time, Activity *ev)
Insert an activity to fire at a specified time.
Definition simulation.cc:1288
SimTime_t getCurrentSimCycle() const
Return the current simulation time as a cycle count.
Definition simulation.cc:65
SST::Statistics::StatisticProcessingEngine stat_engine
Statistics Engine.
Definition simulation_impl.h:478
static Factory * factory
Factory used to generate the simulation components.
Definition simulation_impl.h:384
void initialize()
Perform the init() phase of simulation.
Definition simulation.cc:686
Cycle_t getNextClockCycle(TimeConverter *tc, int priority=CLOCKPRIORITY)
Returns the next Cycle that the TimeConverter would fire.
Definition simulation.cc:1218
ComponentInfo * getComponentInfo(const ComponentId_t &id) const
returns the ComponentInfo object for the given ID
Definition simulation_impl.h:265
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:401
BaseComponent * getComponent(const ComponentId_t &id) const
returns the component with the given ID
Definition simulation_impl.h:251
void endSimulation()
Normal Shutdown.
Definition simulation.cc:1008
static Simulation_impl * getSimulation()
Return a pointer to the singleton instance of the Simulation.
Definition simulation_impl.h:148
Cycle_t reregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Reactivate an existing clock and handler.
Definition simulation.cc:1194
UnitAlgebra getEndSimTime() const
Return the end simulation time as a time.
Definition simulation.cc:89
bool isWireUpFinished()
Returns true when the Wireup is finished.
Definition simulation_impl.h:293
void printStatus(bool fullStatus)
Causes the current status of the simulation to be printed to stderr.
Definition simulation.cc:1074
std::map< std::pair< SimTime_t, int >, Clock * > clockMap_t
Definition simulation_impl.h:140
void setupSimActions(Config *cfg, bool restart=false)
Setup external control actions (forced stops, signal handling.
Definition simulation.cc:249
SimTime_t getEndSimCycle() const
Return the end simulation time as a cycle count.
Definition simulation.cc:71
static Output & getSimulationOutput()
Return the base simulation Output class instance.
Definition simulation_impl.h:154
void complete()
Perform the complete() phase of simulation.
Definition simulation.cc:734
RankInfo getRank() const
Get this instance's parallel rank.
Definition simulation_impl.h:112
RankInfo getNumRanks() const
Get the number of parallel ranks in the simulation.
Definition simulation_impl.h:115
TimeConverter * registerClock(const std::string &freq, Clock::HandlerBase *handler, int priority)
Register a handler to be called on a set frequency.
Definition simulation.cc:1125
SimTime_t getClockForHandler(Clock::HandlerBase *handler)
Gets the clock the handler is registered with, represented by it's factor.
Definition simulation.cc:1230
void checkpoint_append_registry(const std::string ®istry_name, const std::string &blob_name)
Append partitions registry information.
Definition simulation.cc:1658
std::map< std::pair< SimTime_t, int >, OneShot * > oneShotMap_t
Definition simulation_impl.h:141
static TimeLord timeLord
TimeLord of the simulation.
Definition simulation_impl.h:472
static SimTime_t getLocalMinimumNextActivityTime()
Gets the minimum next activity time across all TimeVortices in the Rank.
Definition simulation.cc:388
Statistics::StatisticProcessingEngine * getStatisticsProcessingEngine()
Return the Statistic Processing Engine associated with this Simulation.
Definition simulation.cc:1313
static void shutdown()
Used to signify the end of simulation.
Definition simulation.cc:171
static TimeLord * getTimeLord()
Return the TimeLord associated with this Simulation.
Definition simulation_impl.h:151
void initializeProfileTools(const std::string &config)
Performance Tracking Information.
Definition simulation.cc:1389
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:1262
void requireLibrary(const std::string &name)
Signifies that a library is required for this simulation.
Definition simulation.cc:376
void unregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Remove a clock handler from the list of active clock handlers.
Definition simulation.cc:1252
TimeConverter minPartToTC(SimTime_t cycles) const
Get a handle to a TimeConverter.
Definition simulation.cc:97
CheckpointAction * getCheckpointAction() const
Return the checkpoint event.
Definition simulation_impl.h:302
std::string & getOutputDirectory()
Returns the output directory of the simulation.
Definition simulation_impl.h:121
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_impl.h:390
std::vector< std::pair< ComponentId_t, uint64_t > > component_blob_offsets_
vector to hold offsets of component blobs in checkpoint files
Definition simulation_impl.h:469
static void emergencyShutdown()
Emergency Shutdown Called when a fatal event has occurred.
Definition simulation.cc:978
void adjustTimeAtSimEnd()
Adjust clocks and time to reflect precise simulation end time which may differ in parallel simulation...
Definition simulation.cc:1030
void checkpoint(const std::string &checkpoint_filename)
Write the partition specific checkpoint data.
Definition simulation.cc:1680
const ComponentInfoMap & getComponentInfoMap() const
Returns reference to the Component Info Map.
Definition simulation_impl.h:248
int getCurrentPriority() const
Return the current priority.
Definition simulation.cc:77
An optional heartbeat to show progress in a simulation.
Definition heartbeat.h:33
Forms the base class for statistics output generation within the SST core.
Definition statoutput.h:52
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition statengine.h:58
Definition syncManager.h:138
Definition syncManager.h:95
A class to convert between a component's view of time and the core's view of time.
Definition timeConverter.h:28
Class for creating and managing TimeConverter objects.
Definition timeLord.h:40
Primary Event Queue.
Definition timeVortex.h:30
Performs Unit math in full precision.
Definition unitAlgebra.h:107
Class used to manage files and directories.
Definition filesystem.h:33