SST  10.1.0
StructuralSimulationToolkit
syncManager.h
1 // Copyright 2009-2020 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-2020, 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_SYNCMANAGER_H
13 #define SST_CORE_SYNCMANAGER_H
14 
15 #include "sst/core/sst_types.h"
16 
17 #include "sst/core/action.h"
18 #include "sst/core/link.h"
19 #include "sst/core/rankInfo.h"
20 #include "sst/core/threadsafe.h"
21 
22 #include <vector>
23 #include <unordered_map>
24 
25 namespace SST {
26 
27 class Exit;
28 class Simulation;
29 class SyncBase;
30 class ThreadSyncQueue;
31 class TimeConverter;
32 
33 class NewRankSync {
34 public:
35  NewRankSync() {}
36  virtual ~NewRankSync() {}
37 
38  /** Register a Link which this Sync Object is responsible for */
39  virtual ActivityQueue* registerLink(const RankInfo& to_rank, const RankInfo& from_rank, LinkId_t link_id, Link* link) = 0;
40 
41  virtual void execute(int thread) = 0;
42  virtual void exchangeLinkUntimedData(int thread, std::atomic<int>& msg_count) = 0;
43  virtual void finalizeLinkConfigurations() = 0;
44  virtual void prepareForComplete() = 0;
45 
46  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
47 
48  // void setMaxPeriod(TimeConverter* period) {max_period = period;}
49  TimeConverter* getMaxPeriod() {return max_period;}
50 
51  virtual uint64_t getDataSize() const = 0;
52 
53 protected:
54  SimTime_t nextSyncTime;
55  TimeConverter* max_period;
56 
57  void finalizeConfiguration(Link* link) {
58  link->finalizeConfiguration();
59  }
60 
61  void prepareForCompleteInt(Link* link) {
62  link->prepareForComplete();
63  }
64 
65  void sendUntimedData_sync(Link* link, Event* data) {
66  link->sendUntimedData_sync(data);
67  }
68 
69 private:
70 
71 };
72 
74 public:
75  NewThreadSync () {}
76  virtual ~NewThreadSync() {}
77 
78  virtual void before() = 0;
79  virtual void after() = 0;
80  virtual void execute() = 0;
81  virtual void processLinkUntimedData() = 0;
82  virtual void finalizeLinkConfigurations() = 0;
83  virtual void prepareForComplete() = 0;
84 
85  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
86 
87  void setMaxPeriod(TimeConverter* period) {max_period = period;}
88  TimeConverter* getMaxPeriod() {return max_period;}
89 
90  /** Register a Link which this Sync Object is responsible for */
91  virtual void registerLink(LinkId_t link_id, Link* link) = 0;
92  virtual ActivityQueue* getQueueForThread(int tid) = 0;
93 
94 protected:
95  SimTime_t nextSyncTime;
96  TimeConverter* max_period;
97 
98  void finalizeConfiguration(Link* link) {
99  link->finalizeConfiguration();
100  }
101 
102  void prepareForCompleteInt(Link* link) {
103  link->prepareForComplete();
104  }
105 
106  void sendUntimedData_sync(Link* link, Event* data) {
107  link->sendUntimedData_sync(data);
108  }
109 
110 private:
111 };
112 
113 class SyncManager : public Action {
114 public:
115  SyncManager(const RankInfo& rank, const RankInfo& num_ranks, TimeConverter* minPartTC, SimTime_t min_part, const std::vector<SimTime_t>& interThreadLatencies);
116  virtual ~SyncManager();
117 
118  /** Register a Link which this Sync Object is responsible for */
119  ActivityQueue* registerLink(const RankInfo& to_rank, const RankInfo& from_rank, LinkId_t link_id, Link* link);
120  void execute(void) override;
121 
122  /** Cause an exchange of Initialization Data to occur */
123  void exchangeLinkUntimedData(std::atomic<int>& msg_count);
124  /** Finish link configuration */
126  void prepareForComplete();
127 
128  void print(const std::string& header, Output &out) const override;
129 
130  uint64_t getDataSize() const;
131 
132 private:
133  enum sync_type_t { RANK, THREAD};
134 
135  RankInfo rank;
136  RankInfo num_ranks;
137  static Core::ThreadSafe::Barrier RankExecBarrier[6];
138  static Core::ThreadSafe::Barrier LinkUntimedBarrier[3];
139  // static SimTime_t min_next_time;
140  // static int min_count;
141 
142  static NewRankSync* rankSync;
143  static SimTime_t next_rankSync;
144  NewThreadSync* threadSync;
145  Exit* exit;
146  Simulation * sim;
147 
148  sync_type_t next_sync_type;
149  SimTime_t min_part;
150 
151  void computeNextInsert();
152 
153 };
154 
155 
156 } // namespace SST
157 
158 #endif // SST_CORE_SYNCMANAGER_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
Definition: syncManager.h:73
An Action is a schedulable Activity which is not an Event.
Definition: action.h:30
Definition: syncManager.h:113
Main control class for a SST Simulation.
Definition: simulation.h:73
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:25
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.
void finalizeLinkConfigurations()
Finish link configuration.
Definition: syncManager.cc:248
Definition: syncManager.h:33
Exit Event Action.
Definition: exit.h:34
virtual void registerLink(LinkId_t link_id, Link *link)=0
Register a Link which this Sync Object is responsible for.
void execute(void) override
Function which will be called when the time for this Activity comes to pass.
Definition: syncManager.cc:177
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:152
void exchangeLinkUntimedData(std::atomic< int > &msg_count)
Cause an exchange of Initialization Data to occur.
Definition: syncManager.cc:236
Definition: rankInfo.h:21
void prepareForComplete()
Prepare for complete() phase.
Definition: syncManager.cc:261
Base Class for a queue of Activities.
Definition: activityQueue.h:22
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:282
Definition: threadsafe.h:50