SST  11.0.0
StructuralSimulationToolkit
coreTest_SubComponent.h
1 // Copyright 2009-2021 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-2021, NTESS
6 // All rights reserved.
7 //
8 // Portions are copyright of other developers:
9 // See the file CONTRIBUTORS.TXT in the top level directory
10 // the distribution for more information.
11 //
12 // This file is part of the SST software package. For license
13 // information, see the LICENSE file in the top level directory of the
14 // distribution.
15 
16 #ifndef _CORETESTSUBCOMPONENT_H
17 #define _CORETESTSUBCOMPONENT_H
18 
19 #include <vector>
20 
21 #include <sst/core/component.h>
22 #include <sst/core/subcomponent.h>
23 #include <sst/core/link.h>
24 
25 namespace SST {
26 namespace CoreTestSubComponent {
27 
28 /*
29 
30  CoreTestSubComponent will test the various ways to use SubComponents.
31  The SubComponents will be loadable as both named and unnamed
32  SubComponets. When an unname SubComponent is used, it inherits the
33  port interface from the BaseComponent that created it. A named
34  SubComponent owns it's own ports and will mask the ports from any
35  BaseComponent higher in the call tree.
36 
37  Each BaseComponent will have a port(s) that may or may not be used
38  depending on the configuration.
39 
40  Configurations to be supported:
41 
42  */
43 
44 
46 {
47 public:
48  SubCompInterface(ComponentId_t id) :
49  SubComponent(id)
50  { }
51  SubCompInterface(ComponentId_t id, Params& UNUSED(params)) :
52  SubComponent(id)
53  { }
54  virtual ~SubCompInterface() {}
55  virtual void clock(SST::Cycle_t) {}
56 
57 
58  // typedef std::tuple<int,int> ELI_CONSTRUCTOR_PARAMS;
59 
60  // template <class... ARGS>
61  // static ELI_CONSTRUCTOR_PARAMS convert(ARGS... args) {
62  // return std::make_tuple<ARGS...>(std::forward<ARGS>(args)...);
63  // }
64 
65  SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTestSubComponent::SubCompInterface)
66  // SST_ELI_DECLARE_NEW_BASE(SubComponent,SubCompInterface)
67  // SST_ELI_NEW_BASE_CTOR(ComponentId_t,Params&)
68 
69  SST_ELI_REGISTER_SUBCOMPONENT_DERIVED(
71  "coreTestElement",
72  "SubCompInterface",
73  SST_ELI_ELEMENT_VERSION(1,0,0),
74  "Default implementation of SubCompInterface",
76  )
77 
78 };
79 
80 /* Our trivial component */
82 {
83 public:
84  // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
85  SST_ELI_REGISTER_COMPONENT(SubComponentLoader,
86  "coreTestElement",
87  "SubComponentLoader",
88  SST_ELI_ELEMENT_VERSION(1,0,0),
89  "Demonstrates subcomponents",
90  COMPONENT_CATEGORY_UNCATEGORIZED
91  )
92 
93  SST_ELI_DOCUMENT_PARAMS(
94  {"clock", "Clock Rate", "1GHz"},
95  {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""},
96  {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"},
97  )
98 
99  SST_ELI_DOCUMENT_STATISTICS(
100  {"totalSent", "# of total messages sent", "", 1},
101  )
102 
103  // This ports will be used only by unnamed SubComponents
104  SST_ELI_DOCUMENT_PORTS(
105  {"port%(num_subcomps)d", "Sending or Receiving Port(s)", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
106  )
107 
108  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
109  {"mySubComp", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
110  )
111 
112  SubComponentLoader(ComponentId_t id, SST::Params& params);
113 
114 private:
115 
116  bool tick(SST::Cycle_t);
117  std::vector<SubCompInterface*> subComps;
118 };
119 
120 
121 /* Our example subcomponents */
122 
123 
125 {
126 public:
127 
128  SST_ELI_REGISTER_SUBCOMPONENT_DERIVED(
129  SubCompSlot,
130  "coreTestElement",
131  "SubCompSlot",
132  SST_ELI_ELEMENT_VERSION(1,0,0),
133  "Subcomponent which is just a wrapper for the actual SubComponent to be used",
135  )
136 
137 
138  SST_ELI_DOCUMENT_PARAMS(
139  {"sendCount", "Number of Messages to Send", "10"},
140  {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""},
141  {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"},
142  )
143 
144  SST_ELI_DOCUMENT_STATISTICS(
145  )
146 
147  // Only used when loading unnamed SubComponents
148  SST_ELI_DOCUMENT_PORTS(
149  {"slot_port%(num_subcomps)d", "Port(s) to send or receive on", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
150  )
151 
152  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
153  {"mySubCompSlot", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
154  )
155 
156 
157 private:
158  std::vector<SubCompInterface*> subComps;
159 
160 public:
161  // Legacy API
162  // New API
163  SubCompSlot(ComponentId_t id, Params& params);
164  // Direct load
165  SubCompSlot(ComponentId_t id, std::string unnamed_sub);
166 
167 //SubCompSlot(ComponentId_t id) : SubCompInterface(id) {}
168  ~SubCompSlot() {}
169  void clock(Cycle_t);
170 
171 };
172 
173 
174 
175 
177 {
178 public:
179 
180  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
181  SST_ELI_REGISTER_SUBCOMPONENT_DERIVED(
183  "coreTestElement",
184  "SubCompSender",
185  SST_ELI_ELEMENT_VERSION(1,0,0),
186  "Sending Subcomponent",
188  )
189 
190  SST_ELI_DOCUMENT_PARAMS(
191  {"port_name", "Name of port to connect to", ""},
192  {"sendCount", "Number of Messages to Send", "10"},
193  )
194 
195  SST_ELI_DOCUMENT_STATISTICS(
196  {"numSent", "# of msgs sent", "", 1},
197  )
198 
199  SST_ELI_DOCUMENT_PORTS(
200  {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
201  )
202 
203  // Optional since there is nothing to document
204  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
205  )
206 
207 private:
208  Statistic<uint32_t> *nMsgSent;
209  Statistic<uint32_t> *totalMsgSent;
210  uint32_t nToSend;
211  SST::Link *link;
212 public:
213  // Legacy API
214  // New API
215  SubCompSender(ComponentId_t id, Params &params);
216  // Direct API
217  SubCompSender(ComponentId_t id, uint32_t nToSend, const std::string& port_name);
218  ~SubCompSender() {}
219  void clock(Cycle_t);
220 
221 };
222 
223 
225 {
226 
227 public:
228 
229  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
230  SST_ELI_REGISTER_SUBCOMPONENT_DERIVED(
232  "coreTestElement",
233  "SubCompReceiver",
234  SST_ELI_ELEMENT_VERSION(1,0,0),
235  "Receiving Subcomponent",
237  )
238 
239 
240  // Optional since there is nothing to document
241  SST_ELI_DOCUMENT_PARAMS(
242  )
243 
244  SST_ELI_DOCUMENT_STATISTICS(
245  {"numRecv", "# of msgs recv", "", 1},
246  )
247 
248  SST_ELI_DOCUMENT_PORTS(
249  {"recvPort", "Receiving Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
250  )
251 
252  // Optional since there is nothing to document
253  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
254  )
255 
256 private:
257 
258  Statistic<uint32_t> *nMsgReceived;
259  SST::Link *link;
260 
261  void handleEvent(SST::Event *ev);
262 
263 public:
264  SubCompReceiver(ComponentId_t id, Params &params);
265  SubCompReceiver(ComponentId_t id, std::string port) ;
266  ~SubCompReceiver() {}
267  void clock(Cycle_t);
268 
269 };
270 
271 } // namespace CoreTestSubComponent
272 } // namespace SST
273 
274 
275 
276 
277 #endif /* _CORETESTSUBCOMPONENT_H */
Definition: coreTest_SubComponent.h:45
Main component object for the simulation.
Definition: component.h:31
Definition: coreTest_SubComponent.h:176
Definition: coreTest_SubComponent.h:81
Parameter store.
Definition: params.h:44
Definition: coreTest_SubComponent.h:124
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:31
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29
Definition: coreTest_SubComponent.h:224