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