SST  14.0.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(subComps)
122  }
123  ImplementSerializable(SST::CoreTestSubComponent::SubComponentLoader)
124 
125 private:
126  bool tick(SST::Cycle_t);
127  std::vector<SubCompInterface*> subComps;
128 };
129 
130 /* Our example subcomponents */
132 {
133 public:
134  SST_ELI_REGISTER_SUBCOMPONENT(
135  SubCompSlot,
136  "coreTestElement",
137  "SubCompSlot",
138  SST_ELI_ELEMENT_VERSION(1,0,0),
139  "Subcomponent which is just a wrapper for the actual SubComponent to be used",
141  )
142 
143  SST_ELI_DOCUMENT_PARAMS(
144  {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""},
145  {"verbose", "Verbosity level", "0"},
146  )
147 
148  // Only used when loading unnamed SubComponents
149  SST_ELI_DOCUMENT_PORTS(
150  {"slot_port%d", "Port(s) to send or receive on", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
151  )
152 
153  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
154  {"mySubCompSlot", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
155  )
156 
157  SubCompSlot() {}
158  void serialize_order(SST::Core::Serialization::serializer& ser) override
159  {
160  SubCompSlotInterface::serialize_order(ser);
161  SST_SER(subComps)
162  }
163  ImplementSerializable(SST::CoreTestSubComponent::SubCompSlot)
164 
165 private:
166  std::vector<SubCompInterface*> subComps;
167 
168 public:
169  SubCompSlot(ComponentId_t id, Params& params);
170  // Direct load
171  SubCompSlot(ComponentId_t id, std::string unnamed_sub);
172 
173  ~SubCompSlot() {}
174  void clock(Cycle_t) override;
175 };
176 
177 // Add in some extra levels of ELI hierarchy for testing
179 {
180 public:
181  SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(SST::CoreTestSubComponent::SubCompSendRecvInterface,
183 
184  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
185  SST_ELI_REGISTER_SUBCOMPONENT(
187  "coreTestElement",
188  "SubCompSendRecv",
189  SST_ELI_ELEMENT_VERSION(1,0,0),
190  "Default Subcomponent for ELI testing only",
192  )
193 
194  SST_ELI_DOCUMENT_PARAMS(
195  {"port_name", "Name of port to connect to", ""},
196  {"sendCount", "Number of Messages to Send", "10"},
197  {"verbose", "Verbosity level", "0"}
198  )
199 
200  SST_ELI_DOCUMENT_PORTS(
201  {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
202  // The following port is a test to make sure that when loaded
203  // anonymously, a port that's named the same as one of its
204  // parent's ports doesn't conflict.
205  {"slot_port%d", "This is just a test port that duplicates a port from the SubComponent that will instance it", { "", "" } },
206  )
207 
208  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
209  )
210 
211  SST_ELI_DOCUMENT_STATISTICS(
212  {"numRecv", "# of msgs recv", "", 1},
213  )
214 
215 
216  SubCompSendRecvInterface(ComponentId_t id) : SubCompInterface(id) {}
217  SubCompSendRecvInterface(ComponentId_t id, Params& UNUSED(params)) : SubCompInterface(id) {}
218  virtual ~SubCompSendRecvInterface() {}
219 
221  void serialize_order(SST::Core::Serialization::serializer& ser) override { SubCompInterface::serialize_order(ser); }
223 };
224 
226 {
227 public:
228  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
229  SST_ELI_REGISTER_SUBCOMPONENT(
231  "coreTestElement",
232  "SubCompSender",
233  SST_ELI_ELEMENT_VERSION(1,0,0),
234  "Sending Subcomponent",
236  )
237 
238  SST_ELI_DOCUMENT_PARAMS(
239  )
240 
241  SST_ELI_DOCUMENT_STATISTICS(
242  SST_ELI_DELETE_STAT("numRecv"),
243  {"numSent", "# of msgs sent", "", 1},
244  )
245 
246  SST_ELI_DOCUMENT_PORTS(
247  {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
248  )
249 
250  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
251  {"test_slot", "Test slot", "" }
252  )
253 
254  SubCompSender() {}
255  void serialize_order(SST::Core::Serialization::serializer& ser) override
256  {
257  SubCompSendRecvInterface::serialize_order(ser);
258  SST_SER(link)
259  SST_SER(nToSend)
260  SST_SER(nMsgSent)
261  SST_SER(totalMsgSent)
262  SST_SER(out)
263  }
264  ImplementSerializable(SST::CoreTestSubComponent::SubCompSender)
265 
266 private:
267  Statistic<uint32_t>* nMsgSent;
268  Statistic<uint32_t>* totalMsgSent;
269  uint32_t nToSend;
270  SST::Link* link;
271  SST::Output* out;
272 
273 public:
274  SubCompSender(ComponentId_t id, Params& params);
275  // Direct API
276  SubCompSender(ComponentId_t id, uint32_t nToSend, const std::string& port_name);
277  ~SubCompSender() {}
278  void clock(Cycle_t) override;
279 };
280 
282 {
283 
284 public:
285  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
286  SST_ELI_REGISTER_SUBCOMPONENT(
288  "coreTestElement",
289  "SubCompReceiver",
290  SST_ELI_ELEMENT_VERSION(1,0,0),
291  "Receiving Subcomponent",
293  )
294 
295  // Optional since there is nothing to document
296  SST_ELI_DOCUMENT_PARAMS(
297  SST_ELI_DELETE_PARAM("sendCount")
298  )
299 
300  SST_ELI_DOCUMENT_STATISTICS(
301  )
302 
303  SST_ELI_DOCUMENT_PORTS(
304  SST_ELI_DELETE_PORT("sendPort"),
305  {"recvPort", "Receiving Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
306  )
307 
308  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
309  SST_ELI_DELETE_SUBCOMPONENT_SLOT("test_slot")
310  )
311 
312  SubCompReceiver() {}
313  void serialize_order(SST::Core::Serialization::serializer& ser) override
314  {
315  SubCompSendRecvInterface::serialize_order(ser);
316  SST_SER(link)
317  SST_SER(nMsgReceived)
318  SST_SER(out);
319  }
320  ImplementSerializable(SST::CoreTestSubComponent::SubCompReceiver)
321 
322 private:
323  Statistic<uint32_t>* nMsgReceived;
324  SST::Link* link;
325  SST::Output* out;
326 
327  void handleEvent(SST::Event* ev);
328 
329 public:
330  SubCompReceiver(ComponentId_t id, Params& params);
331  SubCompReceiver(ComponentId_t id, std::string port);
332  ~SubCompReceiver() {}
333  void clock(Cycle_t) override;
334 };
335 
336 } // namespace CoreTestSubComponent
337 } // namespace SST
338 
339 #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:35
Definition: coreTest_SubComponent.h:37
Definition: coreTest_SubComponent.h:178
Main component object for the simulation.
Definition: component.h:30
Definition: action.cc:18
Definition: coreTest_SubComponent.h:225
Definition: coreTest_SubComponent.h:55
Definition: coreTest_SubComponent.h:82
Parameter store.
Definition: params.h:55
Definition: coreTest_SubComponent.h:131
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:281