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