SST  7.0.0
StructuralSimulationToolkit
link.h
1 // Copyright 2009-2017 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 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 sendInitData(Event* init_data);
123  /** Receive an event (if any) during the init() phase */
124  Event* recvInitData();
125 
126 #ifdef __SST_DEBUG_EVENT_TRACKING__
127  void setSendingComponentInfo(const std::string& comp_in, const std::string& type_in, const std::string& port_in) {
128  comp = comp_in;
129  ctype = type_in;
130  port = port_in;
131  }
132 
133  const std::string& getSendingComponentName() { return comp; }
134  const std::string& getSendingComponentType() { return ctype; }
135  const std::string& getSendingPort() { return port; }
136 
137 #endif
138  // UnitAlgebra getTotalInputLatency();
139  // UnitAlgebra getTotalOutputLatency();
140 
141 protected:
142  Link();
143 
144  /** Queue of events to be received by the owning component */
146  /** Queue of events to be received during init by the owning component */
148  /** Currently active Queue */
150  /** Unitialized queue. Used for error detection */
152  /** Unitialized queue. Used for error detection */
154 
155  /** Recieve functor. This functor is set when the link is connected.
156  Determines what the receiver wants to be called
157  */
159 
160  /** Timebase used if no other timebase is specified. Used to specify
161  the untits for added delays when sending, such as in
162  Link::send(). Often set by the Component::registerClock()
163  function if the regAll argument is true.
164  */
166 
167  /** Latency of the link. It is used by the partitioner as the
168  weight. This latency is added to the delay put on the event by
169  the component.
170  */
171  SimTime_t latency;
172 
173  /** Pointer to the opposite side of this link */
175 
176 private:
177  Link( const Link& l );
178 
179  void sendInitData_sync(Event* init_data);
180  void finalizeConfiguration();
181 
182  Type_t type;
183  LinkId_t id;
184 
185 #ifdef __SST_DEBUG_EVENT_TRACKING__
186  std::string comp;
187  std::string ctype;
188  std::string port;
189 #endif
190 
191  // friend class SST::Sync;
192 
193 };
194 
195 /** Self Links are links from a component to itself */
196 class SelfLink : public Link {
197 public:
198  SelfLink() : Link()
199  {
200  pair_link = this;
201  latency = 0;
202  }
203 
204 };
205 
206 
207 } // namespace SST
208 
209 #endif // SST_CORE_LINK_H
Definition: syncManager.h:68
Definition: syncManager.h:103
Main control class for a SST Simulation.
Definition: simulation.h:72
A class to convert between a component's view of time and the core'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