SST 16.0.0
Structural Simulation Toolkit
syncManager.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_SYNC_SYNCMANAGER_H
13#define SST_CORE_SYNC_SYNCMANAGER_H
14
15#include "sst/core/action.h"
16#include "sst/core/link.h"
17#include "sst/core/rankInfo.h"
18#include "sst/core/simulation.h"
19#include "sst/core/sst_types.h"
20#include "sst/core/threadsafe.h"
21
22#include <atomic>
23#include <cstdint>
24#include <map>
25#include <string>
26#include <unordered_map>
27#include <utility>
28#include <vector>
29
30namespace SST {
31
33class Exit;
34class RealTimeManager;
35class Simulation;
36// class SyncBase;
37class ThreadSyncQueue;
38class TimeConverter;
39
40namespace Profile {
41class SyncProfileTool;
43} // namespace Profile
44
45class RankSync
46{
47public:
48 explicit RankSync(RankInfo num_ranks) :
49 num_ranks_(num_ranks)
50 {
51 link_maps.resize(num_ranks_.rank);
52 }
53 RankSync() {}
54 virtual ~RankSync() {}
55
56 /** Register a Link which this Sync Object is responsible for */
57 virtual ActivityQueue* registerLink(const RankInfo& to_rank, const RankInfo& from_rank, Link* link) = 0;
58 void exchangeLinkInfo(uint32_t my_rank);
59 SimTime_t findSyncInterval(uint32_t my_rank);
60
61 virtual void execute(int thread) = 0;
62 virtual void exchangeLinkUntimedData(int thread, std::atomic<int>& msg_count) = 0;
63 virtual void finalizeLinkConfigurations() = 0;
64 virtual void prepareForComplete() = 0;
65
66 /** Set signals to exchange during sync */
67 virtual void setSignals(int end, int usr, int alrm) = 0;
68 /** Return exchanged signals after sync */
69 virtual bool getSignals(int& end, int& usr, int& alrm) = 0;
70
71 /** Set interactive flags to exchange during sync */
72 virtual void setShutdownFlags(bool enter_shutdown, Simulation::ShutdownMode_t shutdown_mode) = 0;
73 virtual void setCkptFlag(bool generate_ckpt) = 0;
74 virtual void setFlags(bool enter_interactive, bool enter_shutdown, Simulation::ShutdownMode_t shutdown_mode) = 0;
75 /** Return exchanged interactive flags after sync */
76 virtual void getShutdownFlags(bool& enter_shutdown, Simulation::ShutdownMode_t& shutdown_mode) = 0;
77 virtual void getCkptFlag(bool& generate_ckpt) = 0;
78 virtual void getFlags(bool& enter_interactive, bool& enter_shutdown, Simulation::ShutdownMode_t& shutdown_mode) = 0;
79 /** Clear interactive flags before next run */
80 virtual void clearFlags() = 0;
81
82 virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
83
84 virtual void setRestartTime(SimTime_t time) { nextSyncTime = time; }
85
86 void setMaxPeriod(SimTime_t period) { max_period = period; }
87 SimTime_t getMaxPeriod() { return max_period; }
88
89 virtual uint64_t getDataSize() const = 0;
90
91 virtual void setProfileToolList(Profile::SyncProfileToolList* UNUSED(profile_list)) {}
92
93protected:
94 SimTime_t nextSyncTime;
95 SimTime_t max_period;
96 const RankInfo num_ranks_;
97
98 /**
99 This uses uint64_t because it is used for two different types of data at different times:
100
101 1 - LinkId_t when doing the Link pointer exchange
102
103 2 - SimTime_t when doing the Sync interval optimization
104
105 In both cases, the uintptr_t is a pointer to a Link
106 */
107 std::vector<std::vector<std::pair<uint64_t, uintptr_t>>> link_maps;
108
109 void finalizeConfiguration(Link* link) { link->finalizeConfiguration(); }
110
111 void prepareForCompleteInt(Link* link) { link->prepareForComplete(); }
112
113 void sendUntimedData_sync(Link* link, Event* data) { link->sendUntimedData_sync(data); }
114
115 inline void setLinkDeliveryInfo(Link* link, uintptr_t info) { link->pair_link->setDeliveryInfo(info); }
116
117 inline Link* getDeliveryLink(Event* ev) { return ev->getDeliveryLink(); }
118};
119
120class ThreadSync
121{
122public:
123 ThreadSync() {}
124 virtual ~ThreadSync() {}
125
126 virtual void before() = 0;
127 virtual void after() = 0;
128 virtual void execute() = 0;
129 virtual void processLinkUntimedData() = 0;
130 virtual void finalizeLinkConfigurations() = 0;
131 virtual void prepareForComplete() = 0;
132
133 /** Set signals to exchange during sync */
134 virtual void setSignals(int end, int usr, int alrm) = 0;
135 /** Return exchanged signals after sync */
136 virtual bool getSignals(int& end, int& usr, int& alrm) = 0;
137
138 /** Set interactive flags to exchange during sync */
139 virtual void setShutdownFlags(bool enter_shutdown, Simulation::ShutdownMode_t shutdown_mode) = 0;
140 virtual void setFlags(bool enter_interactive, bool enter_shutdown, Simulation::ShutdownMode_t shutdown_mode) = 0;
141 /** Return exchanged interactive flags after sync */
142 virtual void getShutdownFlags(bool& enter_shutdown, Simulation::ShutdownMode_t& shutdown_mode) = 0;
143 virtual void getFlags(bool& enter_interactive, bool& enter_shutdown, Simulation::ShutdownMode_t& shutdown_mode) = 0;
144 /** Clear interactive flags before next run */
145 virtual void clearFlags() = 0;
146
147 virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
148 virtual void setRestartTime(SimTime_t time) { nextSyncTime = time; }
149
150 void setMaxPeriod(SimTime_t period) { max_period = period; }
151 SimTime_t getMaxPeriod() { return max_period; }
152
153 /** Register a Link which this Sync Object is responsible for */
154 virtual void registerLink(Link* link) = 0;
155 virtual ActivityQueue* registerRemoteLink(int tid, Link* link) = 0;
156
157 virtual SimTime_t findSyncInterval() { return bit_util::type_max<SimTime_t>; }
158
159 static SimTime_t updateMinimumLatency(SimTime_t lat = bit_util::type_max<SimTime_t>);
160
161protected:
162 SimTime_t nextSyncTime;
163 SimTime_t max_period;
164
165 void finalizeConfiguration(Link* link) { link->finalizeConfiguration(); }
166
167 void prepareForCompleteInt(Link* link) { link->prepareForComplete(); }
168
169 void sendUntimedData_sync(Link* link, Event* data) { link->sendUntimedData_sync(data); }
170
171 inline void setLinkDeliveryInfo(Link* link, uintptr_t info) { link->pair_link->setDeliveryInfo(info); }
172
173 inline Link* getDeliveryLink(Event* ev) { return ev->getDeliveryLink(); }
174
175 /**
176 Get the latency on the link in units of core atomic time base
177 */
178 SimTime_t getLatency(Link* link) { return link->latency; }
179
180 /**
181 Get the delivery_info for the link
182 */
183 uintptr_t getDeliveryInfo(Link* link) { return link->delivery_info; }
184
185 /**
186 Get the pair_link
187 */
188 Link* getPairLink(Link* link) { return link->pair_link; }
189};
190
191class SyncManager : public Action
192{
193public:
194 SyncManager(const RankInfo& rank, const RankInfo& num_ranks, SimTime_t min_part,
195 const std::vector<SimTime_t>& interThreadLatencies, RealTimeManager* real_time);
196 SyncManager(); // For serialization only
197 virtual ~SyncManager() = default;
198
199 /** Register a Link which this Sync Object is responsible for */
200 ActivityQueue* registerLink(const RankInfo& to_rank, const RankInfo& from_rank, Link* link);
201 void exchangeLinkInfo();
202 void handleShutdown();
203 void handleInteractiveConsole();
204 SimTime_t findRankSyncInterval();
205 SimTime_t findThreadSyncInterval();
206 void updateMinPart();
207 void execute() override;
208
209 /** Cause an exchange of Initialization Data to occur */
210 void exchangeLinkUntimedData(std::atomic<int>& msg_count);
211 /** Finish link configuration */
213 void prepareForComplete();
214
215 void print(const std::string& header, Output& out) const override;
216
217 uint64_t getDataSize() const;
218
219 void setRestartTime(SimTime_t time)
220 {
221 rankSync_->setRestartTime(time);
222 threadSync_->setRestartTime(time);
223 }
224
225 std::pair<SimTime_t, SimTime_t> getSyncIntervals()
226 {
227 return std::make_pair(rankSync_->getMaxPeriod(), threadSync_->getMaxPeriod());
228 }
229
230 void addProfileTool(Profile::SyncProfileTool* tool);
231
232 NotSerializable(SST::SyncManager)
233
234private:
235 // Enum to track the next sync type
236 enum sync_type_t { RANK, THREAD };
237
238 RankInfo rank_;
239 RankInfo num_ranks_;
240 static Core::ThreadSafe::Barrier RankExecBarrier_[6];
241 static Core::ThreadSafe::Barrier LinkUntimedBarrier_[3];
242
243 static RankSync* rankSync_;
244 static SimTime_t next_rankSync_;
245 ThreadSync* threadSync_;
246 Exit* exit_;
247 Simulation* sim_;
248
249 sync_type_t next_sync_type_;
250 SimTime_t min_part_;
251
252 RealTimeManager* real_time_;
253 CheckpointAction* checkpoint_;
254 static std::atomic<unsigned> ckpt_generate_;
255 static Core::ThreadSafe::Barrier ic_barrier_;
256
257 Profile::SyncProfileToolList* profile_tools_ = nullptr;
258
259 void computeNextInsert(SimTime_t next_checkpoint_time = MAX_SIMTIME_T);
260 void setupSyncObjects();
261 void getSimShutdownFlags(bool& enter_shutdown, Simulation::ShutdownMode_t& shutdown_mode);
262 void getSimFlags(
263 bool& enter_interactive, bool& enter_shutdown, Simulation::ShutdownMode_t& shutdown_mode, bool& generate_ckpt);
264};
265
266} // namespace SST
267
268#endif // SST_CORE_SYNC_SYNCMANAGER_H
Base Class for a queue of Activities.
Definition activityQueue.h:22
A recurring event to trigger checkpoint generation.
Definition checkpointAction.h:69
Definition threadsafe.h:50
Exit Action.
Definition exit.h:35
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition output.h:58
Definition syncProfileTool.h:145
Definition syncProfileTool.h:37
Definition rankInfo.h:24
Definition syncManager.h:46
virtual ActivityQueue * registerLink(const RankInfo &to_rank, const RankInfo &from_rank, Link *link)=0
Register a Link which this Sync Object is responsible for.
virtual void setSignals(int end, int usr, int alrm)=0
Set signals to exchange during sync.
std::vector< std::vector< std::pair< uint64_t, uintptr_t > > > link_maps
This uses uint64_t because it is used for two different types of data at different times:
Definition syncManager.h:107
virtual void setShutdownFlags(bool enter_shutdown, Simulation::ShutdownMode_t shutdown_mode)=0
Set interactive flags to exchange during sync.
virtual bool getSignals(int &end, int &usr, int &alrm)=0
Return exchanged signals after sync.
virtual void getShutdownFlags(bool &enter_shutdown, Simulation::ShutdownMode_t &shutdown_mode)=0
Return exchanged interactive flags after sync.
virtual void clearFlags()=0
Clear interactive flags before next run.
Class to manage real-time events (signals and alarms).
Definition realtime.h:175
Main control class for a SST Simulation.
Definition simulation.h:121
Definition syncManager.h:192
ActivityQueue * registerLink(const RankInfo &to_rank, const RankInfo &from_rank, Link *link)
Register a Link which this Sync Object is responsible for.
Definition syncManager.cc:453
void finalizeLinkConfigurations()
Finish link configuration.
Definition syncManager.cc:738
void exchangeLinkUntimedData(std::atomic< int > &msg_count)
Cause an exchange of Initialization Data to occur.
Definition syncManager.cc:727
void execute() override
Function which will be called when the time for this Activity comes to pass.
Definition syncManager.cc:538
void prepareForComplete()
Prepare for complete() phase.
Definition syncManager.cc:755
Definition syncQueue.h:100
Definition syncManager.h:121
virtual void setShutdownFlags(bool enter_shutdown, Simulation::ShutdownMode_t shutdown_mode)=0
Set interactive flags to exchange during sync.
virtual void setSignals(int end, int usr, int alrm)=0
Set signals to exchange during sync.
SimTime_t getLatency(Link *link)
Get the latency on the link in units of core atomic time base.
Definition syncManager.h:178
virtual void clearFlags()=0
Clear interactive flags before next run.
virtual void getShutdownFlags(bool &enter_shutdown, Simulation::ShutdownMode_t &shutdown_mode)=0
Return exchanged interactive flags after sync.
virtual void registerLink(Link *link)=0
Register a Link which this Sync Object is responsible for.
uintptr_t getDeliveryInfo(Link *link)
Get the delivery_info for the link.
Definition syncManager.h:183
Link * getPairLink(Link *link)
Get the pair_link.
Definition syncManager.h:188
virtual bool getSignals(int &end, int &usr, int &alrm)=0
Return exchanged signals after sync.
A class to convert between a component's view of time and the core's view of time.
Definition timeConverter.h:31