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