SST  14.0.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  void serialize_order(SST::Core::Serialization::serializer& ser) override
123  {
124  Activity::serialize_order(ser);
125  ser& delivery_info;
126 #ifdef __SST_DEBUG_EVENT_TRACKING__
127  ser& first_comp;
128  ser& first_type;
129  ser& first_port;
130  ser& last_comp;
131  ser& last_type;
132  ser& last_port;
133 #endif
134  }
135 
136 protected:
137  /**
138  * Generates an ID that is unique across ranks, components and events.
139  */
141 
142 
143 private:
144  friend class Link;
145  friend class NullEvent;
146  friend class RankSync;
147  friend class ThreadSync;
148  friend class TimeVortex;
149 
150 
151  /** Cause this event to fire */
152  void execute(void) override;
153 
154  /**
155  This sets the information needed to get the event properly
156  delivered for the next step of transfer.
157 
158  The tag is used to deterministically sort the events and is
159  based off of the sorted link names. This field is unused for
160  events sent across link connected to sync objects.
161 
162  For links that are going to a sync, the delivery_info is used
163  on the remote side to send the event on the proper link. For
164  local links, delivery_info contains the delivery functor.
165  @return void
166  */
167  inline void setDeliveryInfo(LinkId_t tag, uintptr_t delivery_info)
168  {
169  setOrderTag(tag);
170  this->delivery_info = delivery_info;
171  }
172 
173  /** Gets the link id used for delivery. For use by SST Core only */
174  inline Link* getDeliveryLink() { return reinterpret_cast<Link*>(delivery_info); }
175 
176  /** Gets the link id associated with this event. For use by SST Core only */
177  inline LinkId_t getTag(void) const { return getOrderTag(); }
178 
179 
180  /** Holds the delivery information. This is stored as a
181  uintptr_t, but is actually a pointer converted using
182  reinterpret_cast. For events send on links connected to a
183  Component/SubComponent, this holds a pointer to the delivery
184  functor. For events sent on links connected to a Sync object,
185  this holds a pointer to the remote link to send the event on
186  after synchronization.
187  */
188  uintptr_t delivery_info;
189 
190 private:
191  static std::atomic<uint64_t> id_counter;
192 
193 #ifdef __SST_DEBUG_EVENT_TRACKING__
194  std::string first_comp;
195  std::string first_type;
196  std::string first_port;
197  std::string last_comp;
198  std::string last_type;
199  std::string last_port;
200 #endif
201 
203 };
204 
205 /**
206  * Empty Event. Does nothing.
207  */
208 class EmptyEvent : public Event
209 {
210 public:
211  EmptyEvent() : Event() {}
212  ~EmptyEvent() {}
213 
214 private:
215  ImplementSerializable(SST::EmptyEvent)
216 };
217 
219 {
220 public:
221  const ComponentId_t comp_id;
222  const std::string comp_name;
223  const std::string comp_type;
224  const std::string port_name;
225 
227  ComponentId_t id, const std::string& cname, const std::string& ctype, const std::string& pname) :
228  comp_id(id),
229  comp_name(cname),
230  comp_type(ctype),
231  port_name(pname)
232  {}
233 
235 };
236 
237 } // namespace SST
238 
239 #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:35
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:210
Definition: event.h:218
Base class for all Activities in the SST Event Queue.
Definition: activity.h:45
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: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: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:205
Empty Event.
Definition: event.h:208
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