SST  7.1.0
StructuralSimulationToolkit
configGraph.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2017 Sandia Corporation. Under the terms
4 // of Contract DE-NA0003525 with Sandia Corporation, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2017, Sandia Corporation
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 // class ConfigComponent;
192 
193 // class SubComponentSlotDefinition : public SST::Core::Serialization::serializable {
194 
195 // std::string name;
196 // std::vector<ConfigComponent*> slots;
197 
198 // public:
199 
200 // SubComponentSlotDefinition() {}
201 // SubComponentSlotDefinition(const SubComponentSlotDefinition& init) :
202 // name(init.name)
203 // {
204 // for ( auto &cc : init.slots ) {
205 // slots.push_back
206 // }
207 // }
208 
209 
210 // const std::string& getName() const { return name; }
211 
212 // ConfigComponent* getSlot(uint32_t slot) const {
213 // if ( slot <= slots.size() ) return slots[slot];
214 // return NULL;
215 // }
216 
217 // int getMaxPopulatedSlotNumber() const { return slots.size(); }
218 // bool isPopulated(int slot_num) const;
219 
220 // // bool isAllPopulated() const;
221 
222 // // SubComponent* create(int slot_num, Params& params);
223 // // std::vector<SubComponent*> createAll(Params& params);
224 
225 
226 // void serialize_order(SST::Core::Serialization::serializer &ser) {
227 // ser & name;
228 // ser & slots;
229 // }
230 
231 // ImplementSerializable(SST::SubComponentSlotDefinition)
232 // };
233 
234 
236 
237 /** Represents the configuration of a generic component */
239 public:
240  ComponentId_t id; /*!< Unique ID of this component */
241  std::string name; /*!< Name of this component, or slot name for subcomp */
242  int slot_num; /*!< Slot number. Only valid for subcomponents */
243  std::string type; /*!< Type of this component */
244  float weight; /*!< Parititoning weight for this component */
245  RankInfo rank; /*!< Parallel Rank for this component */
246  std::vector<LinkId_t> links; /*!< List of links connected */
247  Params params; /*!< Set of Parameters */
248  std::vector<Statistics::StatisticInfo> enabledStatistics; /*!< List of statistics to be enabled */
249  std::vector<ConfigComponent> subComponents; /*!< List of subcomponents */
250  std::vector<double> coords;
251 
252  inline const ComponentId_t& key()const { return id; }
253 
254  /** Print Component information */
255  void print(std::ostream &os) const;
256 
257  ConfigComponent cloneWithoutLinks() const;
258  ConfigComponent cloneWithoutLinksOrParams() const;
259 
260  ~ConfigComponent() {}
261  ConfigComponent() : id(-1) {}
262 
263  void setRank(RankInfo r);
264  void setWeight(double w);
265  void setCoordinates(const std::vector<double> &c);
266  void addParameter(const std::string &key, const std::string &value, bool overwrite);
267  ConfigComponent* addSubComponent(ComponentId_t, const std::string &name, const std::string &type, int slot);
268  ConfigComponent* findSubComponent(ComponentId_t);
269  const ConfigComponent* findSubComponent(ComponentId_t) const;
270  void enableStatistic(const std::string &statisticName);
271  void addStatisticParameter(const std::string &statisticName, const std::string &param, const std::string &value);
272  void setStatisticParameters(const std::string &statisticName, const Params &params);
273 
274  std::vector<LinkId_t> allLinks() const;
275 
276  void serialize_order(SST::Core::Serialization::serializer &ser) override {
277  ser & id;
278  ser & name;
279  ser & slot_num;
280  ser & type;
281  ser & weight;
282  ser & rank.rank;
283  ser & rank.thread;
284  ser & links;
285  ser & params;
286  ser & enabledStatistics;
287  ser & subComponents;
288  }
289 
290  ImplementSerializable(SST::ConfigComponent)
291 
292 private:
293 
294  friend class ConfigGraph;
295  /** Create a new Component */
296  ConfigComponent(ComponentId_t id, std::string name, std::string type, float weight, RankInfo rank) :
297  id(id),
298  name(name),
299  type(type),
300  weight(weight),
301  rank(rank)
302  {
303  coords.resize(3, 0.0);
304  }
305 
306  ConfigComponent(ComponentId_t id, std::string name, int slot_num, std::string type, float weight, RankInfo rank) :
307  id(id),
308  name(name),
309  slot_num(slot_num),
310  type(type),
311  weight(weight),
312  rank(rank)
313  {
314  coords.resize(3, 0.0);
315  }
316 
317 
318 };
319 
320 
321 
322 /** Map names to Links */
323 // typedef std::map<std::string,ConfigLink> ConfigLinkMap_t;
324 // typedef SparseVectorMap<std::string,ConfigLink> ConfigLinkMap_t;
325 /** Map IDs to Components */
327 /** Map names to Parameter Sets: XML only */
328 typedef std::map<std::string,Params*> ParamsMap_t;
329 /** Map names to variable values: XML only */
330 typedef std::map<std::string,std::string> VariableMap_t;
331 
332 class PartitionGraph;
333 
334 /** A Configuration Graph
335  * A graph representing Components and Links
336  */
338 public:
339  /** Print the configuration graph */
340  void print(std::ostream &os) const {
341  os << "Printing graph" << std::endl;
342  for (ConfigComponentMap_t::const_iterator i = comps.begin() ; i != comps.end() ; ++i) {
343  i->print(os);
344  }
345  }
346 
347  ConfigGraph() {
348  links.clear();
349  comps.clear();
350  // Init the statistic output settings
351  statLoadLevel = STATISTICSDEFAULTLOADLEVEL;
352  statOutputs.emplace_back(STATISTICSDEFAULTOUTPUTNAME);
353  }
354 
355  size_t getNumComponents() { return comps.data.size(); }
356 
357  /** Helper function to set all the ranks to the same value */
358  void setComponentRanks(RankInfo rank);
359  /** Checks to see if rank contains at least one component */
360  bool containsComponentInRank(RankInfo rank);
361  /** Verify that all components have valid Ranks assigned */
362  bool checkRanks(RankInfo ranks);
363 
364 
365  // API for programatic initialization
366  /** Create a new component with weight and rank */
367  ComponentId_t addComponent(ComponentId_t id, std::string name, std::string type, float weight, RankInfo rank);
368  /** Create a new component */
369  ComponentId_t addComponent(ComponentId_t id, std::string name, std::string type);
370 
371 
372  /** Set the statistic ouput module */
373  void setStatisticOutput(const std::string &name);
374 
375  /** Add parameter to the statistic output module */
376  void addStatisticOutputParameter(const std::string &param, const std::string &value);
377 
378  /** Set a set of parameter to the statistic output module */
379  void setStatisticOutputParams(const Params& p);
380 
381  /** Set the statistic system load level */
382  void setStatisticLoadLevel(uint8_t loadLevel);
383 
384  /** Enable a Statistics assigned to a component */
385  void enableStatisticForComponentName(std::string ComponentName, std::string statisticName);
386  void enableStatisticForComponentType(std::string ComponentType, std::string statisticName);
387 
388  /** Add Parameters for a Statistic */
389  void addStatisticParameterForComponentName(const std::string &ComponentName, const std::string &statisticName, const std::string &param, const std::string &value);
390  void addStatisticParameterForComponentType(const std::string &ComponentType, const std::string &statisticName, const std::string &param, const std::string &value);
391 
392  std::vector<ConfigStatOutput>& getStatOutputs() {return statOutputs;}
393  const ConfigStatOutput& getStatOutput(size_t index = 0) const {return statOutputs[index];}
394  long getStatLoadLevel() const {return statLoadLevel;}
395 
396  /** Add a Link to a Component on a given Port */
397  void addLink(ComponentId_t comp_id, std::string link_name, std::string port, std::string latency_str, bool no_cut = false);
398 
399  /** Perform any post-creation cleanup processes */
400  void postCreationCleanup();
401 
402  /** Check the graph for Structural errors */
403  bool checkForStructuralErrors();
404 
405  // Temporary until we have a better API
406  /** Return the map of components */
407  ConfigComponentMap_t& getComponentMap() {
408  return comps;
409  }
410 
411  const std::map<std::string, ConfigStatGroup>& getStatGroups() const { return statGroups; }
412  ConfigStatGroup* getStatGroup(const std::string &name) {
413  auto found = statGroups.find(name);
414  if ( found == statGroups.end() ) {
415  bool ok;
416  std::tie(found, ok) = statGroups.emplace(name, name);
417  }
418  return &(found->second);
419  }
420 
421  bool containsComponent(ComponentId_t id) const;
422  ConfigComponent* findComponent(ComponentId_t);
423  const ConfigComponent* findComponent(ComponentId_t) const;
424 
425  /** Return the map of links */
426  ConfigLinkMap_t& getLinkMap() {
427  return links;
428  }
429 
430  ConfigGraph* getSubGraph(uint32_t start_rank, uint32_t end_rank);
431  ConfigGraph* getSubGraph(const std::set<uint32_t>& rank_set);
432 
433  PartitionGraph* getPartitionGraph();
434  PartitionGraph* getCollapsedPartitionGraph();
435  void annotateRanks(PartitionGraph* graph);
436  void getConnectedNoCutComps(ComponentId_t start, ComponentIdMap_t& group);
437 
438  void serialize_order(SST::Core::Serialization::serializer &ser) override
439  {
440  ser & links;
441  ser & comps;
442  ser & statOutputs;
443  ser & statLoadLevel;
444  ser & statGroups;
445  }
446 
447 private:
448  friend class Simulation;
449  friend class SSTSDLModelDefinition;
450 
451  ConfigLinkMap_t links;
452  ConfigComponentMap_t comps;
453  std::map<std::string, ConfigStatGroup> statGroups;
454 
455  // temporary as a test
456  std::map<std::string,LinkId_t> link_names;
457 
458  std::vector<ConfigStatOutput> statOutputs; // [0] is default
459  uint8_t statLoadLevel;
460 
461  ImplementSerializable(SST::ConfigGraph)
462 
463 };
464 
465 
467 public:
468  ComponentId_t id;
469  float weight;
470  RankInfo rank;
471  LinkIdMap_t links;
472 
473  ComponentIdMap_t group;
474 
476  id = cc.id;
477  weight = cc.weight;
478  rank = cc.rank;
479  }
480 
481  PartitionComponent(LinkId_t id) :
482  id(id),
483  weight(0),
484  rank(RankInfo(RankInfo::UNASSIGNED, 0))
485  {}
486 
487  // PartitionComponent(ComponentId_t id, ConfigGraph* graph, const ComponentIdMap_t& group);
488  void print(std::ostream &os, const PartitionGraph* graph) const;
489 
490  inline ComponentId_t key() const { return id; }
491 
492 };
493 
495 public:
496  LinkId_t id;
497  ComponentId_t component[2];
498  SimTime_t latency[2];
499  bool no_cut;
500 
501  PartitionLink(const ConfigLink& cl) {
502  id = cl.id;
503  component[0] = cl.component[0];
504  component[1] = cl.component[1];
505  latency[0] = cl.latency[0];
506  latency[1] = cl.latency[1];
507  no_cut = cl.no_cut;
508  }
509 
510  inline LinkId_t key() const { return id; }
511 
512  /** Return the minimum latency of this link (from both sides) */
513  SimTime_t getMinLatency() const {
514  if ( latency[0] < latency[1] ) return latency[0];
515  return latency[1]; }
516 
517  /** Print the Link information */
518  void print(std::ostream &os) const {
519  os << " Link " << id << std::endl;
520  os << " component[0] = " << component[0] << std::endl;
521  os << " latency[0] = " << latency[0] << std::endl;
522  os << " component[1] = " << component[1] << std::endl;
523  os << " latency[1] = " << latency[1] << std::endl;
524  }
525 };
526 
529 
531 private:
532  PartitionComponentMap_t comps;
533  PartitionLinkMap_t links;
534 
535 public:
536  /** Print the configuration graph */
537  void print(std::ostream &os) const {
538  os << "Printing graph" << std::endl;
539  for (PartitionComponentMap_t::const_iterator i = comps.begin() ; i != comps.end() ; ++i) {
540  i->print(os,this);
541  }
542  }
543 
544  PartitionComponentMap_t& getComponentMap() {
545  return comps;
546  }
547  PartitionLinkMap_t& getLinkMap() {
548  return links;
549  }
550 
551  const PartitionLink& getLink(LinkId_t id) const {
552  return links[id];
553  }
554 
555  size_t getNumComponents() { return comps.size(); }
556 
557 };
558 
559 } // namespace SST
560 
561 #endif // SST_CORE_CONFIGGRAPH_H
int slot_num
Definition: configGraph.h:242
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:244
ConfigComponentMap_t & getComponentMap()
Return the map of components.
Definition: configGraph.h:407
Main control class for a SST Simulation.
Definition: simulation.h:72
Represents the configuration of a generic component.
Definition: configGraph.h:238
Definition: configGraph.h:530
std::string type
Definition: configGraph.h:243
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:337
void insert(std::string key, std::string value, bool overwrite=true)
Add a key value pair into the param object.
Definition: params.h:339
std::vector< Statistics::StatisticInfo > enabledStatistics
Definition: configGraph.h:248
Definition: configGraph.h:466
Definition: action.cc:17
RankInfo rank
Definition: configGraph.h:245
Definition: serializable.h:109
ConfigLinkMap_t & getLinkMap()
Return the map of links.
Definition: configGraph.h:426
ComponentId_t id
Definition: configGraph.h:240
Definition: rankInfo.h:21
void print(std::ostream &os) const
Print the configuration graph.
Definition: configGraph.h:340
Params params
Definition: configGraph.h:247
ImplementSerializable(SST::ConfigComponent) private ConfigComponent(ComponentId_t id, std::string name, std::string type, float weight, RankInfo rank)
Create a new Component.
Definition: configGraph.h:296
std::vector< LinkId_t > links
Definition: configGraph.h:246
Parameter store.
Definition: params.h:45
Definition: configGraph.h:170
std::string name
Definition: configGraph.h:241
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:36
void print(std::ostream &os) const
Print the configuration graph.
Definition: configGraph.h:537
Definition: configGraph.h:131
Definition: componentInfo.h:30
std::vector< ConfigComponent > subComponents
Definition: configGraph.h:249
Performs Unit math in full precision.
Definition: unitAlgebra.h:104