SST  7.1.0
StructuralSimulationToolkit
syncManager.h
1 // Copyright 2009-2017 Sandia Corporation. Under the terms
2 // of Contract DE-NA0003525 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2017, Sandia Corporation
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 exchangeLinkInitData(int thread, std::atomic<int>& msg_count) = 0;
43  virtual void finalizeLinkConfigurations() = 0;
44 
45  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
46 
47  // void setMaxPeriod(TimeConverter* period) {max_period = period;}
48  TimeConverter* getMaxPeriod() {return max_period;}
49 
50  virtual uint64_t getDataSize() const = 0;
51 
52 protected:
53  SimTime_t nextSyncTime;
54  TimeConverter* max_period;
55 
56  void finalizeConfiguration(Link* link) {
57  link->finalizeConfiguration();
58  }
59 
60  void sendInitData_sync(Link* link, Event* init_data) {
61  link->sendInitData_sync(init_data);
62  }
63 
64 private:
65 
66 };
67 
69 public:
70  NewThreadSync () {}
71  virtual ~NewThreadSync() {}
72 
73  virtual void before() = 0;
74  virtual void after() = 0;
75  virtual void execute() = 0;
76  virtual void processLinkInitData() = 0;
77  virtual void finalizeLinkConfigurations() = 0;
78 
79  virtual SimTime_t getNextSyncTime() { return nextSyncTime; }
80 
81  void setMaxPeriod(TimeConverter* period) {max_period = period;}
82  TimeConverter* getMaxPeriod() {return max_period;}
83 
84  /** Register a Link which this Sync Object is responsible for */
85  virtual void registerLink(LinkId_t link_id, Link* link) = 0;
86  virtual ActivityQueue* getQueueForThread(int tid) = 0;
87 
88 protected:
89  SimTime_t nextSyncTime;
90  TimeConverter* max_period;
91 
92  void finalizeConfiguration(Link* link) {
93  link->finalizeConfiguration();
94  }
95 
96  void sendInitData_sync(Link* link, Event* init_data) {
97  link->sendInitData_sync(init_data);
98  }
99 
100 private:
101 };
102 
103 class SyncManager : public Action {
104 public:
105  SyncManager(const RankInfo& rank, const RankInfo& num_ranks, TimeConverter* minPartTC, SimTime_t min_part, const std::vector<SimTime_t>& interThreadLatencies);
106  virtual ~SyncManager();
107 
108  /** Register a Link which this Sync Object is responsible for */
109  ActivityQueue* registerLink(const RankInfo& to_rank, const RankInfo& from_rank, LinkId_t link_id, Link* link);
110  void execute(void) override;
111 
112  /** Cause an exchange of Initialization Data to occur */
113  void exchangeLinkInitData(std::atomic<int>& msg_count);
114  /** Finish link configuration */
115  void finalizeLinkConfigurations();
116 
117  void print(const std::string& header, Output &out) const override;
118 
119  uint64_t getDataSize() const;
120 
121 private:
122  enum sync_type_t { RANK, THREAD};
123 
124  RankInfo rank;
125  RankInfo num_ranks;
126  static Core::ThreadSafe::Barrier RankExecBarrier[6];
127  static Core::ThreadSafe::Barrier LinkInitBarrier[3];
128  // static SimTime_t min_next_time;
129  // static int min_count;
130 
131  static NewRankSync* rankSync;
132  static SimTime_t next_rankSync;
133  NewThreadSync* threadSync;
134  Exit* exit;
135  Simulation * sim;
136 
137  sync_type_t next_sync_type;
138  SimTime_t min_part;
139 
140  void computeNextInsert();
141 
142 };
143 
144 
145 } // namespace SST
146 
147 #endif // SST_CORE_SYNCMANAGER_H
Output object provides consistant method for outputing data to stdout, stderr and/or sst debug file...
Definition: output.h:54
Definition: syncManager.h:68
An Action is a schedulable Activity which is not an Event.
Definition: action.h:30
Definition: syncManager.h:103
Main control class for a SST Simulation.
Definition: simulation.h:72
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.
Definition: action.cc:17
Definition: syncManager.h:33
Exit Event Action.
Definition: exit.h:34
Definition: rankInfo.h:21
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
Definition: threadsafe.h:42