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