SST 15.0
Structural Simulation Toolkit
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
27namespace SST {
28
30class Exit;
31class RealTimeManager;
32class Simulation_impl;
33// class SyncBase;
34class ThreadSyncQueue;
35class TimeConverter;
36
38namespace Profile {
39class SyncProfileTool;
40}
41
42class RankSync
43{
44public:
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 */
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
76protected:
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
94class ThreadSync
95{
96public:
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
122protected:
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
137class SyncManager : public Action
138{
139public:
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
171private:
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
Base Class for a queue of Activities.
Definition activityQueue.h:22
A recurring event to trigger checkpoint generation.
Definition checkpointAction.h:63
Definition threadsafe.h:46
Exit Event Action.
Definition exit.h:36
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition output.h:54
Definition syncProfileTool.h:29
Definition rankInfo.h:24
Definition syncManager.h:43
virtual void setSignals(int end, int usr, int alrm)=0
Set signals to exchange during sync.
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 bool getSignals(int &end, int &usr, int &alrm)=0
Return exchanged signals after sync.
Class to manage real-time events (signals and alarms)
Definition realtime.h:170
Main control class for a SST Simulation.
Definition simulation_impl.h:87
Definition syncManager.h:138
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:336
void finalizeLinkConfigurations()
Finish link configuration.
Definition syncManager.cc:492
void exchangeLinkUntimedData(std::atomic< int > &msg_count)
Cause an exchange of Initialization Data to occur.
Definition syncManager.cc:481
void execute() override
Function which will be called when the time for this Activity comes to pass.
Definition syncManager.cc:367
void prepareForComplete()
Prepare for complete() phase.
Definition syncManager.cc:509
Definition syncManager.cc:244
Definition syncQueue.h:91
Definition syncManager.h:95
virtual void setSignals(int end, int usr, int alrm)=0
Set signals to exchange during sync.
virtual void registerLink(const std::string &name, Link *link)=0
Register a Link which this Sync Object is responsible for.
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:28