SST 15.0
Structural Simulation Toolkit
enclosingComponent.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_CORETEST_MESSAGEMESH_ENCLOSINGCOMPONENT_H
13#define SST_CORE_CORETEST_MESSAGEMESH_ENCLOSINGCOMPONENT_H
14
15#include "sst/core/testElements/message_mesh/messageEvent.h"
16
17#include "sst/core/component.h"
18#include "sst/core/event.h"
19#include "sst/core/link.h"
20#include "sst/core/rng/rng.h"
21#include "sst/core/ssthandler.h"
22#include "sst/core/subcomponent.h"
23
24#include <vector>
25
26namespace SST::CoreTest::MessageMesh {
27
28class PortInterface : public SST::SubComponent
29{
30public:
31 SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTest::MessageMesh::PortInterface)
32
33 explicit PortInterface(ComponentId_t id) :
34 SubComponent(id)
35 {}
36 virtual ~PortInterface() {}
37
38 /**
39 Base handler for event delivery.
40 */
42
43 /**
44 Used to create handlers to notify the component when a message
45 has arrived. endpoint when the The callback function is
46 expected to be in the form of:
47
48 void func(Event* ev)
49
50 In which case, the class is created with:
51
52 new PortInterface::Handler<classname>(this, &classname::function_name)
53
54 Or, to add static data, the callback function is:
55
56 void func(Event* ev, dataT data)
57
58 and the class is created with:
59
60 new PortInterface::Handler<classname, dataT>(this, &classname::function_name, data)
61 */
62 template <typename classT, typename dataT = void>
64
65 /**
66 Used to create checkpointable handlers to notify the component
67 when a message has arrived. endpoint when the The callback
68 function is expected to be in the form of:
69
70 void func(Event* ev)
71
72 In which case, the class is created with:
73
74 new PortInterface::Handler2<classname, &classname::function_name>(this)
75
76 Or, to add static data, the callback function is:
77
78 void func(Event* ev, dataT data)
79
80 and the class is created with:
81
82 new PortInterface::Handler2<classname, &classname::function_name, dataT>(this, data)
83 */
84 template <typename classT, auto funcT, typename dataT = void>
86
87 virtual void setNotifyOnReceive(HandlerBase* functor) { rFunctor = functor; }
88
89 virtual void send(MessageEvent* ev) = 0;
90
91protected:
92 HandlerBase* rFunctor;
93};
94
95class RouteInterface : public SST::SubComponent
96{
97public:
98 SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTest::MessageMesh::RouteInterface, const std::vector<PortInterface*>&, int)
99
100 explicit RouteInterface(ComponentId_t id) :
101 SubComponent(id)
102 {}
103 virtual ~RouteInterface() {}
104
105 virtual void send(MessageEvent* ev, int incoming_port) = 0;
106};
107
109{
110public:
111 // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
112 SST_ELI_REGISTER_COMPONENT(
114 "coreTestElement",
115 "message_mesh.enclosing_component",
116 SST_ELI_ELEMENT_VERSION(1,0,0),
117 "Base element that encloses the SubComponents that actually provide the functionality",
118 COMPONENT_CATEGORY_NETWORK
119 )
120
121 SST_ELI_DOCUMENT_PARAMS(
122 {"id", "Id for this componentd", ""},
123 )
124
125 SST_ELI_DOCUMENT_STATISTICS(
126 )
127
128 SST_ELI_DOCUMENT_PORTS(
129 )
130
131 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
132 {"ports", "Slot that the ports objects go in", "SST::CoreTest::MessageMesh::PortInterface" },
133 {"route", "Slot that the ports objects go in", "SST::CoreTest::MessageMesh::RouteInterface" }
134 )
135
136 EnclosingComponent(ComponentId_t id, Params& params);
137
138 void setup() override;
139 void finish() override;
140
141private:
142 void handleEvent(SST::Event* ev, int port);
143
144 std::vector<PortInterface*> ports;
145 RouteInterface* route;
146
147 int my_id;
148 int message_count;
149};
150
151// SubComponents
152
153class PortSlot : public PortInterface
154{
155public:
156 // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
157 SST_ELI_REGISTER_SUBCOMPONENT(
158 PortSlot,
159 "coreTestElement",
160 "message_mesh.port_slot",
161 SST_ELI_ELEMENT_VERSION(1,0,0),
162 "SubComponent implementing PortInterface that simply defers to another loaded PortInterface",
164 )
165
166 SST_ELI_DOCUMENT_PARAMS(
167 )
168
169 SST_ELI_DOCUMENT_STATISTICS(
170 )
171
172 SST_ELI_DOCUMENT_PORTS(
173 )
174
175 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
176 {"port", "Slot to load the real PortInterface object", "SST::CoreTest::MessageMesh::PortInterface" }
177 )
178
179 PortSlot(ComponentId_t id, Params& params);
180 ~PortSlot() {}
181
182 void send(MessageEvent* ev) override { port->send(ev); }
183 void setNotifyOnReceive(HandlerBase* functor) override { port->setNotifyOnReceive(functor); }
184
185private:
186 PortInterface* port;
187};
188
189
190class MessagePort : public PortInterface
191{
192public:
193 // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
194 SST_ELI_REGISTER_SUBCOMPONENT(
196 "coreTestElement",
197 "message_mesh.message_port",
198 SST_ELI_ELEMENT_VERSION(1,0,0),
199 "SubComponent implementing PortInterface for sending and receiving messages",
201 )
202
203 SST_ELI_DOCUMENT_PARAMS(
204 )
205
206 SST_ELI_DOCUMENT_STATISTICS(
207 )
208
209 SST_ELI_DOCUMENT_PORTS(
210 {"port", "Port to send or receive on", { "" } },
211 )
212
213 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
214 )
215
216 MessagePort(ComponentId_t id, Params& params);
217 ~MessagePort() {}
218
219 void send(MessageEvent* ev) override;
220 void handleEvent(Event* ev);
221
222private:
223 Link* link;
224};
225
226class RouteMessage : public RouteInterface
227{
228public:
229 // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
230 SST_ELI_REGISTER_SUBCOMPONENT(
232 "coreTestElement",
233 "message_mesh.route_message",
234 SST_ELI_ELEMENT_VERSION(1,0,0),
235 "SubComponent implementing message routing",
237 )
238
239 SST_ELI_DOCUMENT_PARAMS(
240 )
241
242 SST_ELI_DOCUMENT_STATISTICS(
243 {"msg_count", "Message counter", "count", 1},
244 )
245
246 SST_ELI_DOCUMENT_PORTS(
247 )
248
249 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
250 )
251
252 RouteMessage(ComponentId_t id, Params& params, const std::vector<PortInterface*>& ports, int my_id);
253 ~RouteMessage() {}
254
255 void send(MessageEvent* ev, int incoming_port) override;
256
257private:
258 const std::vector<PortInterface*> ports;
259 int my_id;
260 SST::RNG::Random* rng;
261
263};
264
265} // namespace SST::CoreTest::MessageMesh
266
267#endif // SST_CORE_CORETEST_MESSAGEMESH_ENCLOSINGCOMPONENT_H
Main component object for the simulation.
Definition component.h:31
Definition enclosingComponent.h:109
void finish() override
Called after complete phase, but before objects are destroyed.
Definition enclosingComponent.cc:72
void setup() override
Called after all components have been constructed and initialization has completed,...
Definition enclosingComponent.cc:60
Definition messageEvent.h:20
Definition enclosingComponent.h:191
Definition enclosingComponent.h:29
SSTHandler2< void, Event *, classT, dataT, funcT > Handler2
Used to create checkpointable handlers to notify the component when a message has arrived.
Definition enclosingComponent.h:85
SSTHandlerBase< void, Event * > HandlerBase
Base handler for event delivery.
Definition enclosingComponent.h:41
SSTHandler< void, Event *, classT, dataT > Handler
Used to create handlers to notify the component when a message has arrived.
Definition enclosingComponent.h:63
Definition enclosingComponent.h:96
Definition enclosingComponent.h:227
Base class for Events - Items sent across links to communicate between components.
Definition event.h:35
Parameter store.
Definition params.h:58
Implements the base class for random number generators for the SST core.
Definition rng.h:29
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
Forms the template defined base class for statistics gathering within SST.
Definition statbase.h:373
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition subcomponent.h:29