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