SST  15.1.0
StructuralSimulationToolkit
syncManager.h
1 // Copyright 2009-2025 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-2025, 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/sst_types.h"
19 #include "sst/core/threadsafe.h"
20 
21 #include <cstdint>
22 #include <map>
23 #include <string>
24 #include <unordered_map>
25 #include <vector>
26 
27 namespace SST {
28 
29 class CheckpointAction;
30 class Exit;
31 class RealTimeManager;
32 class Simulation_impl;
33 // class SyncBase;
34 class ThreadSyncQueue;
35 class TimeConverter;
36 
37 class SyncProfileToolList;
38 namespace Profile {
39 class SyncProfileTool;
40 }
41 
42 class RankSync
43 {
44 public:
45  explicit RankSync(RankInfo num_ranks) :
46  num_ranks_(num_ranks)
47  {
48  link_maps.resize(num_ranks_.rank);
49  }
50  RankSync() {}
51  virtual ~RankSync() {}
52 
53  /** Register a Link which this Sync Object is responsible for */
54  virtual ActivityQueue* registerLink(
55  const RankInfo& to_rank, const RankInfo& from_rank, const std::string& name, Link* link) = 0;
56  void exchangeLinkInfo(uint32_t my_rank);
57 
58  virtual void execute(int thread) = 0;
59  virtual void exchangeLinkUntimedData(int thread, std::atomic<int>& msg_count) = 0;
60  virtual void finalizeLinkConfigurations() = 0;
61  virtual void prepareForComplete() = 0;
62 
63  /** Set signals to exchange during sync */
64  virtual void setSignals(int end, int usr, int alrm) = 0;
65  /** Return exchanged signals after sync */
66  virtual bool getSignals(int& end, int& usr, int& alrm) = 0;
67 
68  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
69 
70  virtual void setRestartTime(SimTime_t time) { nextSyncTime = time; }
71 
72  TimeConverter getMaxPeriod() { return max_period; }
73 
74  virtual uint64_t getDataSize() const = 0;
75 
76 protected:
77  SimTime_t nextSyncTime;
78  TimeConverter max_period;
79  const RankInfo num_ranks_;
80 
81  std::vector<std::map<std::string, uintptr_t>> link_maps;
82 
83  void finalizeConfiguration(Link* link) { link->finalizeConfiguration(); }
84 
85  void prepareForCompleteInt(Link* link) { link->prepareForComplete(); }
86 
87  void sendUntimedData_sync(Link* link, Event* data) { link->sendUntimedData_sync(data); }
88 
89  inline void setLinkDeliveryInfo(Link* link, uintptr_t info) { link->pair_link->setDeliveryInfo(info); }
90 
91  inline Link* getDeliveryLink(Event* ev) { return ev->getDeliveryLink(); }
92 };
93 
95 {
96 public:
97  ThreadSync() {}
98  virtual ~ThreadSync() {}
99 
100  virtual void before() = 0;
101  virtual void after() = 0;
102  virtual void execute() = 0;
103  virtual void processLinkUntimedData() = 0;
104  virtual void finalizeLinkConfigurations() = 0;
105  virtual void prepareForComplete() = 0;
106 
107  /** Set signals to exchange during sync */
108  virtual void setSignals(int end, int usr, int alrm) = 0;
109  /** Return exchanged signals after sync */
110  virtual bool getSignals(int& end, int& usr, int& alrm) = 0;
111 
112  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
113  virtual void setRestartTime(SimTime_t time) { nextSyncTime = time; }
114 
115  void setMaxPeriod(TimeConverter* period) { max_period = period; }
116  TimeConverter getMaxPeriod() { return max_period; }
117 
118  /** Register a Link which this Sync Object is responsible for */
119  virtual void registerLink(const std::string& name, Link* link) = 0;
120  virtual ActivityQueue* registerRemoteLink(int tid, const std::string& name, Link* link) = 0;
121 
122 protected:
123  SimTime_t nextSyncTime;
124  TimeConverter max_period;
125 
126  void finalizeConfiguration(Link* link) { link->finalizeConfiguration(); }
127 
128  void prepareForCompleteInt(Link* link) { link->prepareForComplete(); }
129 
130  void sendUntimedData_sync(Link* link, Event* data) { link->sendUntimedData_sync(data); }
131 
132  inline void setLinkDeliveryInfo(Link* link, uintptr_t info) { link->pair_link->setDeliveryInfo(info); }
133 
134  inline Link* getDeliveryLink(Event* ev) { return ev->getDeliveryLink(); }
135 };
136 
137 class SyncManager : public Action
138 {
139 public:
140  SyncManager(const RankInfo& rank, const RankInfo& num_ranks, SimTime_t min_part,
141  const std::vector<SimTime_t>& interThreadLatencies, RealTimeManager* real_time);
142  SyncManager(); // For serialization only
143  virtual ~SyncManager() = default;
144 
145  /** Register a Link which this Sync Object is responsible for */
147  const RankInfo& to_rank, const RankInfo& from_rank, const std::string& name, Link* link);
148  void exchangeLinkInfo();
149  void execute() override;
150 
151  /** Cause an exchange of Initialization Data to occur */
152  void exchangeLinkUntimedData(std::atomic<int>& msg_count);
153  /** Finish link configuration */
155  void prepareForComplete();
156 
157  void print(const std::string& header, Output& out) const override;
158 
159  uint64_t getDataSize() const;
160 
161  void setRestartTime(SimTime_t time)
162  {
163  rankSync_->setRestartTime(time);
164  threadSync_->setRestartTime(time);
165  }
166 
167  void addProfileTool(Profile::SyncProfileTool* tool);
168 
169  NotSerializable(SST::SyncManager)
170 
171 private:
172  // Enum to track the next sync type
173  enum sync_type_t { RANK, THREAD };
174 
175  RankInfo rank_;
176  RankInfo num_ranks_;
177  static Core::ThreadSafe::Barrier RankExecBarrier_[5];
178  static Core::ThreadSafe::Barrier LinkUntimedBarrier_[3];
179 
180  static RankSync* rankSync_;
181  static SimTime_t next_rankSync_;
182  ThreadSync* threadSync_;
183  Exit* exit_;
184  Simulation_impl* sim_;
185 
186  sync_type_t next_sync_type_;
187  SimTime_t min_part_;
188 
189  RealTimeManager* real_time_;
190  CheckpointAction* checkpoint_;
191 
192  SyncProfileToolList* profile_tools_ = nullptr;
193 
194  void computeNextInsert(SimTime_t next_checkpoint_time = MAX_SIMTIME_T);
195  void setupSyncObjects();
196 };
197 
198 } // namespace SST
199 
200 #endif // SST_CORE_SYNC_SYNCMANAGER_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:57
An Action is a schedulable Activity which is not an Event.
Definition: action.h:26
Definition: syncManager.h:137
virtual ActivityQueue * registerLink(const RankInfo &to_rank, const RankInfo &from_rank, const std::string &name, 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.
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:27
void finalizeLinkConfigurations()
Finish link configuration.
Definition: syncManager.cc:494
Definition: syncManager.h:42
Definition: syncProfileTool.h:29
A recurring event to trigger checkpoint generation.
Definition: checkpointAction.h:62
Definition: action.cc:18
Definition: syncManager.cc:245
Exit Action.
Definition: exit.h:33
Definition: syncManager.h:94
virtual bool getSignals(int &end, int &usr, int &alrm)=0
Return exchanged signals after sync.
virtual void setSignals(int end, int usr, int alrm)=0
Set signals to exchange during sync.
virtual bool getSignals(int &end, int &usr, int &alrm)=0
Return exchanged signals after sync.
void exchangeLinkUntimedData(std::atomic< int > &msg_count)
Cause an exchange of Initialization Data to occur.
Definition: syncManager.cc:483
ActivityQueue * registerLink(const RankInfo &to_rank, const RankInfo &from_rank, const std::string &name, Link *link)
Register a Link which this Sync Object is responsible for.
Definition: syncManager.cc:338
Main control class for a SST Simulation.
Definition: simulation_impl.h:122
Definition: rankInfo.h:23
void execute() override
Function which will be called when the time for this Activity comes to pass.
Definition: syncManager.cc:369
void prepareForComplete()
Prepare for complete() phase.
Definition: syncManager.cc:511
Base Class for a queue of Activities.
Definition: activityQueue.h:21
Class to manage real-time events (signals and alarms)
Definition: realtime.h:171
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:40
virtual void registerLink(const std::string &name, Link *link)=0
Register a Link which this Sync Object is responsible for.
Definition: threadsafe.h:49