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