SST  14.1.0
StructuralSimulationToolkit
coreTest_SubComponent.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_CORETEST_SUBCOMPONENT_H
13 #define SST_CORE_CORETEST_SUBCOMPONENT_H
14 
15 #include "sst/core/component.h"
16 #include "sst/core/link.h"
17 #include "sst/core/subcomponent.h"
18 
19 #include <vector>
20 
21 namespace SST {
22 namespace CoreTestSubComponent {
23 
24 /*
25 
26  CoreTestSubComponent will test the various ways to use SubComponents.
27  The SubComponents will be loadable as both named and unnamed
28  SubComponets. When an unname SubComponent is used, it inherits the
29  port interface from the BaseComponent that created it. A named
30  SubComponent owns it's own ports and will mask the ports from any
31  BaseComponent higher in the call tree.
32 
33  Each BaseComponent will have a port(s) that may or may not be used
34  depending on the configuration.
35  */
36 
38 {
39 public:
40  SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTestSubComponent::SubCompInterface)
41 
42  SubCompInterface(ComponentId_t id) : SubComponent(id) {}
43  SubCompInterface(ComponentId_t id, Params& UNUSED(params)) : SubComponent(id) {}
45  virtual ~SubCompInterface() {}
46  virtual void clock(SST::Cycle_t) {}
47 
48  void serialize_order(SST::Core::Serialization::serializer& ser) override
49  {
50  SST::SubComponent::serialize_order(ser);
51  }
52  ImplementSerializable(SST::CoreTestSubComponent::SubCompInterface)
53 };
54 
56 {
57 public:
58  SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(SST::CoreTestSubComponent::SubCompSlotInterface,
60 
61  SST_ELI_DOCUMENT_PARAMS(
62  {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"}
63  )
64 
65  SST_ELI_DOCUMENT_PORTS(
66  {"test", "Just a test port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
67  )
68 
69  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
70  )
71 
72  SubCompSlotInterface(ComponentId_t id) : SubCompInterface(id) {}
73  SubCompSlotInterface(ComponentId_t id, Params& UNUSED(params)) : SubCompInterface(id) {}
74  virtual ~SubCompSlotInterface() {}
75 
77  void serialize_order(SST::Core::Serialization::serializer& ser) override { SubCompInterface::serialize_order(ser); }
79 };
80 
81 /* Our trivial component */
83 {
84 public:
85  // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
86  SST_ELI_REGISTER_COMPONENT(
88  "coreTestElement",
89  "SubComponentLoader",
90  SST_ELI_ELEMENT_VERSION(1,0,0),
91  "Demonstrates subcomponents",
92  COMPONENT_CATEGORY_UNCATEGORIZED
93  )
94 
95  SST_ELI_DOCUMENT_PARAMS(
96  {"clock", "Clock Rate", "1GHz"},
97  {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""},
98  {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"},
99  {"verbose", "Verbosity level", "0"},
100  )
101 
102  SST_ELI_DOCUMENT_STATISTICS(
103  {"totalSent", "# of total messages sent", "", 1},
104  )
105 
106  // This ports will be used only by unnamed SubComponents
107  SST_ELI_DOCUMENT_PORTS(
108  {"port%d", "Sending or Receiving Port(s)", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
109  )
110 
111  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
112  {"mySubComp", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
113  )
114 
115  SubComponentLoader(ComponentId_t id, SST::Params& params);
116 
117  SubComponentLoader() {}
118  void serialize_order(SST::Core::Serialization::serializer& ser) override
119  {
120  SST::Component::serialize_order(ser);
121  SST_SER(count)
122  SST_SER(subComps)
123  }
124  ImplementSerializable(SST::CoreTestSubComponent::SubComponentLoader)
125 
126 private:
127  uint32_t count = 0;
128  bool tick(SST::Cycle_t);
129  std::vector<SubCompInterface*> subComps;
130 };
131 
132 /* Our example subcomponents */
134 {
135 public:
136  SST_ELI_REGISTER_SUBCOMPONENT(
137  SubCompSlot,
138  "coreTestElement",
139  "SubCompSlot",
140  SST_ELI_ELEMENT_VERSION(1,0,0),
141  "Subcomponent which is just a wrapper for the actual SubComponent to be used",
143  )
144 
145  SST_ELI_DOCUMENT_PARAMS(
146  {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""},
147  {"verbose", "Verbosity level", "0"},
148  )
149 
150  // Only used when loading unnamed SubComponents
151  SST_ELI_DOCUMENT_PORTS(
152  {"slot_port%d", "Port(s) to send or receive on", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
153  )
154 
155  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
156  {"mySubCompSlot", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
157  )
158 
159  SubCompSlot() {}
160  void serialize_order(SST::Core::Serialization::serializer& ser) override
161  {
162  SubCompSlotInterface::serialize_order(ser);
163  SST_SER(subComps)
164  }
165  ImplementSerializable(SST::CoreTestSubComponent::SubCompSlot)
166 
167 private:
168  std::vector<SubCompInterface*> subComps;
169 
170 public:
171  SubCompSlot(ComponentId_t id, Params& params);
172  // Direct load
173  SubCompSlot(ComponentId_t id, std::string unnamed_sub);
174 
175  ~SubCompSlot() {}
176  void clock(Cycle_t) override;
177 };
178 
179 // Add in some extra levels of ELI hierarchy for testing
181 {
182 public:
183  SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(SST::CoreTestSubComponent::SubCompSendRecvInterface,
185 
186  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
187  SST_ELI_REGISTER_SUBCOMPONENT(
189  "coreTestElement",
190  "SubCompSendRecv",
191  SST_ELI_ELEMENT_VERSION(1,0,0),
192  "Default Subcomponent for ELI testing only",
194  )
195 
196  SST_ELI_DOCUMENT_PARAMS(
197  {"port_name", "Name of port to connect to", ""},
198  {"sendCount", "Number of Messages to Send", "10"},
199  {"verbose", "Verbosity level", "0"}
200  )
201 
202  SST_ELI_DOCUMENT_PORTS(
203  {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
204  // The following port is a test to make sure that when loaded
205  // anonymously, a port that's named the same as one of its
206  // parent's ports doesn't conflict.
207  {"slot_port%d", "This is just a test port that duplicates a port from the SubComponent that will instance it", { "", "" } },
208  )
209 
210  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
211  )
212 
213  SST_ELI_DOCUMENT_STATISTICS(
214  {"numRecv", "# of msgs recv", "", 1},
215  )
216 
217 
218  SubCompSendRecvInterface(ComponentId_t id) : SubCompInterface(id) {}
219  SubCompSendRecvInterface(ComponentId_t id, Params& UNUSED(params)) : SubCompInterface(id) {}
220  virtual ~SubCompSendRecvInterface() {}
221 
223  void serialize_order(SST::Core::Serialization::serializer& ser) override { SubCompInterface::serialize_order(ser); }
225 };
226 
228 {
229 public:
230  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
231  SST_ELI_REGISTER_SUBCOMPONENT(
233  "coreTestElement",
234  "SubCompSender",
235  SST_ELI_ELEMENT_VERSION(1,0,0),
236  "Sending Subcomponent",
238  )
239 
240  SST_ELI_DOCUMENT_PARAMS(
241  )
242 
243  SST_ELI_DOCUMENT_STATISTICS(
244  SST_ELI_DELETE_STAT("numRecv"),
245  {"numSent", "# of msgs sent", "", 1},
246  )
247 
248  SST_ELI_DOCUMENT_PORTS(
249  {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
250  )
251 
252  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
253  {"test_slot", "Test slot", "" }
254  )
255 
256  SubCompSender() {}
257  void serialize_order(SST::Core::Serialization::serializer& ser) override
258  {
259  SubCompSendRecvInterface::serialize_order(ser);
260  SST_SER(link)
261  SST_SER(nToSend)
262  SST_SER(nMsgSent)
263  SST_SER(totalMsgSent)
264  SST_SER(out)
265  }
266  ImplementSerializable(SST::CoreTestSubComponent::SubCompSender)
267 
268 private:
269  Statistic<uint32_t>* nMsgSent;
270  Statistic<uint32_t>* totalMsgSent;
271  uint32_t nToSend;
272  SST::Link* link;
273  SST::Output* out;
274 
275 public:
276  SubCompSender(ComponentId_t id, Params& params);
277  // Direct API
278  SubCompSender(ComponentId_t id, uint32_t nToSend, const std::string& port_name);
279  ~SubCompSender() {}
280  void clock(Cycle_t) override;
281 };
282 
284 {
285 
286 public:
287  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
288  SST_ELI_REGISTER_SUBCOMPONENT(
290  "coreTestElement",
291  "SubCompReceiver",
292  SST_ELI_ELEMENT_VERSION(1,0,0),
293  "Receiving Subcomponent",
295  )
296 
297  // Optional since there is nothing to document
298  SST_ELI_DOCUMENT_PARAMS(
299  SST_ELI_DELETE_PARAM("sendCount")
300  )
301 
302  SST_ELI_DOCUMENT_STATISTICS(
303  )
304 
305  SST_ELI_DOCUMENT_PORTS(
306  SST_ELI_DELETE_PORT("sendPort"),
307  {"recvPort", "Receiving Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
308  )
309 
310  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
311  SST_ELI_DELETE_SUBCOMPONENT_SLOT("test_slot")
312  )
313 
314  SubCompReceiver() {}
315  void serialize_order(SST::Core::Serialization::serializer& ser) override
316  {
317  SubCompSendRecvInterface::serialize_order(ser);
318  SST_SER(link)
319  SST_SER(nMsgReceived)
320  SST_SER(out);
321  }
322  ImplementSerializable(SST::CoreTestSubComponent::SubCompReceiver)
323 
324 private:
325  Statistic<uint32_t>* nMsgReceived;
326  SST::Link* link;
327  SST::Output* out;
328 
329  void handleEvent(SST::Event* ev);
330 
331 public:
332  SubCompReceiver(ComponentId_t id, Params& params);
333  SubCompReceiver(ComponentId_t id, std::string port);
334  ~SubCompReceiver() {}
335  void clock(Cycle_t) override;
336 };
337 
338 } // namespace CoreTestSubComponent
339 } // namespace SST
340 
341 #endif // SST_CORE_CORETEST_SUBCOMPONENT_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
Definition: coreTest_SubComponent.h:37
Definition: coreTest_SubComponent.h:180
Main component object for the simulation.
Definition: component.h:30
Definition: action.cc:18
Definition: coreTest_SubComponent.h:227
Definition: coreTest_SubComponent.h:55
Definition: coreTest_SubComponent.h:82
Parameter store.
Definition: params.h:55
Definition: coreTest_SubComponent.h:133
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:34
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:28
Definition: coreTest_SubComponent.h:283