SST  15.1.0
StructuralSimulationToolkit
configGraph.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2025 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-2025, 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/params.h"
18 #include "sst/core/rankInfo.h"
19 #include "sst/core/serialization/serializable.h"
20 #include "sst/core/sparseVectorMap.h"
21 #include "sst/core/sst_types.h"
22 #include "sst/core/statapi/statbase.h"
23 #include "sst/core/statapi/statoutput.h"
24 #include "sst/core/timeConverter.h"
25 #include "sst/core/unitAlgebra.h"
26 
27 #include <climits>
28 #include <cstddef>
29 #include <cstdint>
30 #include <map>
31 #include <memory>
32 #include <ostream>
33 #include <set>
34 #include <string>
35 #include <utility>
36 #include <vector>
37 
38 using namespace SST::Statistics;
39 
40 namespace SST {
41 
42 class Simulation_impl;
43 
44 class Config;
45 class TimeLord;
46 class ConfigGraph;
47 
48 using ComponentIdMap_t = SparseVectorMap<ComponentId_t>;
49 using LinkIdMap_t = std::vector<LinkId_t>;
50 
51 /** Represents the configuration of a generic Link */
53 {
54  // Static data structures to map latency string to an index that
55  // will hold the SimTime_t for the latency once the atomic
56  // timebase has been set.
57  static std::map<std::string, uint32_t> lat_to_index;
58 
59  static uint32_t getIndexForLatency(const char* latency);
60  static std::vector<SimTime_t> initializeLinkLatencyVector();
61  SimTime_t getLatencyFromIndex(uint32_t index);
62 
63 public:
64  /**
65  Components that are connected to this link. They are filled in
66  the order they are attached in. If the link is marked as
67  non-local, then component[1] holds the rank of the remote
68  component.
69  */
70  ComponentId_t component[2] = { 0, 0 }; /*!< IDs of the connected components */
71 
72  /**
73  This is a dual purpose data member.
74 
75  Graph construction - during graph construction, it holds the
76  index into the LinkLatencyVector, which maps the stored index
77  to the actual latency string. This is done to reduce memory
78  usage because we assume there will be a small number of
79  different latencies specified.
80 
81  Post graph construction - after graph construction, the latency
82  index is replaced with the SimTime_t value representing the
83  specified latency that will be used by the link to add the
84  specified latency to the event.
85 
86  In both cases, the indices match the indices found in the
87  component array, and represent the latency of the link for
88  events sent from the corresponding component.
89 
90  If the link is marked as non-local, then latency[1] holds the
91  thread of the remote component.
92  */
93  SimTime_t latency[2] = { 0, 0 };
94 
95  /**
96  Name of the link. This is used in three cases:
97 
98  Errors - if an error is found in the graph construction, the
99  name is used to report the error to the user
100 
101  Link ordering - the event ordering for links is based on the
102  alphabetized name of the links. The links are sorted by name
103  and order is assigned linearly starting at 1
104 
105  Parallel load - for parallel load, links that cross partition
106  boundaries are connected by matching link names
107  */
108  std::string name;
109 
110  /**
111  id of the link. This is used primarily to find the link in
112  ConfigGraph::links
113  */
114  LinkId_t id = 0;
115 
116  /**
117  This is a dual purpose data member. During graph construction,
118  it counts the number of components currently referencing this
119  link. After graph construction, it is assigned the value used
120  to enforce ordering of events based on the links they were sent
121  on.
122 
123  @see Activity::setOrderTag, Link::tag
124  */
125  LinkId_t order = 0;
126 
127  /**
128  Name of the ports the link is connected to. The indices match
129  the ones used in the component array
130  */
131  std::string port[2];
132 
133  /**
134  Whether or not this link is set to be no-cut
135  */
136  bool no_cut = false;
137 
138  /**
139  Whether this link crosses the graph boundary and is connected
140  on one end to a non-local component. If set to true, there
141  will only be one component connected (information in index 0
142  for the arrays) and the rank for the remote component will be
143  stored in component[1] and the thread in latency[1].
144  */
145  bool nonlocal = false;
146 
147  /**
148  Set to true if this is a cross rank link
149  */
150  bool cross_rank = false;
151 
152  /**
153  Set to true if this is a cross thread link on same rank
154  */
155  bool cross_thread = false;
156 
157  inline LinkId_t key() const { return id; }
158 
159  /** Return the minimum latency of this link (from both sides) */
160  SimTime_t getMinLatency() const
161  {
162  if ( nonlocal ) return latency[0];
163  if ( latency[0] < latency[1] ) return latency[0];
164  return latency[1];
165  }
166 
167  std::string latency_str(uint32_t index) const;
168 
169  /**
170  Sets the link as a non-local link.
171 
172  @param which_local specifies which index is for the local side
173  of the link
174 
175  @param remote_rank_info Rank of the remote side of the link
176 
177  */
178  void setAsNonLocal(int which_local, RankInfo remote_rank_info);
179 
180  /** Print the Link information */
181  void print(std::ostream& os) const
182  {
183  os << "Link " << name << " (id = " << id << ")" << std::endl;
184  os << " nonlocal = " << nonlocal << std::endl;
185  os << " component[0] = " << component[0] << std::endl;
186  os << " port[0] = " << port[0] << std::endl;
187  os << " latency[0] = " << latency[0] << std::endl;
188  os << " component[1] = " << component[1] << std::endl;
189  os << " port[1] = " << port[1] << std::endl;
190  os << " latency[1] = " << latency[1] << std::endl;
191  }
192 
193  /* Do not use. For serialization only */
194  ConfigLink() {}
195 
196  void serialize_order(SST::Core::Serialization::serializer& ser) /*override*/
197  {
198  SST_SER(id);
199  SST_SER(name);
200  SST_SER(component[0]);
201  SST_SER(component[1]);
202  SST_SER(port[0]);
203  SST_SER(port[1]);
204  SST_SER(latency[0]);
205  SST_SER(latency[1]);
206  SST_SER(order);
207  SST_SER(nonlocal);
208  SST_SER(no_cut);
209  SST_SER(cross_rank);
210  SST_SER(cross_thread);
211  }
212 
213 private:
214  friend class ConfigGraph;
215  explicit ConfigLink(LinkId_t id) :
216  id(id),
217  no_cut(false)
218  {
219  order = 0;
220 
221  // Initialize the component data items
222  component[0] = ULONG_MAX;
223  component[1] = ULONG_MAX;
224  }
225 
226  ConfigLink(LinkId_t id, const std::string& n) :
227  id(id),
228  no_cut(false)
229  {
230  order = 0;
231  name = n;
232 
233  // Initialize the component data items
234  component[0] = ULONG_MAX;
235  component[1] = ULONG_MAX;
236  }
237 
238  void updateLatencies();
239 };
240 
242 {
243 public:
244  StatisticId_t id; /*!< Unique ID of this statistic */
245  Params params;
246  bool shared = false;
247  std::string name;
248 
249  ConfigStatistic(StatisticId_t _id, bool _shared = false, std::string _name = "") :
250  id(_id),
251  shared(_shared),
252  name(_name)
253  {}
254 
255  ConfigStatistic() :
256  id(stat_null_id)
257  {}
258 
259  ConfigStatistic(const ConfigStatistic&) = default;
260  ConfigStatistic(ConfigStatistic&&) = default;
261  ConfigStatistic& operator=(const ConfigStatistic&) = default;
262  ConfigStatistic& operator=(ConfigStatistic&&) = default;
263  ~ConfigStatistic() override = default;
264 
265  inline const StatisticId_t& getId() const { return id; }
266 
267  void addParameter(const std::string& key, const std::string& value, bool overwrite);
268 
269  void serialize_order(SST::Core::Serialization::serializer& ser) override
270  {
271  SST_SER(id);
272  SST_SER(shared);
273  SST_SER(name);
274  SST_SER(params);
275  }
276 
277  ImplementSerializable(ConfigStatistic)
278 
279  static constexpr StatisticId_t stat_null_id = std::numeric_limits<StatisticId_t>::max();
280 };
281 
283 {
284 public:
285  std::string name;
286  std::map<std::string, Params> statMap;
287  std::vector<ComponentId_t> components;
288  size_t outputID;
289  UnitAlgebra outputFrequency;
290 
291  explicit ConfigStatGroup(const std::string& name) :
292  name(name),
293  outputID(0)
294  {}
295  ConfigStatGroup() {} /* Do not use */
296 
297  bool addComponent(ComponentId_t id);
298  bool addStatistic(const std::string& name, Params& p);
299  bool setOutput(size_t id);
300  bool setFrequency(const std::string& freq);
301 
302  /**
303  * Checks to make sure that all components in the group support all
304  * of the statistics as configured in the group.
305  * @return pair of: bool for OK, string for error message (if any)
306  */
307  std::pair<bool, std::string> verifyStatsAndComponents(const ConfigGraph* graph);
308 
309  void serialize_order(SST::Core::Serialization::serializer& ser) override
310  {
311  SST_SER(name);
312  SST_SER(statMap);
313  SST_SER(components);
314  SST_SER(outputID);
315  SST_SER(outputFrequency);
316  }
317 
318  ImplementSerializable(SST::ConfigStatGroup)
319 };
320 
322 {
323 public:
324  std::string type;
325  Params params;
326 
327  explicit ConfigStatOutput(const std::string& type) :
328  type(type)
329  {}
330  ConfigStatOutput() {}
331 
332  void addParameter(const std::string& key, const std::string& val) { params.insert(key, val); }
333 
334  void serialize_order(SST::Core::Serialization::serializer& ser) override
335  {
336  SST_SER(type);
337  SST_SER(params);
338  }
339 
340  ImplementSerializable(SST::ConfigStatOutput)
341 };
342 
344 
345 /**
346  Class that represents a PortModule in ConfigGraph
347  */
349 {
350 public:
351  std::string type;
352  Params params;
353  uint8_t stat_load_level = STATISTICLOADLEVELUNINITIALIZED;
354  Params all_stat_config; /*!< If all stats are enabled, the config information for the stats */
355  std::map<std::string, Params> per_stat_configs;
356 
357  ConfigPortModule() = default;
358  ConfigPortModule(const std::string& type, const Params& params) :
359  type(type),
360  params(params)
361  {}
362 
363  void addParameter(const std::string& key, const std::string& value);
364  void addSharedParamSet(const std::string& set);
365  void setStatisticLoadLevel(const uint8_t level);
366  void enableAllStatistics(const SST::Params& params);
367  void enableStatistic(const std::string& statistic_name, const SST::Params& params);
368 
369  void serialize_order(SST::Core::Serialization::serializer& ser)
370  {
371  SST_SER(type);
372  SST_SER(params);
373  SST_SER(stat_load_level);
374  SST_SER(all_stat_config);
375  SST_SER(per_stat_configs);
376  }
377 };
378 
379 
380 /** Represents the configuration of a generic component */
382 {
383  friend class ComponentInfo;
384 
385 public:
386  ComponentId_t id; /*!< Unique ID of this component */
387  ConfigGraph* graph; /*!< Graph that this component belongs to */
388  std::string name; /*!< Name of this component, or slot name for subcomp */
389  int slot_num; /*!< Slot number. Only valid for subcomponents */
390  std::string type; /*!< Type of this component */
391  float weight; /*!< Partitioning weight for this component */
392  RankInfo rank; /*!< Parallel Rank for this component */
393  std::vector<LinkId_t> links; /*!< List of links connected */
394  Params params; /*!< Set of Parameters */
395  uint8_t statLoadLevel; /*!< Statistic load level for this component */
396 
397  std::map<std::string, std::vector<ConfigPortModule>>
398  port_modules; /*!< Map of port names to port modules loaded on that port */
399  std::map<std::string, StatisticId_t>
400  enabledStatNames; /*!< Map of explicitly enabled statistic names to unique IDs */
401  bool enabledAllStats; /*!< Whether all stats in this (sub)component have been enabled */
402  ConfigStatistic allStatConfig; /*!< If all stats are enabled, the config information for the stats */
403 
404  std::vector<ConfigComponent*> subComponents; /*!< List of subcomponents */
405  std::vector<double> coords;
406  uint16_t nextSubID; /*!< Next subID to use for children, if component, if subcomponent, subid of parent */
407  uint16_t nextStatID; /*!< Next statID to use for children */
408  bool visited; /*! Used when traversing graph to indicate component was visited already */
409 
410  static constexpr ComponentId_t null_id = std::numeric_limits<ComponentId_t>::max();
411 
412  inline const ComponentId_t& key() const { return id; }
413 
414  /** Print Component information */
415  void print(std::ostream& os) const;
416 
417  ConfigComponent* cloneWithoutLinks(ConfigGraph* new_graph) const;
418  ConfigComponent* cloneWithoutLinksOrParams(ConfigGraph* new_graph) const;
419  void setConfigGraphPointer(ConfigGraph* graph_ptr);
420 
421  ~ConfigComponent() {}
422  ConfigComponent() :
423  id(null_id),
424  statLoadLevel(STATISTICLOADLEVELUNINITIALIZED),
425  enabledAllStats(false),
426  nextSubID(1),
427  visited(false)
428  {}
429 
430  StatisticId_t getNextStatisticID();
431 
432  ConfigComponent* getParent() const;
433  std::string getFullName() const;
434 
435  void setRank(RankInfo r);
436  void setWeight(double w);
437  void setCoordinates(const std::vector<double>& c);
438  void addParameter(const std::string& key, const std::string& value, bool overwrite);
439  ConfigComponent* addSubComponent(const std::string& name, const std::string& type, int slot);
440  ConfigComponent* findSubComponent(ComponentId_t);
441  const ConfigComponent* findSubComponent(ComponentId_t) const;
442  ConfigComponent* findSubComponentByName(const std::string& name);
443  ConfigStatistic* findStatistic(const std::string& name) const;
444  ConfigStatistic* insertStatistic(StatisticId_t id);
445  ConfigStatistic* findStatistic(StatisticId_t) const;
446  ConfigStatistic* enableStatistic(
447  const std::string& statisticName, const SST::Params& params, bool recursively = false);
448  ConfigStatistic* createStatistic();
449  bool reuseStatistic(const std::string& statisticName, StatisticId_t sid);
450  void addStatisticParameter(
451  const std::string& statisticName, const std::string& param, const std::string& value, bool recursively = false);
452  void setStatisticParameters(const std::string& statisticName, const Params& params, bool recursively = false);
453  void setStatisticLoadLevel(uint8_t level, bool recursively = false);
454 
455  void addSharedParamSet(const std::string& set) { params.addSharedParamSet(set); }
456  [[deprecated(
457  "addGlobalParamSet() has been deprecated and will be removed in SST 16. Please use addSharedParamSet()")]]
458  void addGlobalParamSet(const std::string& set)
459  {
460  params.addSharedParamSet(set);
461  }
462  std::vector<std::string> getParamsLocalKeys() const { return params.getLocalKeys(); }
463  std::vector<std::string> getSubscribedSharedParamSets() const { return params.getSubscribedSharedParamSets(); }
464 
465  [[deprecated("getSubscribedGlobalParamSets() has been deprecated and will be removed in SST 16. Please use "
466  "getSubscribedSharedParamSets()")]]
467  std::vector<std::string> getSubscribedGlobalParamSets() const
468  {
469  return params.getSubscribedSharedParamSets();
470  }
471 
472  /* Adds a PortModule on the port 'port' of the associated component. Returns the index of the
473  * module in the component's vector of PortModules for the given port. */
474  size_t addPortModule(const std::string& port, const std::string& type, const Params& params);
475 
476  std::vector<LinkId_t> allLinks() const;
477 
478  // Gets all the links to return, then clears links from self and
479  // all subcomponents. Used when splitting graphs.
480  std::vector<LinkId_t> clearAllLinks();
481 
482  void serialize_order(SST::Core::Serialization::serializer& ser) override
483  {
484  SST_SER(id);
485  SST_SER(name);
486  SST_SER(slot_num);
487  SST_SER(type);
488  SST_SER(weight);
489  SST_SER(rank.rank);
490  SST_SER(rank.thread);
491  SST_SER(links);
492  SST_SER(params);
493  SST_SER(statLoadLevel);
494  SST_SER(port_modules);
495  SST_SER(enabledStatNames);
496  SST_SER(enabledAllStats);
497  SST_SER(statistics_);
498  SST_SER(allStatConfig);
499  SST_SER(subComponents);
500  SST_SER(coords);
501  SST_SER(nextSubID);
502  SST_SER(nextStatID);
503  }
504 
505  ImplementSerializable(SST::ConfigComponent)
506 
507 private:
508  std::map<StatisticId_t, ConfigStatistic>
509  statistics_; /* Map of explicitly enabled stat IDs to config info for each stat */
510 
511  ComponentId_t getNextSubComponentID();
512 
513  friend class ConfigGraph;
514  /** Checks to make sure port names are valid and that a port isn't used twice
515  */
516  void checkPorts() const;
517 
518  /** Create a new Component */
519  ConfigComponent(ComponentId_t id, ConfigGraph* graph, const std::string& name, const std::string& type,
520  float weight, RankInfo rank) :
521  id(id),
522  graph(graph),
523  name(name),
524  slot_num(0),
525  type(type),
526  weight(weight),
527  rank(rank),
528  statLoadLevel(STATISTICLOADLEVELUNINITIALIZED),
529  enabledAllStats(false),
530  nextSubID(1),
531  nextStatID(1)
532  {
533  coords.resize(3, 0.0);
534  }
535 
536  ConfigComponent(ComponentId_t id, ConfigGraph* graph, uint16_t parent_subid, const std::string& name, int slot_num,
537  const std::string& type, float weight, RankInfo rank) :
538  id(id),
539  graph(graph),
540  name(name),
541  slot_num(slot_num),
542  type(type),
543  weight(weight),
544  rank(rank),
545  statLoadLevel(STATISTICLOADLEVELUNINITIALIZED),
546  enabledAllStats(false),
547  nextSubID(parent_subid),
548  nextStatID(parent_subid)
549  {
550  coords.resize(3, 0.0);
551  }
552 };
553 
554 /** Map names to Links */
555 // using ConfigLinkMap_t = std::map<std::string,ConfigLink>;
556 // using ConfigLinkMap_t = SparseVectorMap<std::string,ConfigLink>;
557 /** Map IDs to Components */
558 using ConfigComponentMap_t = SparseVectorMap<ComponentId_t, ConfigComponent*>;
559 /** Map names to Components */
560 using ConfigComponentNameMap_t = std::map<std::string, ComponentId_t>;
561 /** Map names to Parameter Sets: XML only */
562 using ParamsMap_t = std::map<std::string, Params*>;
563 /** Map names to variable values: XML only */
564 using VariableMap_t = std::map<std::string, std::string>;
565 
566 class PartitionGraph;
567 
569 {
570  std::map<std::string, ConfigStatGroup> groups;
571  std::vector<ConfigStatOutput> outputs; // [0] is default group
572  uint8_t load_level;
573 
574  void serialize_order(SST::Core::Serialization::serializer& ser)
575  {
576  SST_SER(groups);
577  SST_SER(outputs);
578  SST_SER(load_level);
579  }
580 };
581 
582 /** A Configuration Graph
583  * A graph representing Components and Links
584  */
586 {
587 public:
588  /** Print the configuration graph */
589  void print(std::ostream& os) const
590  {
591  os << "Printing graph" << std::endl;
592  os << "Components:" << std::endl;
593  for ( ConfigComponentMap_t::const_iterator i = comps_.begin(); i != comps_.end(); ++i ) {
594  (*i)->print(os);
595  }
596  os << "Links:" << std::endl;
597  for ( auto i = links_.begin(); i != links_.end(); ++i ) {
598  (*i)->print(os);
599  }
600  }
601 
602  ConfigGraph() :
603  nextComponentId(0)
604  {
605  links_.clear();
606  comps_.clear();
607  // Init the statistic output settings
608  stats_config_ = new StatsConfig();
609  stats_config_->load_level = STATISTICSDEFAULTLOADLEVEL;
610  stats_config_->outputs.emplace_back(STATISTICSDEFAULTOUTPUTNAME);
611  // Output is only used for warnings or fatal that should go to stderr
612  Output& o = Output::getDefaultObject();
613  output.init(o.getPrefix(), o.getVerboseLevel(), o.getVerboseMask(), Output::STDERR);
614  }
615 
616  ~ConfigGraph()
617  {
618  for ( auto comp : comps_ ) {
619  delete comp;
620  }
621 
622  if ( stats_config_ ) delete stats_config_;
623  }
624 
625  size_t getNumComponents() { return comps_.data.size(); }
626 
627  size_t getNumComponentsInMPIRank(uint32_t rank);
628 
629  /** Helper function to set all the ranks to the same value */
630  void setComponentRanks(RankInfo rank);
631  /** Checks to see if rank contains at least one component */
632  bool containsComponentInRank(RankInfo rank);
633  /** Verify that all components have valid Ranks assigned */
634  bool checkRanks(RankInfo ranks);
635 
636  // API for programmatic initialization
637  /** Create a new component */
638  ComponentId_t addComponent(const std::string& name, const std::string& type);
639 
640  /** Add a parameter to a shared param set */
641  void addSharedParam(const std::string& shared_set, const std::string& key, const std::string& value);
642 
643  [[deprecated("addGlobalParam() has been deprecated and will be removed in SST 16. Please use addSharedParam()")]]
644  void addGlobalParam(const std::string& shared_set, const std::string& key, const std::string& value);
645 
646  /** Set the statistic output module */
647  void setStatisticOutput(const std::string& name);
648 
649  /** Add parameter to the statistic output module */
650  void addStatisticOutputParameter(const std::string& param, const std::string& value);
651 
652  /** Set a set of parameter to the statistic output module */
653  void setStatisticOutputParams(const Params& p);
654 
655  /** Set the statistic system load level */
656  void setStatisticLoadLevel(uint8_t loadLevel);
657 
658  std::vector<ConfigStatOutput>& getStatOutputs() { return stats_config_->outputs; }
659 
660  const ConfigStatOutput& getStatOutput(size_t index = 0) const { return stats_config_->outputs[index]; }
661 
662  long getStatLoadLevel() const { return stats_config_->load_level; }
663 
664  /**
665  Create link and return it's ID. The provided name is not
666  checked against existing links
667  */
668  LinkId_t createLink(const char* name, const char* latency = nullptr);
669 
670  /** Add a Link to a Component on a given Port */
671  void addLink(ComponentId_t comp_id, LinkId_t link_id, const char* port, const char* latency_str);
672 
673  /**
674  Adds the remote rank info for nonlocal links
675  */
676  void addNonLocalLink(LinkId_t link_id, int rank, int thread);
677 
678  /** Set a Link to be no-cut */
679  void setLinkNoCut(LinkId_t link_name);
680 
681  /** Perform any post-creation cleanup processes */
682  void postCreationCleanup();
683 
684  /** Check the graph for Structural errors */
685  bool checkForStructuralErrors();
686 
687  // Temporary until we have a better API
688  /** Return the map of components */
689  ConfigComponentMap_t& getComponentMap() { return comps_; }
690 
691  const std::map<std::string, ConfigStatGroup>& getStatGroups() const { return stats_config_->groups; }
692  ConfigStatGroup* getStatGroup(const std::string& name)
693  {
694  auto found = stats_config_->groups.find(name);
695  if ( found == stats_config_->groups.end() ) {
696  bool ok;
697  std::tie(found, ok) = stats_config_->groups.emplace(name, name);
698  }
699  return &(found->second);
700  }
701 
702  bool containsComponent(ComponentId_t id) const;
703  ConfigComponent* findComponent(ComponentId_t);
704  ConfigComponent* findComponentByName(const std::string& name);
705  const ConfigComponent* findComponent(ComponentId_t) const;
706 
707  ConfigStatistic* findStatistic(StatisticId_t) const;
708 
709  /** Return the map of links */
710  ConfigLinkMap_t& getLinkMap() { return links_; }
711 
712  ConfigGraph* splitGraph(const std::set<uint32_t>& orig_rank_set, const std::set<uint32_t>& new_rank_set);
713  void reduceGraphToSingleRank(uint32_t rank);
714 
715  SimTime_t getMinimumPartitionLatency();
716 
717  PartitionGraph* getPartitionGraph();
718  PartitionGraph* getCollapsedPartitionGraph();
719  void annotateRanks(PartitionGraph* graph);
720  void getConnectedNoCutComps(ComponentId_t start, std::set<ComponentId_t>& group);
721  StatsConfig* getStatsConfig() { return stats_config_; }
722  StatsConfig* takeStatsConfig()
723  {
724  auto* ret = stats_config_;
725  stats_config_ = nullptr;
726  return ret;
727  }
728 
729  void setComponentConfigGraphPointers();
730  void serialize_order(SST::Core::Serialization::serializer& ser) override
731  {
732  SST_SER(links_);
733  SST_SER(comps_);
734  SST_SER(stats_config_);
735  if ( ser.mode() == SST::Core::Serialization::serializer::UNPACK ) {
736  // Need to reinitialize the ConfigGraph ptrs in the
737  // ConfigComponents
738  setComponentConfigGraphPointers();
739  }
740 
741  SST_SER(cpt_ranks);
742  SST_SER(cpt_currentSimCycle);
743  SST_SER(cpt_currentPriority);
744  SST_SER(cpt_minPart);
745  SST_SER(cpt_minPartTC);
746  SST_SER(cpt_max_event_id);
747 
748  SST_SER(*(cpt_libnames.get()));
749  SST_SER(*(cpt_shared_objects.get()));
750  SST_SER(*(cpt_stats_config.get()));
751  }
752 
753  void restoreRestartData();
754 
755  /********* vv Variables used on restarts only vv ***********/
756  RankInfo cpt_ranks;
757  SimTime_t cpt_currentSimCycle = 0;
758  int cpt_currentPriority = 0;
759  SimTime_t cpt_minPart = std::numeric_limits<SimTime_t>::max();
760  TimeConverter cpt_minPartTC;
761  uint64_t cpt_max_event_id = 0;
762 
763  std::shared_ptr<std::set<std::string>> cpt_libnames = std::make_shared<std::set<std::string>>();
764  std::shared_ptr<std::vector<char>> cpt_shared_objects = std::make_shared<std::vector<char>>();
765  std::shared_ptr<std::vector<char>> cpt_stats_config = std::make_shared<std::vector<char>>();
766 
767  /********* ^^ Variables used on restarts only ^^ ***********/
768 
769 
770 private:
771  friend class Simulation_impl;
772  friend class SSTSDLModelDefinition;
773 
774  Output output;
775 
776  ComponentId_t nextComponentId;
777 
778  ConfigLinkMap_t links_; // SparseVectorMap
779  ConfigComponentMap_t comps_; // SparseVectorMap
780  ConfigComponentNameMap_t comps_by_name_; // std::map
781 
782  std::map<std::string, LinkId_t> link_names_;
783 
784  StatsConfig* stats_config_;
785 
786  ImplementSerializable(SST::ConfigGraph)
787 
788  // Filter class
789  class GraphFilter
790  {
791  ConfigGraph* ograph_;
792  ConfigGraph* ngraph_;
793  const std::set<uint32_t>& oset_;
794  const std::set<uint32_t>& nset_;
795 
796  public:
797  GraphFilter(ConfigGraph* original_graph, ConfigGraph* new_graph, const std::set<uint32_t>& original_rank_set,
798  const std::set<uint32_t>& new_rank_set);
799 
800  ConfigLink* operator()(ConfigLink* link);
801  ConfigComponent* operator()(ConfigComponent* comp);
802  };
803 };
804 
806 {
807 public:
808  ComponentId_t id;
809  float weight;
810  RankInfo rank;
811  LinkIdMap_t links;
812 
813  ComponentIdMap_t group;
814 
815  explicit PartitionComponent(const ConfigComponent* cc)
816  {
817  id = cc->id;
818  weight = cc->weight;
819  rank = cc->rank;
820  }
821 
822  explicit PartitionComponent(LinkId_t id) :
823  id(id),
824  weight(0),
825  rank(RankInfo(RankInfo::UNASSIGNED, 0))
826  {}
827 
828  // PartitionComponent(ComponentId_t id, ConfigGraph* graph, const ComponentIdMap_t& group);
829  void print(std::ostream& os, const PartitionGraph* graph) const;
830 
831  inline ComponentId_t key() const { return id; }
832 };
833 
835 {
836 public:
837  LinkId_t id;
838  ComponentId_t component[2];
839  SimTime_t latency[2];
840  bool no_cut;
841 
842  PartitionLink(const ConfigLink& cl)
843  {
844  id = cl.id;
845  component[0] = cl.component[0];
846  component[1] = cl.component[1];
847  latency[0] = cl.latency[0];
848  latency[1] = cl.latency[1];
849  no_cut = cl.no_cut;
850  }
851 
852  inline LinkId_t key() const { return id; }
853 
854  /** Return the minimum latency of this link (from both sides) */
855  SimTime_t getMinLatency() const
856  {
857  if ( latency[0] < latency[1] ) return latency[0];
858  return latency[1];
859  }
860 
861  /** Print the Link information */
862  void print(std::ostream& os) const
863  {
864  os << " Link " << id << std::endl;
865  os << " component[0] = " << component[0] << std::endl;
866  os << " latency[0] = " << latency[0] << std::endl;
867  os << " component[1] = " << component[1] << std::endl;
868  os << " latency[1] = " << latency[1] << std::endl;
869  }
870 };
871 
872 using PartitionComponentMap_t = SparseVectorMap<ComponentId_t, PartitionComponent*>;
873 using PartitionLinkMap_t = SparseVectorMap<LinkId_t, PartitionLink>;
874 
876 {
877 private:
879  PartitionLinkMap_t links_;
880 
881 public:
882  /** Print the configuration graph */
883  void print(std::ostream& os) const
884  {
885  os << "Printing graph" << std::endl;
886  for ( PartitionComponentMap_t::const_iterator i = comps_.begin(); i != comps_.end(); ++i ) {
887  (*i)->print(os, this);
888  }
889  }
890 
891  PartitionComponentMap_t& getComponentMap() { return comps_; }
892  PartitionLinkMap_t& getLinkMap() { return links_; }
893 
894  const PartitionLink& getLink(LinkId_t id) const { return links_[id]; }
895 
896  size_t getNumComponents() { return comps_.size(); }
897 };
898 
899 } // namespace SST
900 
901 #endif // SST_CORE_CONFIGGRAPH_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:57
int slot_num
Definition: configGraph.h:389
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
std::map< std::string, StatisticId_t > enabledStatNames
Definition: configGraph.h:400
ConfigStatistic allStatConfig
Definition: configGraph.h:402
float weight
Definition: configGraph.h:391
StatisticId_t id
Definition: configGraph.h:244
ConfigComponentMap_t & getComponentMap()
Return the map of components.
Definition: configGraph.h:689
Represents the configuration of a generic component.
Definition: configGraph.h:381
Definition: configGraph.h:875
ConfigComponent(ComponentId_t id, ConfigGraph *graph, const std::string &name, const std::string &type, float weight, RankInfo rank)
Create a new Component.
Definition: configGraph.h:519
std::string type
Definition: configGraph.h:390
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:585
Definition: configGraph.h:568
Class that represents a PortModule in ConfigGraph.
Definition: configGraph.h:348
Definition: configGraph.h:241
bool enabledAllStats
Definition: configGraph.h:401
Definition: configGraph.h:805
Definition: action.cc:18
iterator end()
Returns the end iterator to the underlying vector.
Definition: sparseVectorMap.h:198
RankInfo rank
Definition: configGraph.h:392
uint16_t nextSubID
Definition: configGraph.h:406
iterator begin()
Returns the begin iterator to the underlying vector.
Definition: sparseVectorMap.h:191
uint8_t statLoadLevel
Definition: configGraph.h:395
Definition: serializable.h:23
size_t size()
Returns the number of items in the SparseVectorMap.
Definition: sparseVectorMap.h:278
ConfigLinkMap_t & getLinkMap()
Return the map of links.
Definition: configGraph.h:710
ComponentId_t id
Definition: configGraph.h:386
Params all_stat_config
Definition: configGraph.h:354
Definition: rankInfo.h:23
Definition: output.h:65
void print(std::ostream &os) const
Print the configuration graph.
Definition: configGraph.h:589
Params params
Definition: configGraph.h:394
std::map< std::string, std::vector< ConfigPortModule > > port_modules
Definition: configGraph.h:398
uint16_t nextStatID
Definition: configGraph.h:407
std::vector< LinkId_t > links
Definition: configGraph.h:393
Parameter store.
Definition: params.h:63
Definition: configGraph.h:321
std::string name
Definition: configGraph.h:388
std::vector< ConfigComponent * > subComponents
Definition: configGraph.h:404
void print(std::ostream &os) const
Print the configuration graph.
Definition: configGraph.h:883
Definition: configGraph.h:282
Definition: componentInfo.h:44
uint32_t getVerboseLevel() const
Returns object verbose level.
Definition: output.cc:109
Definition: elementinfo.h:44
ConfigGraph * graph
Definition: configGraph.h:387
uint32_t getVerboseMask() const
Returns object verbose mask.
Definition: output.cc:121
Class that stores data in a vector, but can access the data similar to a map.
Definition: sparseVectorMap.h:46
void insert(const std::string &key, const std::string &value, bool overwrite=true)
Add a key/value pair into the param object.
Definition: params.cc:171
Performs Unit math in full precision.
Definition: unitAlgebra.h:105
std::string getPrefix() const
Returns object prefix.
Definition: output.cc:133