SST  7.2.0
StructuralSimulationToolkit
link.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_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 #ifdef __SST_DEBUG_EVENT_TRACKING__
136  void setSendingComponentInfo(const std::string& comp_in, const std::string& type_in, const std::string& port_in) {
137  comp = comp_in;
138  ctype = type_in;
139  port = port_in;
140  }
141 
142  const std::string& getSendingComponentName() { return comp; }
143  const std::string& getSendingComponentType() { return ctype; }
144  const std::string& getSendingPort() { return port; }
145 
146 #endif
147 
148 protected:
149  Link();
150 
151  /** Queue of events to be received by the owning component */
153  /** Queue of events to be received during init by the owning component */
155  /** Currently active Queue */
157  /** Unitialized queue. Used for error detection */
159  /** Unitialized queue. Used for error detection */
161  /** Unitialized queue. Used for error detection */
163 
164  /** Recieve functor. This functor is set when the link is connected.
165  Determines what the receiver wants to be called
166  */
168 
169  /** Timebase used if no other timebase is specified. Used to specify
170  the untits for added delays when sending, such as in
171  Link::send(). Often set by the Component::registerClock()
172  function if the regAll argument is true.
173  */
175 
176  /** Latency of the link. It is used by the partitioner as the
177  weight. This latency is added to the delay put on the event by
178  the component.
179  */
180  SimTime_t latency;
181 
182  /** Pointer to the opposite side of this link */
184 
185 private:
186  Link( const Link& l );
187 
188  void sendUntimedData_sync(Event* data);
189  void finalizeConfiguration();
190  void prepareForComplete();
191 
192  Type_t type;
193  LinkId_t id;
194 
195 #ifdef __SST_DEBUG_EVENT_TRACKING__
196  std::string comp;
197  std::string ctype;
198  std::string port;
199 #endif
200 
201 };
202 
203 /** Self Links are links from a component to itself */
204 class SelfLink : public Link {
205 public:
206  SelfLink() : Link()
207  {
208  pair_link = this;
209  latency = 0;
210  }
211 
212 };
213 
214 
215 } // namespace SST
216 
217 #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: action.cc:17
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:34
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