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