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/unitAlgebra.h" 27 #include "sst/core/util/basicPerf.h" 28 #include "sst/core/util/filesystem.h" 40 #include <unordered_map> 45 extern int main(
int argc,
char** argv);
51 void SST_Exit(
int exit_code);
53 #define _SIM_DBG(fmt, args...) __DBG(DBG_SIM, Sim, fmt, ##args) 54 #define STATALLFLAG "--ALLSTATS--" 57 class CheckpointAction;
63 class InteractiveConsole;
67 class RealTimeManager;
68 class SimulatorHeartbeat;
77 namespace Statistics {
78 class StatisticOutput;
79 class StatisticProcessingEngine;
82 namespace Serialization {
100 std::vector<Activity*> data;
102 using iterator = std::vector<Activity*>::iterator;
105 iterator action_start;
111 std::pair<iterator, iterator> getEventsForHandler(uintptr_t handler);
113 std::pair<iterator, iterator> getActions();
170 double getRunPhaseElapsedRealTime()
const;
171 double getInitPhaseElapsedRealTime()
const;
172 double getCompletePhaseElapsedRealTime()
const;
198 RankInfo my_rank,
RankInfo num_ranks,
bool restart, SimTime_t currentSimCycle,
int currentPriority);
223 int initializeStatisticEngine(
StatsConfig* stats_config);
226 void exchangeLinkInfo();
243 void prepare_for_run();
254 bool isIndependentThread() {
return independent; }
256 void printProfilingInfo(FILE* fp);
258 void printPerformanceInfo();
272 SimTime_t getInterThreadMinLatency()
const {
return interThreadMinLatency; }
274 static TimeConverter getMinPartTC() {
return minPartTC; }
276 LinkMap* getComponentLinkMap(ComponentId_t
id)
const 278 ComponentInfo* info = compInfoMap.getByID(
id);
279 if (
nullptr == info ) {
283 return info->getLinkMap();
294 if (
nullptr != i ) {
295 return i->getComponent();
298 printf(
"Simulation::getComponent() couldn't find component with id = %" PRIu64
"\n",
id);
307 if (
nullptr != i ) {
311 printf(
"Simulation::getComponentInfo() couldn't find component with id = %" PRIu64
"\n",
id);
333 uint64_t getTimeVortexMaxDepth()
const;
335 uint64_t getTimeVortexCurrentDepth()
const;
337 uint64_t getSyncQueueDataSize()
const;
343 std::pair<pvt::TimeVortexSort::iterator, pvt::TimeVortexSort::iterator> getEventsForHandler(uintptr_t handler);
359 void reportClock(SimTime_t factor,
int priority);
393 friend int ::main(
int argc,
char** argv);
404 std::string initializeCheckpointInfrastructure(
const std::string& prefix);
405 void scheduleCheckpoint();
410 void checkpoint(
const std::string& checkpoint_filename);
422 const std::string& registry_filename,
const std::string& globals_filename);
433 if ( serial_restart_ )
return RankInfo(0, 0);
434 return RankInfo(rank.rank, rank.thread);
437 void initialize_interactive_console(
const std::string& type);
448 static void resizeBarriers(uint32_t nthr);
455 static std::mutex simulationMutex;
461 static std::map<LinkId_t, Link*> cross_thread_links;
462 bool direct_interthread;
464 Component* createComponent(ComponentId_t
id,
const std::string& name,
Params& params);
466 TimeVortex* getTimeVortex()
const {
return timeVortex; }
485 enum ShutdownMode_t {
491 friend class SyncManager;
493 TimeVortex* timeVortex =
nullptr;
494 std::string timeVortexType;
495 TimeConverter threadMinPartTC;
496 Activity* current_activity;
497 static SimTime_t minPart;
498 static TimeConverter minPartTC;
499 std::vector<SimTime_t> interThreadLatencies;
500 SimTime_t interThreadMinLatency = MAX_SIMTIME_T;
501 SyncManager* syncManager;
502 ComponentInfoMap compInfoMap;
505 SimulatorHeartbeat* m_heartbeat =
nullptr;
506 CheckpointAction* checkpoint_action_;
507 static std::string checkpoint_directory_;
510 static std::atomic<int> untimed_msg_count;
511 unsigned int untimed_phase;
512 volatile sig_atomic_t signal_arrived_;
513 ShutdownMode_t shutdown_mode_;
514 bool wireUpFinished_;
515 RealTimeManager* real_time_;
516 std::string interactive_type_ =
"";
517 std::string interactive_start_ =
"";
518 std::string replay_file_ =
"";
519 InteractiveConsole* interactive_ =
nullptr;
520 bool enter_interactive_ =
false;
521 std::string interactive_msg_;
522 SimTime_t stop_at_ = 0;
525 Core::OneShotManager one_shot_manager_;
547 std::map<std::string, SST::Profile::ProfileTool*> profile_tools;
549 std::map<std::string, std::vector<std::string>> profiler_map;
551 template <
typename T>
552 std::vector<T*> getProfileTool(std::string point)
556 std::vector<std::string>& profilers = profiler_map.at(point);
558 for (
auto& x : profilers ) {
562 T* tool =
dynamic_cast<T*
>(val);
565 Output::getDefaultObject().fatal(CALL_INFO_LONG, 1,
566 "ERROR: wrong type of profiling tool found (name = %s). Check to make sure the profiling " 567 "points enabled for this tool accept the type specified\n",
572 catch ( std::out_of_range& e ) {
575 Output::getDefaultObject().fatal(CALL_INFO_LONG, 1,
576 "INTERNAL ERROR: ProfileTool refered to in profiler_map not found in profile_tools map\n");
581 catch ( std::out_of_range& e ) {
591 #if SST_PERFORMANCE_INSTRUMENTING 595 #if SST_PERIODIC_PRINT 596 uint64_t periodicCounter = 0;
599 #if SST_RUNTIME_PROFILING 600 uint64_t sumtime = 0;
601 uint64_t runtime = 0;
602 struct timeval start, end, diff;
603 struct timeval sumstart, sumend, sumdiff;
607 #if SST_EVENT_PROFILING 608 uint64_t rankLatency = 0;
609 uint64_t messageXferSize = 0;
611 uint64_t rankExchangeBytes = 0;
612 uint64_t rankExchangeEvents = 0;
613 uint64_t rankExchangeCounter = 0;
617 void incrementSerialCounters(uint64_t count);
618 void incrementExchangeCounters(uint64_t events, uint64_t bytes);
622 #if SST_SYNC_PROFILING 623 uint64_t rankSyncCounter = 0;
624 uint64_t rankSyncTime = 0;
625 uint64_t threadSyncCounter = 0;
626 uint64_t threadSyncTime = 0;
628 void incrementSyncTime(
bool rankSync, uint64_t count);
631 #if SST_HIGH_RESOLUTION_CLOCK 632 uint64_t clockDivisor = 1e9;
633 std::string clockResolution =
"ns";
635 uint64_t clockDivisor = 1e6;
636 std::string clockResolution =
"us";
640 SimulationRunMode runMode;
643 SimTime_t currentSimCycle = 0;
644 int currentPriority = 0;
645 SimTime_t endSimCycle = 0;
651 std::string output_directory;
653 double run_phase_start_time_;
654 double run_phase_total_time_;
655 double init_phase_start_time_;
656 double init_phase_total_time_;
657 double complete_phase_start_time_;
658 double complete_phase_total_time_;
660 static std::unordered_map<std::thread::id, Simulation_impl*> instanceMap;
661 static std::vector<Simulation_impl*> instanceVec_;
664 std::map<std::pair<int, uintptr_t>, Link*> link_restart_tracking;
665 std::map<uintptr_t, uintptr_t> event_handler_restart_tracking;
666 uint32_t checkpoint_id_ = 0;
667 std::string checkpoint_prefix_ =
"";
668 std::string globalOutputFileName =
"";
669 bool serial_restart_ =
false;
672 static Config config;
673 static StatsConfig* stats_config_;
675 void printSimulationState();
677 friend void wait_my_turn_start();
678 friend void wait_my_turn_end();
685 SimTime_t getNextActivityTime()
const;
693 void wait_my_turn_start(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
695 void wait_my_turn_end(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
699 #endif // SST_CORE_SIMULATION_IMPL_H Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:57
Statistics::StatisticProcessingEngine * getStatisticsProcessingEngine()
Return the Statistic Processing Engine associated with this Simulation.
Definition: simulation.cc:1428
void printStatus(bool fullStatus)
Causes the current status of the simulation to be printed to stderr.
Definition: simulation.cc:1204
An Action is a schedulable Activity which is not an Event.
Definition: action.h:26
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
RankInfo getRankForLinkOnRestart(RankInfo rank, uintptr_t UNUSED(tag))
Function used to get the rank for a link on restart.
Definition: simulation_impl.h:431
Base template for handlers which take a class defined argument.
Definition: ssthandler.h:109
TimeConverter minPartToTC(SimTime_t cycles) const
Get a handle to a TimeConverter.
Definition: simulation.cc:187
RankInfo getNumRanks() const
Get the number of parallel ranks in the simulation.
Definition: simulation_impl.h:151
Definition: simulation_impl.h:95
Base class for all Activities in the SST Event Queue.
Definition: activity.h:47
static TimeLord * getTimeLord()
Return the TimeLord associated with this Simulation.
Definition: simulation_impl.h:187
void insertActivity(SimTime_t time, Activity *ev)
Insert an activity to fire at a specified time.
Definition: simulation.cc:1403
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:27
Main component object for the simulation.
Definition: component.h:30
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:585
Primary Event Queue.
Definition: timeVortex.h:31
UnitAlgebra getElapsedSimTime() const
Return the elapsed simulation time as a time.
Definition: simulation.cc:173
static Output sim_output
Output.
Definition: simulation_impl.h:537
A recurring event to trigger checkpoint generation.
Definition: checkpointAction.h:62
Definition: configGraph.h:568
CheckpointAction * getCheckpointAction() const
Return the checkpoint event.
Definition: simulation_impl.h:340
const ComponentInfoMap & getComponentInfoMap() const
Returns reference to the Component Info Map.
Definition: simulation_impl.h:288
bool isWireUpFinished()
Returns true when the Wireup is finished.
Definition: simulation_impl.h:331
void setOutputDirectory(const std::string &outDir)
Set the output directory for this simulation
Definition: simulation_impl.h:320
static Output & getSimulationOutput()
Return the base simulation Output class instance.
Definition: simulation_impl.h:190
static void notifySignal()
Sets an internal flag for signaling the simulation.
Definition: simulation.cc:1192
void setup()
Perform the setup() and run phases of the simulation.
Definition: simulation.cc:885
SimTime_t getCurrentSimCycle() const
Return the current simulation time as a cycle count.
Definition: simulation.cc:155
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:1694
SST::Statistics::StatisticProcessingEngine stat_engine
Statistics Engine.
Definition: simulation_impl.h:541
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:446
Base class for objects created by the serializer mapping mode used to map the variables for objects...
Definition: objectMap.h:158
void initialize()
Perform the init() phase of simulation.
Definition: simulation.cc:802
SimTime_t getClockForHandler(Clock::HandlerBase *handler)
Gets the clock the handler is registered with, represented by it's factor.
Definition: simulation.cc:1370
Exit Action.
Definition: exit.h:33
Definition: componentInfo.h:284
RankInfo getRank() const
Get this instance's parallel rank.
Definition: simulation_impl.h:148
Exit * getExit() const
Return the exit event.
Definition: simulation_impl.h:216
A Clock class.
Definition: clock.h:33
BaseComponent * getComponent(const ComponentId_t &id) const
returns the component with the given ID
Definition: simulation_impl.h:291
Cycle_t reregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Reactivate an existing clock and handler.
Definition: simulation.cc:1334
void initializeProfileTools(const std::string &config)
Performance Tracking Information.
Definition: simulation.cc:1511
UnitAlgebra getEndSimTime() const
Return the end simulation time as a time.
Definition: simulation.cc:179
static Simulation_impl * createSimulation(RankInfo my_rank, RankInfo num_ranks, bool restart, SimTime_t currentSimCycle, int currentPriority)
Create new simulation.
Definition: simulation.cc:243
void endSimulation()
Normal Shutdown.
Definition: simulation.cc:1132
static SimTime_t getLocalMinimumNextActivityTime()
Gets the minimum next activity time across all TimeVortices in the Rank.
Definition: simulation.cc:493
SimTime_t getEndSimCycle() const
Return the end simulation time as a cycle count.
Definition: simulation.cc:161
void unregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Remove a clock handler from the list of active clock handlers.
Definition: simulation.cc:1392
ComponentInfo * getComponentInfo(const ComponentId_t &id) const
returns the ComponentInfo object for the given ID
Definition: simulation_impl.h:304
Main control class for a SST Simulation.
Definition: simulation_impl.h:122
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:1118
Definition: rankInfo.h:23
Main component object for the simulation.
Definition: baseComponent.h:64
static Simulation_impl * getSimulation()
Return a pointer to the singleton instance of the Simulation.
Definition: simulation_impl.h:184
void complete()
Perform the complete() phase of simulation.
Definition: simulation.cc:850
static Factory * factory
Factory used to generate the simulation components.
Definition: simulation_impl.h:440
Class to sort the contents of the TimeVortex in preparation for checkpointing.
Definition: simulation_impl.h:93
Definition: threadsafe.h:135
Cycle_t getNextClockCycle(TimeConverter *tc, int priority=CLOCKPRIORITY)
Returns the next Cycle that the TimeConverter would fire.
Definition: simulation.cc:1358
void checkpoint(const std::string &checkpoint_filename)
Write the partition specific checkpoint data.
Definition: simulation.cc:1864
void adjustTimeAtSimEnd()
Adjust clocks and time to reflect precise simulation end time which may differ in parallel simulation...
Definition: simulation.cc:1154
static void emergencyShutdown()
Emergency Shutdown Called when a fatal event has occurred.
Definition: simulation.cc:1102
static TimeLord timeLord
TimeLord of the simulation.
Definition: simulation_impl.h:535
Parameter store.
Definition: params.h:63
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:39
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:54
SimulationRunMode getSimulationMode() const
Get the run mode of the simulation (e.g.
Definition: simulation_impl.h:130
std::string & getOutputDirectory()
Returns the output directory of the simulation
Definition: simulation_impl.h:157
TimeConverter * registerClock(const std::string &freq, Clock::HandlerBase *handler, int priority)
Register a handler to be called on a set frequency.
Definition: simulation.cc:1255
Definition: componentInfo.h:44
int getCurrentPriority() const
Return the current priority.
Definition: simulation.cc:167
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:506
void checkpoint_append_registry(const std::string ®istry_name, const std::string &blob_name)
Append partitions registry information.
Definition: simulation.cc:1842
void requireLibrary(const std::string &name)
Signifies that a library is required for this simulation.
Definition: simulation.cc:481
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:54
const std::vector< SimTime_t > & getInterThreadLatencies() const
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_impl.h:270
bool parseSignalString(std::string &arg, std::string &name, Params ¶ms)
Helper for signal string parsing.
Definition: simulation.cc:423
Performs Unit math in full precision.
Definition: unitAlgebra.h:105
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:530
Definition: threadsafe.h:49
Class used to track various performance data during simulation execution.
Definition: basicPerf.h:98
Link between two components.
Definition: link.h:56
Class used to manage files and directories.
Definition: filesystem.h:34
static void shutdown()
Used to signify the end of simulation.
Definition: simulation.cc:264
void setupSimActions()
Setup external control actions (forced stops, signal handling.
Definition: simulation.cc:353
std::map< std::pair< SimTime_t, int >, Clock * > clockMap_t
Definition: simulation_impl.h:176