SST  6.0.0
StructuralSimulationToolkit
link.h
1 // Copyright 2009-2016 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-2016, 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 
45  /** Create a new link with a given ID */
46  Link(LinkId_t id);
47 
48  virtual ~Link();
49 
50  /** set minimum link latency */
51  void setLatency(Cycle_t lat);
52  /** Set additional Latency to be added on to events coming in on this link.
53  * @param cycles Number of Cycles to be added
54  * @param timebase Base Units of cycles
55  */
56  void addRecvLatency(int cycles, std::string timebase);
57  /** Set additional Latency to be added on to events coming in on this link.
58  * @param cycles Number of Cycles to be added
59  * @param timebase Base Units of cycles
60  */
61  void addRecvLatency(SimTime_t cycles, TimeConverter* timebase);
62 
63  /** Set the callback function to be called when a message is delivered. */
64  void setFunctor(Event::HandlerBase* functor) {
65  rFunctor = functor;
66  }
67 
68  /** Specifies that this link has no callback, and is poll-based only */
69  void setPolling();
70 
71  /** Send an event over the link with additional delay. Sends an event
72  over a link with an additional delay specified with a
73  TimeConverter. I.e. the total delay is the link's delay + the
74  additional specified delay.
75  @param delay - additional delay
76  @param tc - time converter to specify units for the additional delay
77  @param event - the Event to send
78  */
79  void send( SimTime_t delay, TimeConverter* tc, Event* event );
80 
81  /** Send an event with additional delay. Sends an event over a link
82  with additional delay specified by the Link's default
83  timebase.
84  @param delay The additional delay, in units of the default Link timebase
85  @param event The event to send
86  */
87  inline void send( SimTime_t delay, Event* event ) {
88  send(delay,defaultTimeBase,event);
89  }
90 
91  /** Send an event with the Link's default delay
92  @param event The event to send
93  */
94  inline void send( Event* event ) {
95  send( 0, event );
96  }
97 
98 
99  /** Retrieve a pending event from the Link. For links which do not
100  have a set event handler, they can be polled with this function.
101  Returns NULL if there is no pending event.
102  */
103  Event* recv();
104 
105 
106  /** Manually set the default detaulTimeBase
107  @param tc TimeConverter object for the timebase */
109  /** Return the default Time Base for this link */
111 
112  /** Causes an event to be delivered to the registered callback */
113  inline void deliverEvent(Event* event) const {
114  (*rFunctor)(event);
115  }
116 
117  /** Return the ID of this link */
118  LinkId_t getId() { return id; }
119 
120  /** Send data during the init() phase. */
121  void sendInitData(Event* init_data);
122  /** Receive an event (if any) during the init() phase */
123  Event* recvInitData();
124 
125 #ifdef __SST_DEBUG_EVENT_TRACKING__
126  void setSendingComponentInfo(const std::string& comp_in, const std::string& type_in, const std::string& port_in) {
127  comp = comp_in;
128  ctype = type_in;
129  port = port_in;
130  }
131 
132  const std::string& getSendingComponentName() { return comp; }
133  const std::string& getSendingComponentType() { return ctype; }
134  const std::string& getSendingPort() { return port; }
135 
136 #endif
137  // UnitAlgebra getTotalInputLatency();
138  // UnitAlgebra getTotalOutputLatency();
139 
140 protected:
141  Link();
142 
143  /** Queue of events to be received by the owning component */
145  /** Queue of events to be received during init by the owning component */
147  /** Currently active Queue */
149  /** Unitialized queue. Used for error detection */
151  /** Unitialized queue. Used for error detection */
153 
154  /** Recieve functor. This functor is set when the link is connected.
155  Determines what the receiver wants to be called
156  */
158 
159  /** Timebase used if no other timebase is specified. Used to specify
160  the untits for added delays when sending, such as in
161  Link::send(). Often set by the Component::registerClock()
162  function if the regAll argument is true.
163  */
165 
166  /** Latency of the link. It is used by the partitioner as the
167  weight. This latency is added to the delay put on the event by
168  the component.
169  */
170  SimTime_t latency;
171 
172  /** Pointer to the opposite side of this link */
174 
175 private:
176  Link( const Link& l );
177 
178  void sendInitData_sync(Event* init_data);
179  void finalizeConfiguration();
180 
181  Type_t type;
182  LinkId_t id;
183 
184 #ifdef __SST_DEBUG_EVENT_TRACKING__
185  std::string comp;
186  std::string ctype;
187  std::string port;
188 #endif
189 
190  // friend class SST::Sync;
191 
192 };
193 
194 /** Self Links are links from a component to itself */
195 class SelfLink : public Link {
196 public:
197  SelfLink() : Link()
198  {
199  pair_link = this;
200  latency = 0;
201  }
202 
203 };
204 
205 
206 } // namespace SST
207 
208 #endif // SST_CORE_LINK_H
Definition: syncManager.h:68
Definition: syncManager.h:103
Main control class for a SST Simulation.
Definition: simulation.h:75
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
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