SST  10.0.0
StructuralSimulationToolkit
configGraph.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2020 NTESS. Under the terms
4 // of Contract DE-NA0003525 with NTESS, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2020, NTESS
8 // All rights reserved.
9 //
10 // This file is part of the SST software package. For license
11 // information, see the LICENSE file in the top level directory of the
12 // distribution.
13 
14 #ifndef SST_CORE_CONFIGGRAPH_H
15 #define SST_CORE_CONFIGGRAPH_H
16 
17 #include "sst/core/sst_types.h"
18 
19 #include <vector>
20 #include <map>
21 #include <set>
22 #include <climits>
23 
24 #include "sst/core/sparseVectorMap.h"
25 #include "sst/core/params.h"
26 #include "sst/core/statapi/statbase.h"
27 #include "sst/core/statapi/statoutput.h"
28 #include "sst/core/rankInfo.h"
29 #include "sst/core/unitAlgebra.h"
30 
31 #include "sst/core/serialization/serializable.h"
32 
33 using namespace SST::Statistics;
34 
35 namespace SST {
36 
37 
38 class Simulation;
39 
40 class Config;
41 class TimeLord;
42 class ConfigGraph;
43 
44 typedef SparseVectorMap<ComponentId_t> ComponentIdMap_t;
45 typedef std::vector<LinkId_t> LinkIdMap_t;
46 
47 
48 /** Represents the configuration of a generic Link */
50 public:
51  LinkId_t id; /*!< ID of this link */
52  std::string name; /*!< Name of this link */
53  ComponentId_t component[2]; /*!< IDs of the connected components */
54  std::string port[2]; /*!< Names of the connected ports */
55  SimTime_t latency[2]; /*!< Latency from each side */
56  std::string latency_str[2];/*!< Temp string holding latency */
57  int current_ref; /*!< Number of components currently referring to this Link */
58  bool no_cut; /*!< If set to true, partitioner will not make a cut through this Link */
59 
60  // inline const std::string& key() const { return name; }
61  inline LinkId_t key() const { return id; }
62 
63  /** Return the minimum latency of this link (from both sides) */
64  SimTime_t getMinLatency() const {
65  if ( latency[0] < latency[1] ) return latency[0];
66  return latency[1];
67  }
68 
69  /** Print the Link information */
70  void print(std::ostream &os) const {
71  os << "Link " << name << " (id = " << id << ")" << std::endl;
72  os << " component[0] = " << component[0] << std::endl;
73  os << " port[0] = " << port[0] << std::endl;
74  os << " latency[0] = " << latency[0] << std::endl;
75  os << " component[1] = " << component[1] << std::endl;
76  os << " port[1] = " << port[1] << std::endl;
77  os << " latency[1] = " << latency[1] << std::endl;
78  }
79 
80  /* Do not use. For serialization only */
81  ConfigLink() {}
82 
83  void serialize_order(SST::Core::Serialization::serializer &ser) override {
84  ser & id;
85  ser & name;
86  ser & component[0];
87  ser & component[1];
88  ser & port[0];
89  ser & port[1];
90  ser & latency[0];
91  ser & latency[1];
92  ser & current_ref;
93  }
94 
95  ImplementSerializable(SST::ConfigLink)
96 
97 private:
98  friend class ConfigGraph;
99  ConfigLink(LinkId_t id) :
100  id(id),
101  no_cut(false)
102  {
103  current_ref = 0;
104 
105  // Initialize the component data items
106  component[0] = ULONG_MAX;
107  component[1] = ULONG_MAX;
108  }
109 
110  ConfigLink(LinkId_t id, const std::string& n) :
111  id(id),
112  no_cut(false)
113  {
114  current_ref = 0;
115  name = n;
116 
117  // Initialize the component data items
118  component[0] = ULONG_MAX;
119  component[1] = ULONG_MAX;
120  }
121 
122  void updateLatencies(TimeLord*);
123 
124 
125 };
126 
127 
128 
130 public:
131  std::string name;
132  std::map<std::string, Params> statMap;
133  std::vector<ComponentId_t> components;
134  size_t outputID;
135  UnitAlgebra outputFrequency;
136 
137  ConfigStatGroup(const std::string& name) : name(name), outputID(0) { }
138  ConfigStatGroup() {} /* Do not use */
139 
140 
141  bool addComponent(ComponentId_t id);
142  bool addStatistic(const std::string& name, Params &p);
143  bool setOutput(size_t id);
144  bool setFrequency(const std::string& freq);
145 
146  /**
147  * Checks to make sure that all components in the group support all
148  * of the statistics as configured in the group.
149  * @return pair of: bool for OK, string for error message (if any)
150  */
151  std::pair<bool, std::string> verifyStatsAndComponents(const ConfigGraph* graph);
152 
153 
154 
155  void serialize_order(SST::Core::Serialization::serializer &ser) override {
156  ser & name;
157  ser & statMap;
158  ser & components;
159  ser & outputID;
160  ser & outputFrequency;
161  }
162 
163  ImplementSerializable(SST::ConfigStatGroup)
164 
165 };
166 
167 
169 public:
170 
171  std::string type;
172  Params params;
173 
174  ConfigStatOutput(const std::string& type) : type(type) { }
175  ConfigStatOutput() { }
176 
177  void addParameter(const std::string& key, const std::string& val) {
178  params.insert(key, val);
179  }
180 
181  void serialize_order(SST::Core::Serialization::serializer &ser) override {
182  ser & type;
183  ser & params;
184  }
185 
186  ImplementSerializable(SST::ConfigStatOutput)
187 };
188 
189 
191 
192 /** Represents the configuration of a generic component */
194 public:
195  ComponentId_t id; /*!< Unique ID of this component */
196  ConfigGraph* graph; /*!< Graph that this component belongs to */
197  std::string name; /*!< Name of this component, or slot name for subcomp */
198  int slot_num; /*!< Slot number. Only valid for subcomponents */
199  std::string type; /*!< Type of this component */
200  float weight; /*!< Partitioning weight for this component */
201  RankInfo rank; /*!< Parallel Rank for this component */
202  std::vector<LinkId_t> links; /*!< List of links connected */
203  Params params; /*!< Set of Parameters */
204  uint8_t statLoadLevel; /*!< Statistic load level for this component */
205  std::vector<Statistics::StatisticInfo> enabledStatistics; /*!< List of statistics to be enabled */
206  std::vector<ConfigComponent> subComponents; /*!< List of subcomponents */
207  std::vector<double> coords;
208  uint16_t nextSubID; /*!< Next subID to use for children, if component, if subcomponent, subid of parent */
209 
210  static constexpr ComponentId_t null_id = std::numeric_limits<ComponentId_t>::max();
211 
212  inline const ComponentId_t& key()const { return id; }
213 
214  /** Print Component information */
215  void print(std::ostream &os) const;
216 
217  ConfigComponent cloneWithoutLinks() const;
218  ConfigComponent cloneWithoutLinksOrParams() const;
219 
220  ~ConfigComponent() {}
221  ConfigComponent() : id(null_id), statLoadLevel(STATISTICLOADLEVELUNINITIALIZED), nextSubID(1) { }
222 
223  ComponentId_t getNextSubComponentID();
224 
225  ConfigComponent* getParent() const;
226  std::string getFullName() const;
227 
228 
229  void setRank(RankInfo r);
230  void setWeight(double w);
231  void setCoordinates(const std::vector<double> &c);
232  void addParameter(const std::string& key, const std::string& value, bool overwrite);
233  ConfigComponent* addSubComponent(ComponentId_t, const std::string& name, const std::string& type, int slot);
234  ConfigComponent* findSubComponent(ComponentId_t);
235  const ConfigComponent* findSubComponent(ComponentId_t) const;
236  ConfigComponent* findSubComponentByName(const std::string& name);
237  void enableStatistic(const std::string& statisticName, bool recursively = false);
238  void addStatisticParameter(const std::string& statisticName, const std::string& param, const std::string& value, bool recursively = false);
239  void setStatisticParameters(const std::string& statisticName, const Params &params, bool recursively = false);
240  void setStatisticLoadLevel(uint8_t level, bool recursively = false);
241 
242  std::vector<LinkId_t> allLinks() const;
243 
244  void serialize_order(SST::Core::Serialization::serializer &ser) override {
245  ser & id;
246  ser & name;
247  ser & slot_num;
248  ser & type;
249  ser & weight;
250  ser & rank.rank;
251  ser & rank.thread;
252  ser & links;
253  ser & params;
254  ser & statLoadLevel;
255  ser & enabledStatistics;
256  ser & subComponents;
257  ser & coords;
258  ser & nextSubID;
259  }
260 
261  ImplementSerializable(SST::ConfigComponent)
262 
263 private:
264 
265  friend class ConfigGraph;
266  /** Create a new Component */
267  ConfigComponent(ComponentId_t id, ConfigGraph* graph, const std::string& name, const std::string& type, float weight, RankInfo rank) :
268  id(id),
269  graph(graph),
270  name(name),
271  type(type),
272  weight(weight),
273  rank(rank),
274  statLoadLevel(STATISTICLOADLEVELUNINITIALIZED),
275  nextSubID(1)
276  {
277  coords.resize(3, 0.0);
278  }
279 
280  ConfigComponent(ComponentId_t id, ConfigGraph* graph, uint16_t parent_subid, const std::string& name, int slot_num, const std::string& type, float weight, RankInfo rank) :
281  id(id),
282  graph(graph),
283  name(name),
284  slot_num(slot_num),
285  type(type),
286  weight(weight),
287  rank(rank),
288  statLoadLevel(STATISTICLOADLEVELUNINITIALIZED),
289  nextSubID(parent_subid)
290  {
291  coords.resize(3, 0.0);
292  }
293 
294 
295 };
296 
297 
298 
299 /** Map names to Links */
300 // typedef std::map<std::string,ConfigLink> ConfigLinkMap_t;
301 // typedef SparseVectorMap<std::string,ConfigLink> ConfigLinkMap_t;
302 /** Map IDs to Components */
303 typedef SparseVectorMap<ComponentId_t,ConfigComponent> ConfigComponentMap_t;
304 /** Map names to Components */
305 // typedef std::map<std::string,ConfigComponent*> ConfigComponentNameMap_t;
306 /** Map names to Parameter Sets: XML only */
307 typedef std::map<std::string,Params*> ParamsMap_t;
308 /** Map names to variable values: XML only */
309 typedef std::map<std::string,std::string> VariableMap_t;
310 
311 class PartitionGraph;
312 
313 /** A Configuration Graph
314  * A graph representing Components and Links
315  */
316 class ConfigGraph : public SST::Core::Serialization::serializable {
317 public:
318  /** Print the configuration graph */
319  void print(std::ostream &os) const {
320  os << "Printing graph" << std::endl;
321  for (ConfigComponentMap_t::const_iterator i = comps.begin() ; i != comps.end() ; ++i) {
322  i->print(os);
323  }
324  }
325 
326  ConfigGraph() {
327  links.clear();
328  comps.clear();
329  // Init the statistic output settings
330  statLoadLevel = STATISTICSDEFAULTLOADLEVEL;
331  statOutputs.emplace_back(STATISTICSDEFAULTOUTPUTNAME);
332  }
333 
334  size_t getNumComponents() { return comps.data.size(); }
335 
336  /** Helper function to set all the ranks to the same value */
337  void setComponentRanks(RankInfo rank);
338  /** Checks to see if rank contains at least one component */
339  bool containsComponentInRank(RankInfo rank);
340  /** Verify that all components have valid Ranks assigned */
341  bool checkRanks(RankInfo ranks);
342 
343 
344  // API for programmatic initialization
345  /** Create a new component with weight and rank */
346  ComponentId_t addComponent(ComponentId_t id, const std::string& name, const std::string& type, float weight, RankInfo rank);
347  /** Create a new component */
348  ComponentId_t addComponent(ComponentId_t id, const std::string& name, const std::string& type);
349 
350 
351  /** Set the statistic output module */
352  void setStatisticOutput(const std::string& name);
353 
354  /** Add parameter to the statistic output module */
355  void addStatisticOutputParameter(const std::string& param, const std::string& value);
356 
357  /** Set a set of parameter to the statistic output module */
358  void setStatisticOutputParams(const Params& p);
359 
360  /** Set the statistic system load level */
361  void setStatisticLoadLevel(uint8_t loadLevel);
362 
363  /** Enable a Statistics assigned to a component */
364  void enableStatisticForComponentName(const std::string& ComponentName, const std::string& statisticName, bool recursive = false);
365  void enableStatisticForComponentType(const std::string& ComponentType, const std::string& statisticName, bool recursive = false);
366 
367  /** Add Parameters for a Statistic */
368  void addStatisticParameterForComponentName(const std::string& ComponentName, const std::string& statisticName, const std::string& param, const std::string& value, bool recursively);
369  void addStatisticParameterForComponentType(const std::string& ComponentType, const std::string& statisticName, const std::string& param, const std::string& value, bool recursively);
370  void setStatisticLoadLevelForComponentType(const std::string& compType, uint8_t level, bool recursively = false);
371 
372  std::vector<ConfigStatOutput>& getStatOutputs() {return statOutputs;}
373  const ConfigStatOutput& getStatOutput(size_t index = 0) const {return statOutputs[index];}
374  long getStatLoadLevel() const {return statLoadLevel;}
375 
376  /** Add a Link to a Component on a given Port */
377  void addLink(ComponentId_t comp_id, const std::string& link_name, const std::string& port, const std::string& latency_str, bool no_cut = false);
378 
379  /** Set a Link to be no-cut */
380  void setLinkNoCut(const std::string& link_name);
381 
382  /** Perform any post-creation cleanup processes */
383  void postCreationCleanup();
384 
385  /** Check the graph for Structural errors */
386  bool checkForStructuralErrors();
387 
388  // Temporary until we have a better API
389  /** Return the map of components */
391  return comps;
392  }
393 
394  const std::map<std::string, ConfigStatGroup>& getStatGroups() const { return statGroups; }
395  ConfigStatGroup* getStatGroup(const std::string& name) {
396  auto found = statGroups.find(name);
397  if ( found == statGroups.end() ) {
398  bool ok;
399  std::tie(found, ok) = statGroups.emplace(name, name);
400  }
401  return &(found->second);
402  }
403 
404  bool containsComponent(ComponentId_t id) const;
405  ConfigComponent* findComponent(ComponentId_t);
406  const ConfigComponent* findComponent(ComponentId_t) const;
407 
408  /** Return the map of links */
410  return links;
411  }
412 
413  ConfigGraph* getSubGraph(uint32_t start_rank, uint32_t end_rank);
414  ConfigGraph* getSubGraph(const std::set<uint32_t>& rank_set);
415 
416  PartitionGraph* getPartitionGraph();
417  PartitionGraph* getCollapsedPartitionGraph();
418  void annotateRanks(PartitionGraph* graph);
419  void getConnectedNoCutComps(ComponentId_t start, ComponentIdMap_t& group);
420 
421  void serialize_order(SST::Core::Serialization::serializer &ser) override
422  {
423  ser & links;
424  ser & comps;
425  ser & statOutputs;
426  ser & statLoadLevel;
427  ser & statGroups;
428  }
429 
430 private:
431  friend class Simulation;
432  friend class SSTSDLModelDefinition;
433 
434  ConfigLinkMap_t links;
435  ConfigComponentMap_t comps;
436  // ConfigComponentNameMap_t compsByName;
437  std::map<std::string, ConfigStatGroup> statGroups;
438 
439  // temporary as a test
440  std::map<std::string,LinkId_t> link_names;
441 
442  std::vector<ConfigStatOutput> statOutputs; // [0] is default
443  uint8_t statLoadLevel;
444 
445  ImplementSerializable(SST::ConfigGraph)
446 
447 };
448 
449 
451 public:
452  ComponentId_t id;
453  float weight;
454  RankInfo rank;
455  LinkIdMap_t links;
456 
457  ComponentIdMap_t group;
458 
460  id = cc.id;
461  weight = cc.weight;
462  rank = cc.rank;
463  }
464 
465  PartitionComponent(LinkId_t id) :
466  id(id),
467  weight(0),
468  rank(RankInfo(RankInfo::UNASSIGNED, 0))
469  {}
470 
471  // PartitionComponent(ComponentId_t id, ConfigGraph* graph, const ComponentIdMap_t& group);
472  void print(std::ostream &os, const PartitionGraph* graph) const;
473 
474  inline ComponentId_t key() const { return id; }
475 
476 };
477 
479 public:
480  LinkId_t id;
481  ComponentId_t component[2];
482  SimTime_t latency[2];
483  bool no_cut;
484 
485  PartitionLink(const ConfigLink& cl) {
486  id = cl.id;
487  component[0] = cl.component[0];
488  component[1] = cl.component[1];
489  latency[0] = cl.latency[0];
490  latency[1] = cl.latency[1];
491  no_cut = cl.no_cut;
492  }
493 
494  inline LinkId_t key() const { return id; }
495 
496  /** Return the minimum latency of this link (from both sides) */
497  SimTime_t getMinLatency() const {
498  if ( latency[0] < latency[1] ) return latency[0];
499  return latency[1]; }
500 
501  /** Print the Link information */
502  void print(std::ostream &os) const {
503  os << " Link " << id << std::endl;
504  os << " component[0] = " << component[0] << std::endl;
505  os << " latency[0] = " << latency[0] << std::endl;
506  os << " component[1] = " << component[1] << std::endl;
507  os << " latency[1] = " << latency[1] << std::endl;
508  }
509 };
510 
511 typedef SparseVectorMap<ComponentId_t,PartitionComponent> PartitionComponentMap_t;
512 typedef SparseVectorMap<LinkId_t,PartitionLink> PartitionLinkMap_t;
513 
515 private:
517  PartitionLinkMap_t links;
518 
519 public:
520  /** Print the configuration graph */
521  void print(std::ostream &os) const {
522  os << "Printing graph" << std::endl;
523  for (PartitionComponentMap_t::const_iterator i = comps.begin() ; i != comps.end() ; ++i) {
524  i->print(os,this);
525  }
526  }
527 
528  PartitionComponentMap_t& getComponentMap() {
529  return comps;
530  }
531  PartitionLinkMap_t& getLinkMap() {
532  return links;
533  }
534 
535  const PartitionLink& getLink(LinkId_t id) const {
536  return links[id];
537  }
538 
539  size_t getNumComponents() { return comps.size(); }
540 
541 };
542 
543 } // namespace SST
544 
545 #endif // SST_CORE_CONFIGGRAPH_H
int slot_num
Definition: configGraph.h:198
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
float weight
Definition: configGraph.h:200
ConfigComponentMap_t & getComponentMap()
Return the map of components.
Definition: configGraph.h:390
Represents the configuration of a generic component.
Definition: configGraph.h:193
Definition: configGraph.h:514
std::string type
Definition: configGraph.h:199
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:316
void print(std::ostream &os) const
Print the configuration graph.
Definition: configGraph.h:521
std::vector< Statistics::StatisticInfo > enabledStatistics
Definition: configGraph.h:205
Definition: configGraph.h:450
RankInfo rank
Definition: configGraph.h:201
uint16_t nextSubID
Definition: configGraph.h:208
uint8_t statLoadLevel
Definition: configGraph.h:204
Definition: serializable.h:109
ConfigLinkMap_t & getLinkMap()
Return the map of links.
Definition: configGraph.h:409
ComponentId_t id
Definition: configGraph.h:195
Definition: rankInfo.h:21
Params params
Definition: configGraph.h:203
void print(std::ostream &os) const
Print the configuration graph.
Definition: configGraph.h:319
std::vector< LinkId_t > links
Definition: configGraph.h:202
Parameter store.
Definition: params.h:44
Definition: configGraph.h:168
std::string name
Definition: configGraph.h:197
Definition: configGraph.h:129
ConfigGraph * graph
Definition: configGraph.h:196
std::vector< ConfigComponent > subComponents
Definition: configGraph.h:206
Performs Unit math in full precision.
Definition: unitAlgebra.h:107