SST  14.1.0
StructuralSimulationToolkit
event.h
1 // Copyright 2009-2024 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-2024, 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  /**
64  New style (checkpointable) SSTHandler
65  */
66  template <typename classT, auto funcT, typename dataT = void>
68 
69  /** Type definition of unique identifiers */
70  typedef std::pair<uint64_t, int> id_type;
71  /** Constant, default value for id_types */
72  static const id_type NO_ID;
73 
74  Event() : Activity(), delivery_info(0)
75  {
76  setPriority(EVENTPRIORITY);
77 #if __SST_DEBUG_EVENT_TRACKING__
78  first_comp = "";
79  last_comp = "";
80 #endif
81  }
82  virtual ~Event();
83 
84  /** Clones the event in for the case of a broadcast */
85  virtual Event* clone();
86 
87 
88 #ifdef __SST_DEBUG_EVENT_TRACKING__
89 
90  virtual void printTrackingInfo(const std::string& header, Output& out) const override
91  {
92  out.output(
93  "%s Event first sent from: %s:%s (type: %s) and last received by %s:%s (type: %s)\n", header.c_str(),
94  first_comp.c_str(), first_port.c_str(), first_type.c_str(), last_comp.c_str(), last_port.c_str(),
95  last_type.c_str());
96  }
97 
98  const std::string& getFirstComponentName() { return first_comp; }
99  const std::string& getFirstComponentType() { return first_type; }
100  const std::string& getFirstPort() { return first_port; }
101  const std::string& getLastComponentName() { return last_comp; }
102  const std::string& getLastComponentType() { return last_type; }
103  const std::string& getLastPort() { return last_port; }
104 
105  void addSendComponent(const std::string& comp, const std::string& type, const std::string& port)
106  {
107  if ( first_comp == "" ) {
108  first_comp = comp;
109  first_type = type;
110  first_port = port;
111  }
112  }
113  void addRecvComponent(const std::string& comp, const std::string& type, const std::string& port)
114  {
115  last_comp = comp;
116  last_type = type;
117  last_port = port;
118  }
119 
120 #endif
121 
122  bool isEvent() final { return true; }
123 
124  void serialize_order(SST::Core::Serialization::serializer& ser) override
125  {
126  Activity::serialize_order(ser);
127  ser& delivery_info;
128 #ifdef __SST_DEBUG_EVENT_TRACKING__
129  ser& first_comp;
130  ser& first_type;
131  ser& first_port;
132  ser& last_comp;
133  ser& last_type;
134  ser& last_port;
135 #endif
136  }
137 
138 protected:
139  /**
140  * Generates an ID that is unique across ranks, components and events.
141  */
143 
144 
145 private:
146  friend class Link;
147  friend class NullEvent;
148  friend class RankSync;
149  friend class ThreadSync;
150  friend class TimeVortex;
151 
152 
153  /** Cause this event to fire */
154  void execute(void) override;
155 
156  /**
157  This sets the information needed to get the event properly
158  delivered for the next step of transfer.
159 
160  The tag is used to deterministically sort the events and is
161  based off of the sorted link names. This field is unused for
162  events sent across link connected to sync objects.
163 
164  For links that are going to a sync, the delivery_info is used
165  on the remote side to send the event on the proper link. For
166  local links, delivery_info contains the delivery functor.
167  @return void
168  */
169  inline void setDeliveryInfo(LinkId_t tag, uintptr_t delivery_info)
170  {
171  setOrderTag(tag);
172  this->delivery_info = delivery_info;
173  }
174 
175  /** Gets the link id used for delivery. For use by SST Core only */
176  inline Link* getDeliveryLink() { return reinterpret_cast<Link*>(delivery_info); }
177 
178  /** Gets the link id associated with this event. For use by SST Core only */
179  inline LinkId_t getTag(void) const { return getOrderTag(); }
180 
181 
182  /** Holds the delivery information. This is stored as a
183  uintptr_t, but is actually a pointer converted using
184  reinterpret_cast. For events send on links connected to a
185  Component/SubComponent, this holds a pointer to the delivery
186  functor. For events sent on links connected to a Sync object,
187  this holds a pointer to the remote link to send the event on
188  after synchronization.
189  */
190  uintptr_t delivery_info;
191 
192 private:
193  static std::atomic<uint64_t> id_counter;
194 
195 #ifdef __SST_DEBUG_EVENT_TRACKING__
196  std::string first_comp;
197  std::string first_type;
198  std::string first_port;
199  std::string last_comp;
200  std::string last_type;
201  std::string last_port;
202 #endif
203 
205 };
206 
207 /**
208  * Empty Event. Does nothing.
209  */
210 class EmptyEvent : public Event
211 {
212 public:
213  EmptyEvent() : Event() {}
214  ~EmptyEvent() {}
215 
216 private:
217  ImplementSerializable(SST::EmptyEvent)
218 };
219 
221 {
222 public:
223  const ComponentId_t comp_id;
224  const std::string comp_name;
225  const std::string comp_type;
226  const std::string port_name;
227 
229  ComponentId_t id, const std::string& cname, const std::string& ctype, const std::string& pname) :
230  comp_id(id),
231  comp_name(cname),
232  comp_type(ctype),
233  port_name(pname)
234  {}
235 
237 };
238 
239 } // namespace SST
240 
241 #endif // SST_CORE_EVENT_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:53
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:210
Definition: event.h:220
Base class for all Activities in the SST Event Queue.
Definition: activity.h:46
Base template for the class.
Definition: ssthandler.h:466
Handler class with user-data argument.
Definition: ssthandler.h:284
void setOrderTag(uint32_t tag)
Sets the order tag.
Definition: activity.h:151
void setPriority(uint64_t priority)
Set the priority of the Activity.
Definition: activity.h:185
Definition: action.cc:18
std::pair< uint64_t, int > id_type
Type definition of unique identifiers.
Definition: event.h:70
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:184
Just a tag class for the various metadata that will need to be stored in the simulation object to all...
Definition: ssthandler.h:28
static const id_type NO_ID
Constant, default value for id_types.
Definition: event.h:72
ImplementVirtualSerializable(SST::Activity) void setQueueOrder(uint64_t order)
Set a new Queue order.
Definition: activity.h:209
Empty Event.
Definition: event.h:210
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:154