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