SST  14.0.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 Exit;
27 class Simulation_impl;
28 // class SyncBase;
29 class ThreadSyncQueue;
30 class TimeConverter;
31 
32 class SyncProfileToolList;
33 namespace Profile {
34 class SyncProfileTool;
35 }
36 
38 {
39 public:
40  RankSync(RankInfo num_ranks) : num_ranks(num_ranks) { link_maps.resize(num_ranks.rank); }
41  RankSync() : max_period(nullptr) {}
42  virtual ~RankSync() {}
43 
44  /** Register a Link which this Sync Object is responsible for */
45  virtual ActivityQueue*
46  registerLink(const RankInfo& to_rank, const RankInfo& from_rank, const std::string& name, Link* link) = 0;
47  void exchangeLinkInfo(uint32_t my_rank);
48 
49  virtual void execute(int thread) = 0;
50  virtual void exchangeLinkUntimedData(int thread, std::atomic<int>& msg_count) = 0;
51  virtual void finalizeLinkConfigurations() = 0;
52  virtual void prepareForComplete() = 0;
53 
54  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
55 
56  // void setMaxPeriod(TimeConverter* period) {max_period = period;}
57  TimeConverter* getMaxPeriod() { return max_period; }
58 
59  virtual uint64_t getDataSize() const = 0;
60 
61  void serialize_order(SST::Core::Serialization::serializer& ser) override
62  {
63  ser& nextSyncTime;
64  ser& max_period; // Unused
65  // ser& num_ranks; // const so a pain to serialize but don't need it
66  ser& link_maps;
67  }
68  ImplementVirtualSerializable(SST::RankSync) protected : SimTime_t nextSyncTime;
69  TimeConverter* max_period;
70  const RankInfo num_ranks;
71 
72  std::vector<std::map<std::string, uintptr_t>> link_maps;
73 
74  void finalizeConfiguration(Link* link) { link->finalizeConfiguration(); }
75 
76  void prepareForCompleteInt(Link* link) { link->prepareForComplete(); }
77 
78  void sendUntimedData_sync(Link* link, Event* data) { link->sendUntimedData_sync(data); }
79 
80  inline void setLinkDeliveryInfo(Link* link, uintptr_t info) { link->pair_link->setDeliveryInfo(info); }
81 
82  inline Link* getDeliveryLink(Event* ev) { return ev->getDeliveryLink(); }
83 
84 private:
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  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
101 
102  void setMaxPeriod(TimeConverter* period) { max_period = period; }
103  TimeConverter* getMaxPeriod() { return max_period; }
104 
105  /** Register a Link which this Sync Object is responsible for */
106  virtual void registerLink(const std::string& name, Link* link) = 0;
107  virtual ActivityQueue* registerRemoteLink(int tid, const std::string& name, Link* link) = 0;
108 
109  void serialize_order(SST::Core::Serialization::serializer& ser) override
110  {
111  ser& nextSyncTime;
112  ser& max_period; // Unused
113  }
114  ImplementVirtualSerializable(SST::ThreadSync)
115 
116  protected :
117 
118  SimTime_t nextSyncTime;
119  TimeConverter* max_period;
120 
121  void finalizeConfiguration(Link* link) { link->finalizeConfiguration(); }
122 
123  void prepareForCompleteInt(Link* link) { link->prepareForComplete(); }
124 
125  void sendUntimedData_sync(Link* link, Event* data) { link->sendUntimedData_sync(data); }
126 
127  inline void setLinkDeliveryInfo(Link* link, uintptr_t info) { link->pair_link->setDeliveryInfo(info); }
128 
129  inline Link* getDeliveryLink(Event* ev) { return ev->getDeliveryLink(); }
130 
131 private:
132 };
133 
134 class SyncManager : public Action
135 {
136 public:
137  SyncManager(
138  const RankInfo& rank, const RankInfo& num_ranks, TimeConverter* minPartTC, SimTime_t min_part,
139  const std::vector<SimTime_t>& interThreadLatencies);
140  SyncManager(); // For serialization only
141  virtual ~SyncManager();
142 
143  /** Register a Link which this Sync Object is responsible for */
145  registerLink(const RankInfo& to_rank, const RankInfo& from_rank, const std::string& name, Link* link);
146  void exchangeLinkInfo();
147  void execute(void) override;
148 
149  /** Cause an exchange of Initialization Data to occur */
150  void exchangeLinkUntimedData(std::atomic<int>& msg_count);
151  /** Finish link configuration */
153  void prepareForComplete();
154 
155  void print(const std::string& header, Output& out) const override;
156 
157  uint64_t getDataSize() const;
158 
159  void addProfileTool(Profile::SyncProfileTool* tool);
160 
161  void serialize_order(SST::Core::Serialization::serializer& ser) override;
162  ImplementSerializable(SST::SyncManager)
163 private:
164  enum sync_type_t { RANK, THREAD };
165 
166  RankInfo rank;
167  RankInfo num_ranks;
168  static Core::ThreadSafe::Barrier RankExecBarrier[6];
169  static Core::ThreadSafe::Barrier LinkUntimedBarrier[3];
170  // static SimTime_t min_next_time;
171  // static int min_count;
172 
173  static RankSync* rankSync;
174  static SimTime_t next_rankSync;
175  ThreadSync* threadSync;
176  Exit* exit;
177  Simulation_impl* sim;
178 
179  sync_type_t next_sync_type;
180  SimTime_t min_part;
181 
182  SyncProfileToolList* profile_tools = nullptr;
183 
184  void computeNextInsert();
185 };
186 
187 } // namespace SST
188 
189 #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
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
Definition: syncManager.h:134
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.
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:414
Definition: syncManager.h:37
Definition: syncProfileTool.h:28
Definition: action.cc:18
Definition: syncManager.cc:220
Definition: serializable.h:118
Exit Event Action.
Definition: exit.h:34
Definition: syncManager.h:87
void execute(void) override
Function which will be called when the time for this Activity comes to pass.
Definition: syncManager.cc:340
void exchangeLinkUntimedData(std::atomic< int > &msg_count)
Cause an exchange of Initialization Data to occur.
Definition: syncManager.cc:403
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:309
Main control class for a SST Simulation.
Definition: simulation_impl.h:70
Definition: rankInfo.h:21
void prepareForComplete()
Prepare for complete() phase.
Definition: syncManager.cc:427
Base Class for a queue of Activities.
Definition: activityQueue.h:21
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