SST  14.1.0
StructuralSimulationToolkit
componentInfo.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_COMPONENTINFO_H
13 #define SST_CORE_COMPONENTINFO_H
14 
15 #include "sst/core/params.h"
16 #include "sst/core/serialization/serializer_fwd.h"
17 #include "sst/core/sst_types.h"
18 
19 #include <functional>
20 #include <map>
21 #include <string>
22 #include <unordered_set>
23 
24 namespace SST {
25 
26 class BaseComponent;
27 class ComponentInfoMap;
28 class LinkMap;
29 
30 class ConfigComponent;
31 class ConfigStatistic;
32 
33 class Simulation_impl;
34 class TimeConverter;
35 
36 namespace Core {
37 namespace Serialization {
38 namespace pvt {
39 class SerializeBaseComponentHelper;
40 } // namespace pvt
41 } // namespace Serialization
42 } // namespace Core
43 
45 {
46 
47 public:
48  typedef std::vector<ConfigStatistic> statEnableList_t; /*!< List of Enabled Statistics */
49 
50  // Share Flags for SubComponent loading
51  static const uint64_t SHARE_PORTS = 0x1;
52  static const uint64_t SHARE_STATS = 0x2;
53  static const uint64_t INSERT_STATS = 0x4;
54 
55  static const uint64_t SHARE_NONE = 0x0;
56 
57 private:
58  // Mask to make sure users are only setting the flags that are
59  // available to them
60  static const uint64_t USER_FLAGS = 0x7;
61 
62  // Friend classes
63  friend class Simulation_impl;
64  friend class BaseComponent;
65  friend class ComponentInfoMap;
67 
68  /**
69  Component ID.
70 
71  SubComponents share the lower bits (defined by macros in
72  sst_types.h) with their Component parent. However, every
73  SubComponent has a unique ID.
74  */
75  const ComponentId_t id;
76 
77  ComponentInfo* parent_info;
78  /**
79  Name of the Component/SubComponent.
80  */
81  const std::string name;
82 
83  /**
84  Type of the Component/SubComponent.
85  */
86  const std::string type;
87 
88  /**
89  LinkMap containing the links assigned to this
90  Component/SubComponent in the python file.
91 
92  This field is not used for SubComponents loaded with
93  loadAnonymousSubComponent().
94  */
95  LinkMap* link_map;
96 
97  /**
98  Pointer to the Component created using this ComponentInfo.
99  */
100  BaseComponent* component;
101 
102  /**
103  SubComponents loaded into the Component/SubComponent.
104  */
105  std::map<ComponentId_t, ComponentInfo> subComponents;
106 
107  /**
108  Parameters defined in the python file for the (Sub)Component.
109 
110  This field is used for only a short time while loading for
111  SubComponents loaded with loadAnonymousSubComponent().
112  For python defined SubComponents, this field is created during
113  python execution.
114  */
115  Params* params;
116 
117  TimeConverter* defaultTimeBase;
118 
119  std::map<StatisticId_t, ConfigStatistic>* statConfigs;
120  std::map<std::string, StatisticId_t>* enabledStatNames;
121  bool enabledAllStats;
122  const ConfigStatistic* allStatConfig;
123 
124  uint8_t statLoadLevel;
125 
126  std::vector<double> coordinates;
127 
128  uint64_t subIDIndex;
129 
130  // Variables only used by SubComponents
131 
132  /**
133  Name of the slot this SubComponent was loaded into. This field
134  is not used for Components.
135  */
136  const std::string slot_name;
137 
138  /**
139  Index in the slot this SubComponent was loaded into. This field
140  is not used for Components.
141  */
142  int slot_num;
143 
144  /**
145  Sharing flags.
146 
147  Determines whether various data is shared from parent to child.
148  */
149  uint64_t share_flags;
150 
151  bool sharesPorts() { return (share_flags & SHARE_PORTS) != 0; }
152 
153  bool sharesStatistics() { return (share_flags & SHARE_STATS) != 0; }
154 
155  bool canInsertStatistics() { return (share_flags & INSERT_STATS) != 0; }
156 
157  inline void setComponent(BaseComponent* comp) { component = comp; }
158  // inline void setParent(BaseComponent* comp) { parent = comp; }
159 
160  /* Lookup Key style constructor */
161  ComponentInfo(ComponentId_t id, const std::string& name);
162  void finalizeLinkConfiguration() const;
163  void prepareForComplete() const;
164 
165  ComponentId_t addAnonymousSubComponent(
166  ComponentInfo* parent_info, const std::string& type, const std::string& slot_name, int slot_num,
167  uint64_t share_flags);
168 
169 public:
170  /**
171  Constructor used only for serialization
172  */
173  ComponentInfo();
174 
175  /**
176  Function used to serialize the class
177  */
179  void serialize_comp(SST::Core::Serialization::serializer& ser);
180 
181  /* Old ELI Style subcomponent constructor */
182  ComponentInfo(const std::string& type, const Params* params, const ComponentInfo* parent_info);
183 
184  /* Anonymous SubComponent */
186  ComponentId_t id, ComponentInfo* parent_info, const std::string& type, const std::string& slot_name,
187  int slot_num, uint64_t share_flags /*, const Params& params_in*/);
188 
189  /* New ELI Style */
190  ComponentInfo(ConfigComponent* ccomp, const std::string& name, ComponentInfo* parent_info, LinkMap* link_map);
192  ~ComponentInfo();
193 
194  bool isAnonymous() { return COMPDEFINED_SUBCOMPONENT_ID_MASK(id); }
195 
196  bool isUser() { return !COMPDEFINED_SUBCOMPONENT_ID_MASK(id); }
197 
198  inline ComponentId_t getID() const { return id; }
199 
200  inline const std::string& getName() const
201  {
202  if ( name.empty() && parent_info ) return parent_info->getName();
203  return name;
204  }
205 
206  inline const std::string& getParentComponentName() const
207  {
208  // First, get the actual component (parent pointer will be
209  // nullptr).
210  const ComponentInfo* real_comp = this;
211  while ( real_comp->parent_info != nullptr )
212  real_comp = real_comp->parent_info;
213  return real_comp->getName();
214  }
215 
216  /**
217  Get the short name for this SubComponent (name not including
218  any parents, so just slot_name[index])
219  */
220  inline std::string getShortName() const { return name.substr(name.find_last_of(':') + 1); }
221 
222  inline const std::string& getSlotName() const { return slot_name; }
223 
224  inline int getSlotNum() const { return slot_num; }
225 
226  inline const std::string& getType() const { return type; }
227 
228  inline BaseComponent* getComponent() const { return component; }
229 
230  LinkMap* getLinkMap();
231 
232  inline const Params* getParams() const { return params; }
233 
234  // inline std::map<std::string, ComponentInfo>& getSubComponents() { return subComponents; }
235  inline std::map<ComponentId_t, ComponentInfo>& getSubComponents() { return subComponents; }
236 
237  ComponentInfo* findSubComponent(const std::string& slot, int slot_num);
238  ComponentInfo* findSubComponent(ComponentId_t id);
239  bool hasLinks() const;
240 
241  uint8_t getStatisticLoadLevel() { return statLoadLevel; }
242 
243  struct HashName
244  {
245  size_t operator()(const ComponentInfo* info) const
246  {
247  std::hash<std::string> hash;
248  return hash(info->name);
249  }
250  };
251 
252  struct EqualsName
253  {
254  bool operator()(const ComponentInfo* lhs, const ComponentInfo* rhs) const { return lhs->name == rhs->name; }
255  };
256 
257  struct HashID
258  {
259  size_t operator()(const ComponentInfo* info) const
260  {
261  std::hash<ComponentId_t> hash;
262  return hash(info->id);
263  }
264  };
265 
266  struct EqualsID
267  {
268  bool operator()(const ComponentInfo* lhs, const ComponentInfo* rhs) const { return lhs->id == rhs->id; }
269  };
270 
271  //// Functions used only for testing, they will not create valid
272  //// ComponentInfos for simulation
273 
274  /**
275  (DO NOT USE) Constructor used only for serialization testing
276  */
277  ComponentInfo(ComponentId_t id, const std::string& name, const std::string& slot_name, TimeConverter* tv = nullptr);
278 
280  test_addSubComponentInfo(const std::string& name, const std::string& slot_name, TimeConverter* tv = nullptr);
281 
282  void test_printComponentInfoHierarchy(int index = 0);
283 };
284 
286 {
287 private:
288  std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID> dataByID;
289 
290 public:
291  typedef std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID>::const_iterator
292  const_iterator;
293 
294  const_iterator begin() const { return dataByID.begin(); }
295 
296  const_iterator end() const { return dataByID.end(); }
297 
298  ComponentInfoMap() {}
299 
300  void insert(ComponentInfo* info) { dataByID.insert(info); }
301 
302  ComponentInfo* getByID(const ComponentId_t key) const
303  {
304  ComponentInfo infoKey(COMPONENT_ID_MASK(key), "");
305  auto value = dataByID.find(&infoKey);
306  if ( value == dataByID.end() ) return nullptr;
307  if ( SUBCOMPONENT_ID_MASK(key) != 0 ) {
308  // Looking for a subcomponent
309  return (*value)->findSubComponent(key);
310  }
311  return *value;
312  }
313 
314  bool empty() { return dataByID.empty(); }
315 
316  void clear()
317  {
318  for ( auto i : dataByID ) {
319  delete i;
320  }
321  dataByID.clear();
322  }
323 
324  size_t size() { return dataByID.size(); }
325 };
326 
327 } // namespace SST
328 
329 #endif // SST_CORE_COMPONENTINFO_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
Maps port names to the Links that are connected to it.
Definition: linkMap.h:27
std::string getShortName() const
Get the short name for this SubComponent (name not including any parents, so just slot_name[index]) ...
Definition: componentInfo.h:220
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:27
void serialize_order(SST::Core::Serialization::serializer &ser)
Function used to serialize the class.
Definition: componentInfo.cc:195
Definition: configGraph.h:125
Definition: action.cc:18
Definition: componentInfo.h:266
Definition: componentInfo.h:285
Definition: componentInfo.h:243
Main control class for a SST Simulation.
Definition: simulation_impl.h:76
std::vector< ConfigStatistic > statEnableList_t
Definition: componentInfo.h:48
Main component object for the simulation.
Definition: baseComponent.h:62
Definition: componentInfo.h:257
Definition: componentInfo.h:252
Parameter store.
Definition: params.h:55
ComponentInfo()
Constructor used only for serialization.
Definition: componentInfo.cc:43
Definition: componentInfo.h:44