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/sst_types.h" 24 #include "sst/core/statapi/statengine.h" 25 #include "sst/core/unitAlgebra.h" 32 #include <unordered_map> 35 extern int main(
int argc,
char** argv);
39 #define _SIM_DBG(fmt, args...) __DBG(DBG_SIM, Sim, fmt, ##args) 40 #define STATALLFLAG "--ALLSTATS--" 43 class CheckpointAction;
49 class InteractiveConsole;
53 class RealTimeManager;
54 class SimulatorHeartbeat;
63 namespace Statistics {
64 class StatisticOutput;
65 class StatisticProcessingEngine;
68 namespace Serialization {
124 double getRunPhaseElapsedRealTime()
const;
125 double getInitPhaseElapsedRealTime()
const;
126 double getCompletePhaseElapsedRealTime()
const;
178 void exchangeLinkInfo();
195 void prepare_for_run();
206 bool isIndependentThread() {
return independent; }
208 void printProfilingInfo(FILE* fp);
210 void printPerformanceInfo();
220 const std::vector<SimTime_t>& getInterThreadLatencies()
const {
return interThreadLatencies; }
222 SimTime_t getInterThreadMinLatency()
const {
return interThreadMinLatency; }
224 static TimeConverter* getMinPartTC() {
return minPartTC; }
226 LinkMap* getComponentLinkMap(ComponentId_t
id)
const 228 ComponentInfo* info = compInfoMap.getByID(
id);
229 if (
nullptr == info ) {
return nullptr; }
231 return info->getLinkMap();
243 if (
nullptr != i ) {
return i->getComponent(); }
245 printf(
"Simulation::getComponent() couldn't find component with id = %" PRIu64
"\n",
id);
255 if (
nullptr != i ) {
return i; }
257 printf(
"Simulation::getComponentInfo() couldn't find component with id = %" PRIu64
"\n",
id);
279 uint64_t getTimeVortexMaxDepth()
const;
281 uint64_t getTimeVortexCurrentDepth()
const;
283 uint64_t getSyncQueueDataSize()
const;
329 friend int ::main(
int argc,
char** argv);
332 Simulation_impl(Config* config, RankInfo my_rank, RankInfo num_ranks,
bool restart);
333 Simulation_impl(Simulation_impl
const&);
334 void operator=(Simulation_impl
const&);
339 TimeConverter*
minPartToTC(SimTime_t cycles)
const;
341 std::string initializeCheckpointInfrastructure(
const std::string& prefix);
342 void scheduleCheckpoint();
347 void checkpoint(
const std::string& checkpoint_filename);
359 int checkpoint_id,
const std::string& registry_filename,
const std::string& globals_filename);
360 void restart(Config* config);
362 void initialize_interactive_console(
const std::string& type);
367 static void resizeBarriers(uint32_t nthr);
374 static std::mutex simulationMutex;
378 static std::map<LinkId_t, Link*> cross_thread_links;
379 bool direct_interthread;
381 Component* createComponent(ComponentId_t
id,
const std::string& name,
Params& params);
383 TimeVortex* getTimeVortex()
const {
return timeVortex; }
408 friend class SyncManager;
410 TimeVortex* timeVortex;
411 std::string timeVortexType;
412 TimeConverter* threadMinPartTC;
413 Activity* current_activity;
414 static SimTime_t minPart;
415 static TimeConverter* minPartTC;
416 std::vector<SimTime_t> interThreadLatencies;
417 SimTime_t interThreadMinLatency;
418 SyncManager* syncManager;
420 ComponentInfoMap compInfoMap;
424 SimulatorHeartbeat* m_heartbeat =
nullptr;
425 CheckpointAction* checkpoint_action_;
426 static std::string checkpoint_directory_;
429 static std::atomic<int> untimed_msg_count;
430 unsigned int untimed_phase;
431 volatile sig_atomic_t signal_arrived_;
432 ShutdownMode_t shutdown_mode_;
433 bool wireUpFinished_;
434 RealTimeManager* real_time_;
435 std::string interactive_type_ =
"";
436 std::string interactive_start_ =
"";
437 InteractiveConsole* interactive_ =
nullptr;
438 bool enter_interactive_ =
false;
439 std::string interactive_msg_;
459 std::map<std::string, SST::Profile::ProfileTool*> profile_tools;
461 std::map<std::string, std::vector<std::string>> profiler_map;
463 template <
typename T>
464 std::vector<T*> getProfileTool(std::string point)
468 std::vector<std::string>& profilers = profiler_map.at(point);
470 for (
auto& x : profilers ) {
474 T* tool =
dynamic_cast<T*
>(val);
477 Output::getDefaultObject().fatal(
479 "ERROR: wrong type of profiling tool found (name = %s). Check to make sure the profiling " 480 "points enabled for this tool accept the type specified\n",
485 catch ( std::out_of_range& e ) {
488 Output::getDefaultObject().fatal(
490 "INTERNAL ERROR: ProfileTool refered to in profiler_map not found in profile_tools map\n");
495 catch ( std::out_of_range& e ) {
505 #if SST_PERFORMANCE_INSTRUMENTING 509 #if SST_PERIODIC_PRINT 510 uint64_t periodicCounter = 0;
513 #if SST_RUNTIME_PROFILING 514 uint64_t sumtime = 0;
515 uint64_t runtime = 0;
516 struct timeval start, end, diff;
517 struct timeval sumstart, sumend, sumdiff;
521 #if SST_EVENT_PROFILING 522 uint64_t rankLatency = 0;
523 uint64_t messageXferSize = 0;
525 uint64_t rankExchangeBytes = 0;
526 uint64_t rankExchangeEvents = 0;
527 uint64_t rankExchangeCounter = 0;
531 void incrementSerialCounters(uint64_t count);
532 void incrementExchangeCounters(uint64_t events, uint64_t bytes);
536 #if SST_SYNC_PROFILING 537 uint64_t rankSyncCounter = 0;
538 uint64_t rankSyncTime = 0;
539 uint64_t threadSyncCounter = 0;
540 uint64_t threadSyncTime = 0;
542 void incrementSyncTime(
bool rankSync, uint64_t count);
545 #if SST_HIGH_RESOLUTION_CLOCK 546 uint64_t clockDivisor = 1e9;
547 std::string clockResolution =
"ns";
549 uint64_t clockDivisor = 1e6;
550 std::string clockResolution =
"us";
554 SimulationRunMode runMode;
557 SimTime_t currentSimCycle;
559 SimTime_t endSimCycle;
565 std::string output_directory;
567 double run_phase_start_time_;
568 double run_phase_total_time_;
569 double init_phase_start_time_;
570 double init_phase_total_time_;
571 double complete_phase_start_time_;
572 double complete_phase_total_time_;
574 static std::unordered_map<std::thread::id, Simulation_impl*> instanceMap;
575 static std::vector<Simulation_impl*> instanceVec_;
578 std::map<uintptr_t, Link*> link_restart_tracking;
579 std::map<uintptr_t, uintptr_t> event_handler_restart_tracking;
580 uint32_t checkpoint_id_ = 0;
581 std::string checkpoint_prefix_ =
"";
582 std::string globalOutputFileName =
"";
584 void printSimulationState();
586 friend void wait_my_turn_start();
587 friend void wait_my_turn_end();
594 SimTime_t getNextActivityTime()
const;
602 void wait_my_turn_start(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
604 void wait_my_turn_end(Core::ThreadSafe::Barrier& barrier,
int thread,
int total_threads);
608 #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:53
void printStatus(bool fullStatus)
Causes the current status of the simulation to be printed to stderr.
Definition: simulation.cc:1047
An Action is a schedulable Activity which is not an Event.
Definition: action.h:26
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:210
RankInfo getNumRanks() const
Get the number of parallel ranks in the simulation.
Definition: simulation_impl.h:105
Base class for all Activities in the SST Event Queue.
Definition: activity.h:46
Class to contain SST Simulation Configuration variables.
Definition: config.h:38
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, and will always callback after the timedelay.
Definition: simulation.cc:1177
void insertActivity(SimTime_t time, Activity *ev)
Insert an activity to fire at a specified time.
Definition: simulation.cc:1203
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:389
Primary Event Queue.
Definition: timeVortex.h:27
UnitAlgebra getElapsedSimTime() const
Return the elapsed simulation time as a time.
Definition: simulation.cc:82
static Output sim_output
Output.
Definition: simulation_impl.h:449
A recurring event to trigger checkpoint generation.
Definition: checkpointAction.h:60
CheckpointAction * getCheckpointAction() const
Return the checkpoint event.
Definition: simulation_impl.h:286
bool isWireUpFinished()
Returns true when the Wireup is finished.
Definition: simulation_impl.h:277
void setOutputDirectory(const std::string &outDir)
Set the output directory for this simulation
Definition: simulation_impl.h:266
static Output & getSimulationOutput()
Return the base simulation Output class instance.
Definition: simulation_impl.h:144
static void notifySignal()
Sets an internal flag for signaling the simulation.
Definition: simulation.cc:1041
void setup()
Perform the setup() and run phases of the simulation.
Definition: simulation.cc:748
SimTime_t getCurrentSimCycle() const
Return the current simulation time as a cycle count.
Definition: simulation.cc:64
const ComponentInfoMap & getComponentInfoMap(void)
Returns reference to the Component Info Map.
Definition: simulation_impl.h:236
SST::Statistics::StatisticProcessingEngine stat_engine
Statistics Engine.
Definition: simulation_impl.h:453
Class created by the serializer mapping mode used to map the variables for objects.
Definition: objectMap.h:61
void initialize()
Perform the init() phase of simulation.
Definition: simulation.cc:669
TimeConverter * minPartToTC(SimTime_t cycles) const
Get a handle to a TimeConverter.
Definition: simulation.cc:96
SSTHandlerBaseNoArgs< void > HandlerBase
Base handler for OneShot callbacks.
Definition: oneshot.h:38
SimTime_t getClockForHandler(Clock::HandlerBase *handler)
Gets the clock the handler is registered with, represented by it's factor.
Definition: simulation.cc:1157
Exit Event Action.
Definition: exit.h:34
Definition: componentInfo.h:285
RankInfo getRank() const
Get this instance's parallel rank.
Definition: simulation_impl.h:102
Exit * getExit() const
Return the exit event.
Definition: simulation_impl.h:166
A Clock class.
Definition: clock.h:32
BaseComponent * getComponent(const ComponentId_t &id) const
returns the component with the given ID
Definition: simulation_impl.h:239
Cycle_t reregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Reactivate an existing clock and handler.
Definition: simulation.cc:1133
void initializeProfileTools(const std::string &config)
Performance Tracking Information.
Definition: simulation.cc:1304
UnitAlgebra getEndSimTime() const
Return the end simulation time as a time.
Definition: simulation.cc:88
static TimeLord * getTimeLord(void)
Return the TimeLord associated with this Simulation.
Definition: simulation_impl.h:141
std::map< std::pair< SimTime_t, int >, OneShot * > oneShotMap_t
Definition: simulation_impl.h:131
static SimTime_t getLocalMinimumNextActivityTime()
Gets the minimum next activity time across all TimeVortices in the Rank.
Definition: simulation.cc:383
SimTime_t getEndSimCycle() const
Return the end simulation time as a cycle count.
Definition: simulation.cc:70
void unregisterClock(TimeConverter *tc, Clock::HandlerBase *handler, int priority)
Remove a clock handler from the list of active clock handlers.
Definition: simulation.cc:1167
ComponentInfo * getComponentInfo(const ComponentId_t &id) const
returns the ComponentInfo object for the given ID
Definition: simulation_impl.h:251
Main control class for a SST Simulation.
Definition: simulation_impl.h:76
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:969
Definition: rankInfo.h:21
Main component object for the simulation.
Definition: baseComponent.h:62
static Simulation_impl * getSimulation()
Return a pointer to the singleton instance of the Simulation.
Definition: simulation_impl.h:138
void complete()
Perform the complete() phase of simulation.
Definition: simulation.cc:713
static Factory * factory
Factory used to generate the simulation components.
Definition: simulation_impl.h:365
Definition: threadsafe.h:121
Cycle_t getNextClockCycle(TimeConverter *tc, int priority=CLOCKPRIORITY)
Returns the next Cycle that the TImeConverter would fire.
Definition: simulation.cc:1145
void setupSimActions(Config *cfg, bool restart=false)
Setup external control actions (forced stops, signal handling.
Definition: simulation.cc:246
A OneShot Event class.
Definition: oneshot.h:32
void checkpoint(const std::string &checkpoint_filename)
Write the partition specific checkpoint data.
Definition: simulation.cc:1592
void adjustTimeAtSimEnd()
Adjust clocks and time to reflect precise simulation end time which may differ in parallel simulation...
Definition: simulation.cc:1003
static void emergencyShutdown()
Emergency Shutdown Called when a fatal event has occurred.
Definition: simulation.cc:953
static TimeLord timeLord
TimeLord of the simulation.
Definition: simulation_impl.h:447
Parameter store.
Definition: params.h:55
void endSimulation(void)
Normal Shutdown.
Definition: simulation.cc:981
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:37
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:43
SimulationRunMode getSimulationMode() const
Get the run mode of the simulation (e.g.
Definition: simulation_impl.h:84
std::string & getOutputDirectory()
Returns the output directory of the simulation
Definition: simulation_impl.h:111
TimeConverter * registerClock(const std::string &freq, Clock::HandlerBase *handler, int priority)
Register a handler to be called on a set frequency.
Definition: simulation.cc:1092
Definition: componentInfo.h:44
int getCurrentPriority() const
Return the current priority.
Definition: simulation.cc:76
Statistics::StatisticProcessingEngine * getStatisticsProcessingEngine(void)
Return the Statistic Processing Engine associated with this Simulation.
Definition: simulation.cc:1228
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:394
void checkpoint_append_registry(const std::string ®istry_name, const std::string &blob_name)
Append partitions registry information.
Definition: simulation.cc:1570
void requireLibrary(const std::string &name)
Signifies that a library is required for this simulation.
Definition: simulation.cc:371
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:52
std::map< std::pair< SimTime_t, int >, Clock * > clockMap_t
Definition: simulation_impl.h:130
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:1484
bool parseSignalString(std::string &arg, std::string &name, Params ¶ms)
Helper for signal string parsing.
Definition: simulation.cc:311
Performs Unit math in full precision.
Definition: unitAlgebra.h:106
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:444
Definition: threadsafe.h:47
Link between two components.
Definition: link.h:51
static void shutdown()
Used to signify the end of simulation.
Definition: simulation.cc:170
static Simulation_impl * createSimulation(Config *config, RankInfo my_rank, RankInfo num_ranks, bool restart)
Create new simulation.
Definition: simulation.cc:155