SST  13.0.0
StructuralSimulationToolkit
event.h
1 // Copyright 2009-2023 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-2023, 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_EVENT_H
13 #define SST_CORE_EVENT_H
14 
15 #include "sst/core/activity.h"
16 #include "sst/core/sst_types.h"
17 #include "sst/core/ssthandler.h"
18 
19 #include <atomic>
20 #include <cinttypes>
21 #include <string>
22 
23 namespace SST {
24 
25 class Link;
26 class NullEvent;
27 class RankSync;
28 class ThreadSync;
29 
30 /**
31  * Base class for Events - Items sent across links to communicate between
32  * components.
33  */
34 class Event : public Activity
35 {
36 public:
37  /**
38  Base handler for event delivery.
39  */
41 
42  /**
43  Used to create handlers for event delivery. The callback
44  function is expected to be in the form of:
45 
46  void func(Event* event)
47 
48  In which case, the class is created with:
49 
50  new Event::Handler<classname>(this, &classname::function_name)
51 
52  Or, to add static data, the callback function is:
53 
54  void func(Event* event, dataT data)
55 
56  and the class is created with:
57 
58  new Event::Handler<classname, dataT>(this, &classname::function_name, data)
59  */
60  template <typename classT, typename dataT = void>
62 
63  /** Type definition of unique identifiers */
64  typedef std::pair<uint64_t, int> id_type;
65  /** Constant, default value for id_types */
66  static const id_type NO_ID;
67 
68  Event() : Activity()
69  {
70  setPriority(EVENTPRIORITY);
71 #if __SST_DEBUG_EVENT_TRACKING__
72  first_comp = "";
73  last_comp = "";
74 #endif
75  }
76  virtual ~Event();
77 
78  /** Clones the event in for the case of a broadcast */
79  virtual Event* clone();
80 
81 
82 #ifdef __SST_DEBUG_EVENT_TRACKING__
83 
84  virtual void printTrackingInfo(const std::string& header, Output& out) const override
85  {
86  out.output(
87  "%s Event first sent from: %s:%s (type: %s) and last received by %s:%s (type: %s)\n", header.c_str(),
88  first_comp.c_str(), first_port.c_str(), first_type.c_str(), last_comp.c_str(), last_port.c_str(),
89  last_type.c_str());
90  }
91 
92  const std::string& getFirstComponentName() { return first_comp; }
93  const std::string& getFirstComponentType() { return first_type; }
94  const std::string& getFirstPort() { return first_port; }
95  const std::string& getLastComponentName() { return last_comp; }
96  const std::string& getLastComponentType() { return last_type; }
97  const std::string& getLastPort() { return last_port; }
98 
99  void addSendComponent(const std::string& comp, const std::string& type, const std::string& port)
100  {
101  if ( first_comp == "" ) {
102  first_comp = comp;
103  first_type = type;
104  first_port = port;
105  }
106  }
107  void addRecvComponent(const std::string& comp, const std::string& type, const std::string& port)
108  {
109  last_comp = comp;
110  last_type = type;
111  last_port = port;
112  }
113 
114 #endif
115 
116  void serialize_order(SST::Core::Serialization::serializer& ser) override
117  {
118  Activity::serialize_order(ser);
119  ser& delivery_info;
120 #ifdef __SST_DEBUG_EVENT_TRACKING__
121  ser& first_comp;
122  ser& first_type;
123  ser& first_port;
124  ser& last_comp;
125  ser& last_type;
126  ser& last_port;
127 #endif
128  }
129 
130 protected:
131  /**
132  * Generates an ID that is unique across ranks, components and events.
133  */
135 
136 
137 private:
138  friend class Link;
139  friend class NullEvent;
140  friend class RankSync;
141  friend class ThreadSync;
142 
143 
144  /** Cause this event to fire */
145  void execute(void) override;
146 
147  /**
148  This sets the information needed to get the event properly
149  delivered for the next step of transfer.
150 
151  The tag is used to deterministically sort the events and is
152  based off of the sorted link names. This field is unused for
153  events sent across link connected to sync objects.
154 
155  For links that are going to a sync, the delivery_info is used
156  on the remote side to send the event on the proper link. For
157  local links, delivery_info contains the delivery functor.
158  */
159  inline void setDeliveryInfo(LinkId_t tag, uintptr_t delivery_info)
160  {
161  setOrderTag(tag);
162  this->delivery_info = delivery_info;
163  }
164 
165  /** Gets the link id used for delivery. For use by SST Core only */
166  inline Link* getDeliveryLink() { return reinterpret_cast<Link*>(delivery_info); }
167 
168  /** Gets the link id associated with this event. For use by SST Core only */
169  inline LinkId_t getTag(void) const { return getOrderTag(); }
170 
171 
172  /** Holds the delivery information. This is stored as a
173  uintptr_t, but is actually a pointer converted using
174  reinterpret_cast. For events send on links connected to a
175  Component/SubComponent, this holds a pointer to the delivery
176  functor. For events sent on links connected to a Sync object,
177  this holds a pointer to the remote link to send the event on
178  after synchronization.
179  */
180  uintptr_t delivery_info;
181 
182 private:
183  static std::atomic<uint64_t> id_counter;
184 
185 #ifdef __SST_DEBUG_EVENT_TRACKING__
186  std::string first_comp;
187  std::string first_type;
188  std::string first_port;
189  std::string last_comp;
190  std::string last_type;
191  std::string last_port;
192 #endif
193 
195 };
196 
197 /**
198  * Empty Event. Does nothing.
199  */
200 class EmptyEvent : public Event
201 {
202 public:
203  EmptyEvent() : Event() {}
204  ~EmptyEvent() {}
205 
206 private:
207  ImplementSerializable(SST::EmptyEvent)
208 };
209 
211 {
212 public:
213  const ComponentId_t comp_id;
214  const std::string comp_name;
215  const std::string comp_type;
216  const std::string port_name;
217 
219  ComponentId_t id, const std::string& cname, const std::string& ctype, const std::string& pname) :
220  comp_id(id),
221  comp_name(cname),
222  comp_type(ctype),
223  port_name(pname)
224  {}
225 
227 };
228 
229 } // namespace SST
230 
231 #endif // SST_CORE_EVENT_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:51
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:34
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:170
Definition: event.h:210
Base class for all Activities in the SST Event Queue.
Definition: activity.h:45
Handler class with user-data argument.
Definition: ssthandler.h:219
void setOrderTag(uint32_t tag)
Sets the order tag.
Definition: activity.h:150
void setPriority(uint64_t priority)
Set the priority of the Activity.
Definition: activity.h:181
Definition: action.cc:18
std::pair< uint64_t, int > id_type
Type definition of unique identifiers.
Definition: event.h:64
void output(uint32_t line, const char *file, const char *func, const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition: output.h:182
Just a tag class for the various metadata that will need to be stored in the simulation object to all...
Definition: ssthandler.h:27
static const id_type NO_ID
Constant, default value for id_types.
Definition: event.h:66
ImplementVirtualSerializable(SST::Activity) void setQueueOrder(uint64_t order)
Set a new Queue order.
Definition: activity.h:205
Empty Event.
Definition: event.h:200
id_type generateUniqueId()
Generates an ID that is unique across ranks, components and events.
Definition: event.cc:45
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:34
virtual Event * clone()
Clones the event in for the case of a broadcast.
Definition: event.cc:35
uint32_t getOrderTag() const
Return the order tag associated with this activity.
Definition: activity.h:153