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