SST  10.1.0
StructuralSimulationToolkit
link.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_LINK_H
13 #define SST_CORE_LINK_H
14 
15 #include "sst/core/sst_types.h"
16 
17 #include "sst/core/event.h"
18 
19 namespace SST {
20 
21 #define _LINK_DBG( fmt, args...) __DBG( DBG_LINK, Link, fmt, ## args )
22 
23 class TimeConverter;
24 class LinkPair;
25 class Simulation;
26 class ActivityQueue;
27 class SyncBase;
28 
29 class UnitAlgebra;
30 
31  /** Link between two components. Carries events */
32 class Link {
33  typedef enum { POLL, HANDLER, QUEUE } Type_t;
34 public:
35 
36  friend class LinkPair;
37  friend class NewRankSync;
38  friend class NewThreadSync;
39  friend class Simulation;
40  friend class SyncBase;
41  friend class ThreadSync;
42  friend class SyncManager;
43  friend class ComponentInfo;
44 
45  /** Create a new link with a given ID */
46  Link(LinkId_t id);
47 
48  virtual ~Link();
49 
50  /** Set additional Latency to be added to events being sent out of this link
51  * @param cycles Number of Cycles to be added
52  * @param timebase Base Units of cycles
53  */
54  void addSendLatency(int cycles, const std::string& timebase);
55 
56  /** Set additional Latency to be added to events being sent out of this link
57  * @param cycles Number of Cycles to be added
58  * @param timebase Base Units of cycles
59  */
60  void addSendLatency(SimTime_t cycles, TimeConverter* timebase);
61 
62  /** Set additional Latency to be added on to events coming in on this link.
63  * @param cycles Number of Cycles to be added
64  * @param timebase Base Units of cycles
65  */
66  void addRecvLatency(int cycles, const std::string& timebase);
67 
68  /** Set additional Latency to be added on to events coming in on this link.
69  * @param cycles Number of Cycles to be added
70  * @param timebase Base Units of cycles
71  */
72  void addRecvLatency(SimTime_t cycles, TimeConverter* timebase);
73 
74  /** Set the callback function to be called when a message is delivered. */
75  void setFunctor(Event::HandlerBase* functor) {
76  rFunctor = functor;
77  }
78 
79  /** Specifies that this link has no callback, and is poll-based only */
80  void setPolling();
81 
82  /** Send an event over the link with additional delay. Sends an event
83  over a link with an additional delay specified with a
84  TimeConverter. I.e. the total delay is the link's delay + the
85  additional specified delay.
86  @param delay - additional delay
87  @param tc - time converter to specify units for the additional delay
88  @param event - the Event to send
89  */
90  void send( SimTime_t delay, TimeConverter* tc, Event* event );
91 
92  /** Send an event with additional delay. Sends an event over a link
93  with additional delay specified by the Link's default
94  timebase.
95  @param delay The additional delay, in units of the default Link timebase
96  @param event The event to send
97  */
98  inline void send( SimTime_t delay, Event* event ) {
99  send(delay,defaultTimeBase,event);
100  }
101 
102  /** Send an event with the Link's default delay
103  @param event The event to send
104  */
105  inline void send( Event* event ) {
106  send( 0, event );
107  }
108 
109 
110  /** Retrieve a pending event from the Link. For links which do not
111  have a set event handler, they can be polled with this function.
112  Returns nullptr if there is no pending event.
113  */
114  Event* recv();
115 
116 
117  /** Manually set the default detaulTimeBase
118  @param tc TimeConverter object for the timebase */
120  /** Return the default Time Base for this link */
122 
123  /** Causes an event to be delivered to the registered callback */
124  inline void deliverEvent(Event* event) const {
125  (*rFunctor)(event);
126  }
127 
128  /** Return the ID of this link */
129  LinkId_t getId() { return id; }
130 
131  /** Send data during the init() phase. */
132  void sendUntimedData(Event* data);
133  /** Receive an event (if any) during the init() phase */
135 
136  /** Send data during the complete() phase. */
137  void sendInitData(Event* init_data) {
138  sendUntimedData(init_data);
139  }
140  /** Receive an event (if any) during the complete() phase */
142  return recvUntimedData();
143  }
144 
145 
146  void setAsConfigured() {
147  configured = true;
148  }
149 
150  bool isConfigured() {
151  return configured;
152  }
153 
154 #ifdef __SST_DEBUG_EVENT_TRACKING__
155  void setSendingComponentInfo(const std::string& comp_in, const std::string& type_in, const std::string& port_in) {
156  comp = comp_in;
157  ctype = type_in;
158  port = port_in;
159  }
160 
161  const std::string& getSendingComponentName() { return comp; }
162  const std::string& getSendingComponentType() { return ctype; }
163  const std::string& getSendingPort() { return port; }
164 
165 #endif
166 
167 protected:
168  Link();
169 
170  /** Queue of events to be received by the owning component */
172  /** Queue of events to be received during init by the owning component */
174  /** Currently active Queue */
176  /** Uninitialized queue. Used for error detection */
178  /** Uninitialized queue. Used for error detection */
180  /** Uninitialized queue. Used for error detection */
182 
183  /** Receive functor. This functor is set when the link is connected.
184  Determines what the receiver wants to be called
185  */
187 
188  /** Timebase used if no other timebase is specified. Used to specify
189  the units for added delays when sending, such as in
190  Link::send(). Often set by the Component::registerClock()
191  function if the regAll argument is true.
192  */
194 
195  /** Latency of the link. It is used by the partitioner as the
196  weight. This latency is added to the delay put on the event by
197  the component.
198  */
199  SimTime_t latency;
200 
201  /** Pointer to the opposite side of this link */
203 
204 private:
205  Link( const Link& l );
206 
207  /** Set minimum link latency */
208  void setLatency(Cycle_t lat);
209 
210  void sendUntimedData_sync(Event* data);
211  void finalizeConfiguration();
212  void prepareForComplete();
213 
214  Type_t type;
215  LinkId_t id;
216  bool configured;
217 
218 #ifdef __SST_DEBUG_EVENT_TRACKING__
219  std::string comp;
220  std::string ctype;
221  std::string port;
222 #endif
223 
224 };
225 
226 /** Self Links are links from a component to itself */
227 class SelfLink : public Link {
228 public:
229  SelfLink() : Link()
230  {
231  pair_link = this;
232  latency = 0;
233  }
234 
235 };
236 
237 
238 } // namespace SST
239 
240 #endif // SST_CORE_LINK_H
Definition: syncManager.h:73
Definition: syncManager.h:113
Main control class for a SST Simulation.
Definition: simulation.h:73
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:25
Definition: syncManager.h:33
Definition: threadSync.h:35
SyncBase defines the API for Sync objects, which are used to synchronize between MPI ranks in a simul...
Definition: syncBase.h:34
Defines a pair of links (to define a connected link)
Definition: linkPair.h:24
Functor classes for Event handling.
Definition: event.h:86
Definition: componentInfo.h:36
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