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