SST  13.0.0
StructuralSimulationToolkit
syncManager.h
1 // Copyright 2009-2023 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-2023, 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 
37 class RankSync
38 {
39 public:
40  RankSync(RankInfo num_ranks) : num_ranks(num_ranks) { link_maps.resize(num_ranks.rank); }
41  virtual ~RankSync() {}
42 
43  /** Register a Link which this Sync Object is responsible for */
44  virtual ActivityQueue*
45  registerLink(const RankInfo& to_rank, const RankInfo& from_rank, const std::string& name, Link* link) = 0;
46  void exchangeLinkInfo(uint32_t my_rank);
47 
48  virtual void execute(int thread) = 0;
49  virtual void exchangeLinkUntimedData(int thread, std::atomic<int>& msg_count) = 0;
50  virtual void finalizeLinkConfigurations() = 0;
51  virtual void prepareForComplete() = 0;
52 
53  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
54 
55  // void setMaxPeriod(TimeConverter* period) {max_period = period;}
56  TimeConverter* getMaxPeriod() { return max_period; }
57 
58  virtual uint64_t getDataSize() const = 0;
59 
60 protected:
61  SimTime_t nextSyncTime;
62  TimeConverter* max_period;
63  const RankInfo num_ranks;
64 
65  std::vector<std::map<std::string, uintptr_t>> link_maps;
66 
67  void finalizeConfiguration(Link* link) { link->finalizeConfiguration(); }
68 
69  void prepareForCompleteInt(Link* link) { link->prepareForComplete(); }
70 
71  void sendUntimedData_sync(Link* link, Event* data) { link->sendUntimedData_sync(data); }
72 
73  inline void setLinkDeliveryInfo(Link* link, uintptr_t info) { link->pair_link->setDeliveryInfo(info); }
74 
75  inline Link* getDeliveryLink(Event* ev) { return ev->getDeliveryLink(); }
76 
77 private:
78 };
79 
81 {
82 public:
83  ThreadSync() {}
84  virtual ~ThreadSync() {}
85 
86  virtual void before() = 0;
87  virtual void after() = 0;
88  virtual void execute() = 0;
89  virtual void processLinkUntimedData() = 0;
90  virtual void finalizeLinkConfigurations() = 0;
91  virtual void prepareForComplete() = 0;
92 
93  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
94 
95  void setMaxPeriod(TimeConverter* period) { max_period = period; }
96  TimeConverter* getMaxPeriod() { return max_period; }
97 
98  /** Register a Link which this Sync Object is responsible for */
99  virtual void registerLink(const std::string& name, Link* link) = 0;
100  virtual ActivityQueue* registerRemoteLink(int tid, const std::string& name, Link* link) = 0;
101 
102 protected:
103  SimTime_t nextSyncTime;
104  TimeConverter* max_period;
105 
106  void finalizeConfiguration(Link* link) { link->finalizeConfiguration(); }
107 
108  void prepareForCompleteInt(Link* link) { link->prepareForComplete(); }
109 
110  void sendUntimedData_sync(Link* link, Event* data) { link->sendUntimedData_sync(data); }
111 
112  inline void setLinkDeliveryInfo(Link* link, uintptr_t info) { link->pair_link->setDeliveryInfo(info); }
113 
114  inline Link* getDeliveryLink(Event* ev) { return ev->getDeliveryLink(); }
115 
116 private:
117 };
118 
119 class SyncManager : public Action
120 {
121 public:
122  SyncManager(
123  const RankInfo& rank, const RankInfo& num_ranks, TimeConverter* minPartTC, SimTime_t min_part,
124  const std::vector<SimTime_t>& interThreadLatencies);
125  virtual ~SyncManager();
126 
127  /** Register a Link which this Sync Object is responsible for */
129  registerLink(const RankInfo& to_rank, const RankInfo& from_rank, const std::string& name, Link* link);
130  void exchangeLinkInfo();
131  void execute(void) override;
132 
133  /** Cause an exchange of Initialization Data to occur */
134  void exchangeLinkUntimedData(std::atomic<int>& msg_count);
135  /** Finish link configuration */
137  void prepareForComplete();
138 
139  void print(const std::string& header, Output& out) const override;
140 
141  uint64_t getDataSize() const;
142 
143  void addProfileTool(Profile::SyncProfileTool* tool);
144 
145 private:
146  enum sync_type_t { RANK, THREAD };
147 
148  RankInfo rank;
149  RankInfo num_ranks;
150  static Core::ThreadSafe::Barrier RankExecBarrier[6];
151  static Core::ThreadSafe::Barrier LinkUntimedBarrier[3];
152  // static SimTime_t min_next_time;
153  // static int min_count;
154 
155  static RankSync* rankSync;
156  static SimTime_t next_rankSync;
157  ThreadSync* threadSync;
158  Exit* exit;
159  Simulation_impl* sim;
160 
161  sync_type_t next_sync_type;
162  SimTime_t min_part;
163 
164  SyncProfileToolList* profile_tools = nullptr;
165 
166  void computeNextInsert();
167 
168  NotSerializable(SST::SyncManager)
169 };
170 
171 } // namespace SST
172 
173 #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:51
An Action is a schedulable Activity which is not an Event.
Definition: action.h:26
Definition: syncManager.h:119
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:26
void finalizeLinkConfigurations()
Finish link configuration.
Definition: syncManager.cc:398
Definition: syncManager.h:37
Definition: syncProfileTool.h:28
Definition: action.cc:18
Definition: syncManager.cc:211
Exit Event Action.
Definition: exit.h:34
Definition: syncManager.h:80
void execute(void) override
Function which will be called when the time for this Activity comes to pass.
Definition: syncManager.cc:324
void exchangeLinkUntimedData(std::atomic< int > &msg_count)
Cause an exchange of Initialization Data to occur.
Definition: syncManager.cc:387
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:293
Main control class for a SST Simulation.
Definition: simulation_impl.h:73
Definition: rankInfo.h:21
void prepareForComplete()
Prepare for complete() phase.
Definition: syncManager.cc:411
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