SST  6.0.0
StructuralSimulationToolkit
configGraph.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2016 Sandia Corporation. Under the terms
4 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2016, 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/statoutput.h"
27 #include "sst/core/rankInfo.h"
28 
29 #include <sst/core/serialization/serializable.h>
30 
31 // #include "sst/core/simulation.h"
32 
33 using namespace SST::Statistics;
34 
35 namespace SST {
36 
37 
38 class Simulation;
39 
40 class Config;
41 class TimeLord;
42 
43 typedef SparseVectorMap<ComponentId_t> ComponentIdMap_t;
44 typedef std::vector<LinkId_t> LinkIdMap_t;
45 
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) {
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 typedef SparseVectorMap<LinkId_t,ConfigLink> ConfigLinkMap_t;
128 
129 /** Represents the configuration of a generic component */
131 public:
132  ComponentId_t id; /*!< Unique ID of this component */
133  std::string name; /*!< Name of this component */
134  std::string type; /*!< Type of this component */
135  float weight; /*!< Parititoning weight for this component */
136  RankInfo rank; /*!< Parallel Rank for this component */
137  std::vector<LinkId_t> links; /*!< List of links connected */
138  Params params; /*!< Set of Parameters */
139  bool isIntrospector; /*!< Is this an Introspector? */
140  std::vector<std::string> enabledStatistics; /*!< List of statistics to be enabled */
141  std::vector<Params> enabledStatParams; /*!< List of parameters for enabled statistics */
142 
143  inline const ComponentId_t& key()const { return id; }
144 
145  /** Print Component information */
146  void print(std::ostream &os) const;
147 
148  ConfigComponent cloneWithoutLinks() const;
149  ConfigComponent cloneWithoutLinksOrParams() const;
150 
151  ~ConfigComponent() {}
152  ConfigComponent() {} // for serialization
153 
154  void serialize_order(SST::Core::Serialization::serializer &ser) {
155  ser & id;
156  ser & name;
157  ser & type;
158  ser & weight;
159  ser & rank.rank;
160  ser & rank.thread;
161  ser & links;
162  ser & params;
163  ser & isIntrospector;
164  ser & enabledStatistics;
165  ser & enabledStatParams;
166  }
167 
168  ImplementSerializable(SST::ConfigComponent)
169 
170 private:
171 
172  friend class ConfigGraph;
173  /** Create a new Component */
174  ConfigComponent(ComponentId_t id, std::string name, std::string type, float weight, RankInfo rank, bool isIntrospector) :
175  id(id),
176  name(name),
177  type(type),
178  weight(weight),
179  rank(rank),
180  isIntrospector(isIntrospector)
181  { }
182 
183 
184 };
185 
186 
187 /** Map names to Links */
188 // typedef std::map<std::string,ConfigLink> ConfigLinkMap_t;
189 // typedef SparseVectorMap<std::string,ConfigLink> ConfigLinkMap_t;
190 /** Map IDs to Components */
191 typedef SparseVectorMap<ComponentId_t,ConfigComponent> ConfigComponentMap_t;
192 /** Map names to Parameter Sets: XML only */
193 typedef std::map<std::string,Params*> ParamsMap_t;
194 /** Map names to variable values: XML only */
195 typedef std::map<std::string,std::string> VariableMap_t;
196 
197 class PartitionGraph;
198 
199 /** A Configuration Graph
200  * A graph representing Components and Links
201  */
203 public:
204  /** Print the configuration graph */
205  void print(std::ostream &os) const {
206  os << "Printing graph" << std::endl;
207  for (ConfigComponentMap_t::const_iterator i = comps.begin() ; i != comps.end() ; ++i) {
208  i->print(os);
209  }
210  }
211 
212  ConfigGraph() {
213  links.clear();
214  comps.clear();
215  nextCompID = 0;
216  // Init the statistic output settings
217  statOutputName = STATISTICSDEFAULTOUTPUTNAME;
218  statLoadLevel = STATISTICSDEFAULTLOADLEVEL;
219  }
220 
221  size_t getNumComponents() { return comps.data.size(); }
222 
223  /** Helper function to set all the ranks to the same value */
224  void setComponentRanks(RankInfo rank);
225  /** Checks to see if rank contains at least one component */
226  bool containsComponentInRank(RankInfo rank);
227  /** Verify that all components have valid Ranks assigned */
228  bool checkRanks(RankInfo ranks);
229 
230 
231  // API for programatic initialization
232  /** Create a new component with weight and rank */
233  ComponentId_t addComponent(std::string name, std::string type, float weight, RankInfo rank);
234  /** Create a new component */
235  ComponentId_t addComponent(std::string name, std::string type);
236 
237  /** Set on which rank a Component will exist (partitioning) */
238  void setComponentRank(ComponentId_t comp_id, RankInfo rank);
239  /** Set the weight of a Component (partitioning) */
240  void setComponentWeight(ComponentId_t comp_id, float weight);
241 
242  /** Add a set of Parameters to a component */
243  void addParams(ComponentId_t comp_id, Params& p);
244  /** Add a single parameter to a component */
245  void addParameter(ComponentId_t comp_id, std::string key, std::string value, bool overwrite = false);
246 
247  /** Set the statistic ouput module */
248  void setStatisticOutput(const char* name);
249 
250  /** Add parameter to the statistic output module */
251  void addStatisticOutputParameter(const char* param, const char* value);
252 
253  /** Set a set of parameter to the statistic output module */
254  void setStatisticOutputParams(const Params& p);
255 
256  /** Set the statistic system load level */
257  void setStatisticLoadLevel(uint8_t loadLevel);
258 
259  /** Enable a Statistics assigned to a component */
260  void enableComponentStatistic(ComponentId_t comp_id, std::string statisticName);
261  void enableStatisticForComponentName(std::string ComponentName, std::string statisticName);
262  void enableStatisticForComponentType(std::string ComponentType, std::string statisticName);
263 
264  /** Add Parameters for a Statistic */
265  void addComponentStatisticParameter(ComponentId_t comp_id, std::string statisticName, const char* param, const char* value);
266  void addStatisticParameterForComponentName(std::string ComponentName, std::string statisticName, const char* param, const char* value);
267  void addStatisticParameterForComponentType(std::string ComponentType, std::string statisticName, const char* param, const char* value);
268 
269  const std::string& getStatOutput() const {return statOutputName;}
270  const Params& getStatOutputParams() const {return statOutputParams;}
271  long getStatLoadLevel() const {return statLoadLevel;}
272 
273  /** Add a Link to a Component on a given Port */
274  void addLink(ComponentId_t comp_id, std::string link_name, std::string port, std::string latency_str, bool no_cut = false);
275 
276  /** Create a new Introspector */
277  ComponentId_t addIntrospector(std::string name, std::string type);
278 
279  /** Perform any post-creation cleanup processes */
280  void postCreationCleanup();
281 
282  /** Check the graph for Structural errors */
283  bool checkForStructuralErrors();
284 
285  // Temporary until we have a better API
286  /** Return the map of components */
287  ConfigComponentMap_t& getComponentMap() {
288  return comps;
289  }
290  /** Return the map of links */
291  ConfigLinkMap_t& getLinkMap() {
292  return links;
293  }
294 
295  ConfigGraph* getSubGraph(uint32_t start_rank, uint32_t end_rank);
296  ConfigGraph* getSubGraph(const std::set<uint32_t>& rank_set);
297 
298  PartitionGraph* getPartitionGraph();
299  PartitionGraph* getCollapsedPartitionGraph();
300  void annotateRanks(PartitionGraph* graph);
301  void getConnectedNoCutComps(ComponentId_t start, ComponentIdMap_t& group);
302 
303  void serialize_order(SST::Core::Serialization::serializer &ser)
304  {
305  ser & links;
306  ser & comps;
307  ser & statOutputName;
308  ser & statOutputParams;
309  ser & statLoadLevel;
310  }
311 
312 private:
313  friend class Simulation;
314  friend class SSTSDLModelDefinition;
315 
316  ConfigLinkMap_t links;
317  ConfigComponentMap_t comps;
318 
319  // temporary as a test
320  std::map<std::string,LinkId_t> link_names;
321 
322  ComponentId_t nextCompID;
323 
324  std::string statOutputName;
325  Params statOutputParams;
326  uint8_t statLoadLevel;
327 
328  ImplementSerializable(SST::ConfigGraph)
329 
330 };
331 
332 
334 public:
335  ComponentId_t id;
336  float weight;
337  RankInfo rank;
338  LinkIdMap_t links;
339 
340  ComponentIdMap_t group;
341 
343  id = cc.id;
344  weight = cc.weight;
345  rank = cc.rank;
346  }
347 
348  PartitionComponent(LinkId_t id) :
349  id(id),
350  weight(0),
351  rank(RankInfo(RankInfo::UNASSIGNED, 0))
352  {}
353 
354  // PartitionComponent(ComponentId_t id, ConfigGraph* graph, const ComponentIdMap_t& group);
355  void print(std::ostream &os, const PartitionGraph* graph) const;
356 
357  inline const ComponentId_t key() const { return id; }
358 
359 };
360 
362 public:
363  LinkId_t id;
364  ComponentId_t component[2];
365  SimTime_t latency[2];
366  bool no_cut;
367 
368  PartitionLink(const ConfigLink& cl) {
369  id = cl.id;
370  component[0] = cl.component[0];
371  component[1] = cl.component[1];
372  latency[0] = cl.latency[0];
373  latency[1] = cl.latency[1];
374  no_cut = cl.no_cut;
375  }
376 
377  inline const LinkId_t key() const { return id; }
378 
379  /** Return the minimum latency of this link (from both sides) */
380  SimTime_t getMinLatency() const {
381  if ( latency[0] < latency[1] ) return latency[0];
382  return latency[1]; }
383 
384  /** Print the Link information */
385  void print(std::ostream &os) const {
386  os << " Link " << id << std::endl;
387  os << " component[0] = " << component[0] << std::endl;
388  os << " latency[0] = " << latency[0] << std::endl;
389  os << " component[1] = " << component[1] << std::endl;
390  os << " latency[1] = " << latency[1] << std::endl;
391  }
392 };
393 
394 typedef SparseVectorMap<ComponentId_t,PartitionComponent> PartitionComponentMap_t;
395 typedef SparseVectorMap<LinkId_t,PartitionLink> PartitionLinkMap_t;
396 
398 private:
399  PartitionComponentMap_t comps;
400  PartitionLinkMap_t links;
401 
402 public:
403  /** Print the configuration graph */
404  void print(std::ostream &os) const {
405  os << "Printing graph" << std::endl;
406  for (PartitionComponentMap_t::const_iterator i = comps.begin() ; i != comps.end() ; ++i) {
407  i->print(os,this);
408  }
409  }
410 
411  PartitionComponentMap_t& getComponentMap() {
412  return comps;
413  }
414  PartitionLinkMap_t& getLinkMap() {
415  return links;
416  }
417 
418  const PartitionLink& getLink(LinkId_t id) const {
419  return links[id];
420  }
421 
422  size_t getNumComponents() { return comps.size(); }
423 
424 };
425 
426 } // namespace SST
427 
428 #endif // SST_CORE_CONFIGGRAPH_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
bool isIntrospector
Definition: configGraph.h:139
float weight
Definition: configGraph.h:135
ConfigComponentMap_t & getComponentMap()
Return the map of components.
Definition: configGraph.h:287
std::vector< Params > enabledStatParams
Definition: configGraph.h:141
Represents the configuration of a generic component.
Definition: configGraph.h:130
Definition: configGraph.h:397
std::string type
Definition: configGraph.h:134
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:202
void print(std::ostream &os) const
Print the configuration graph.
Definition: configGraph.h:404
Definition: configGraph.h:333
Definition: action.cc:17
RankInfo rank
Definition: configGraph.h:136
Definition: serializable.h:108
ConfigLinkMap_t & getLinkMap()
Return the map of links.
Definition: configGraph.h:291
ComponentId_t id
Definition: configGraph.h:132
Definition: rankInfo.h:21
Params params
Definition: configGraph.h:138
std::vector< std::string > enabledStatistics
Definition: configGraph.h:140
void print(std::ostream &os) const
Print the configuration graph.
Definition: configGraph.h:205
std::vector< LinkId_t > links
Definition: configGraph.h:137
Parameter store.
Definition: params.h:46
std::string name
Definition: configGraph.h:133
Definition: simulation.h:62