SST 16.0.0
Structural Simulation Toolkit
configGraph.h
1// -*- c++ -*-
2
3// Copyright 2009-2026 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-2026, 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_MODEL_CONFIGGRAPH_H
15#define SST_CORE_MODEL_CONFIGGRAPH_H
16
17#include "sst/core/model/configComponent.h"
18#include "sst/core/model/configLink.h"
19#include "sst/core/model/configStatistic.h"
20#include "sst/core/params.h"
21#include "sst/core/rankInfo.h"
22#include "sst/core/serialization/serializable.h"
23#include "sst/core/sparseVectorMap.h"
24#include "sst/core/sst_types.h"
25#include "sst/core/statapi/statbase.h"
26#include "sst/core/statapi/statoutput.h"
27#include "sst/core/timeConverter.h"
28#include "sst/core/unitAlgebra.h"
29
30#include <climits>
31#include <cstddef>
32#include <cstdint>
33#include <map>
34#include <memory>
35#include <ostream>
36#include <set>
37#include <string>
38#include <vector>
39
40using namespace SST::Statistics;
41
42namespace SST {
43
44class Simulation;
45
46class Config;
47class TimeLord;
48struct StatsConfig;
49class ConfigComponent;
50
51using ComponentIdMap_t = SparseVectorMap<ComponentId_t>;
52using LinkIdMap_t = std::vector<LinkId_t>;
53
54class ConfigLink;
55
56
57using ConfigLinkMap_t = SparseVectorMap<LinkId_t, ConfigLink*>;
58
59/** Map names to Links */
60/** Map IDs to Components */
61using ConfigComponentMap_t = SparseVectorMap<ComponentId_t, ConfigComponent*>;
62/** Map names to Components */
63using ConfigComponentNameMap_t = std::map<std::string, ComponentId_t>;
64/** Map names to Parameter Sets: XML only */
65using ParamsMap_t = std::map<std::string, Params*>;
66/** Map names to variable values: XML only */
67using VariableMap_t = std::map<std::string, std::string>;
68
69class PartitionGraph;
70
71
72/** A Configuration Graph
73 * A graph representing Components and Links
74 */
76{
77public:
78
79 static bool serialize_for_checkpoint;
80
81 /** Print the configuration graph */
82 void print(std::ostream& os) const
83 {
84 os << "Printing graph" << std::endl;
85 os << "Components:" << std::endl;
86 for ( ConfigComponentMap_t::const_iterator i = comps_.begin(); i != comps_.end(); ++i ) {
87 (*i)->print(os);
88 }
89 os << "Links:" << std::endl;
90 for ( auto i = links_.begin(); i != links_.end(); ++i ) {
91 (*i)->print(os);
92 }
93 }
94
97
98 size_t getNumComponents() { return comps_.data.size(); }
99
100 size_t getNumComponentsInMPIRank(uint32_t rank);
101
102 /** Helper function to set all the ranks to the same value */
103 void setComponentRanks(RankInfo rank);
104 /** Checks to see if rank contains at least one component */
106 /** Verify that all components have valid Ranks assigned */
107 bool checkRanks(RankInfo ranks);
108
109 // API for programmatic initialization
110 /** Create a new component */
111 ComponentId_t addComponent(const std::string& name, const std::string& type);
112
113 /** Add a parameter to a shared param set */
114 void addSharedParam(const std::string& shared_set, const std::string& key, const std::string& value);
115
116 [[deprecated("addGlobalParam() has been deprecated and will be removed in SST 16. Please use addSharedParam()")]]
117 void addGlobalParam(const std::string& shared_set, const std::string& key, const std::string& value);
118
119 /** Set the statistic output module */
120 void setStatisticOutput(const std::string& name);
121
122 /** Add parameter to the statistic output module */
123 void addStatisticOutputParameter(const std::string& param, const std::string& value);
124
125 /** Set a set of parameter to the statistic output module */
126 void setStatisticOutputParams(const Params& p);
127
128 /** Set the statistic system load level */
129 void setStatisticLoadLevel(uint8_t loadLevel);
130
131 std::vector<ConfigStatOutput>& getStatOutputs();
132
133 const ConfigStatOutput& getStatOutput(size_t index = 0) const;
134
135 long getStatLoadLevel() const;
136
137 /**
138 Create link and return it's ID. The provided name is not
139 checked against existing links
140 */
141 LinkId_t createLink(const char* name, const char* latency = nullptr);
142
143 /** Add a Link to a Component on a given Port */
144 void addLink(ComponentId_t comp_id, LinkId_t link_id, const char* port, const char* latency_str);
145
146 /**
147 Adds the remote rank info for nonlocal links
148 */
149 void addNonLocalLink(LinkId_t link_id, int rank, int thread);
150
151 /** Set a Link to be no-cut */
152 void setLinkNoCut(LinkId_t link_name);
153
154 /** Perform any post-creation cleanup processes */
155 void postCreationCleanup();
156
157 /** Check the graph for Structural errors */
159
160 // Temporary until we have a better API
161 /** Return the map of components */
162 ConfigComponentMap_t& getComponentMap() { return comps_; }
163
164 void getNonLocalLinks(std::vector<ConfigLink*>& vec);
165
166 void updateLinkId(ConfigLink* link, LinkId_t new_id);
167 void resortLinkMap();
168
169 const std::map<std::string, ConfigStatGroup>& getStatGroups() const;
170 ConfigStatGroup* getStatGroup(const std::string& name);
171
172 bool containsComponent(ComponentId_t id) const;
173 ConfigComponent* findComponent(ComponentId_t);
174 ConfigComponent* findComponentByName(const std::string& name);
175 const ConfigComponent* findComponent(ComponentId_t) const;
176
177 ConfigStatistic* findStatistic(ComponentId_t, StatisticId_t) const;
178
179 /** Return the map of links */
180 ConfigLinkMap_t& getLinkMap() { return links_; }
181
182 ConfigGraph* splitGraph(const std::set<uint32_t>& orig_rank_set, const std::set<uint32_t>& new_rank_set);
183 void reduceGraphToSingleRank(uint32_t rank);
184
185 SimTime_t getMinimumPartitionLatency();
186
187 PartitionGraph* getPartitionGraph();
188 PartitionGraph* getCollapsedPartitionGraph();
189 void annotateRanks(PartitionGraph* graph);
190 void getConnectedNoCutComps(ComponentId_t start, std::set<ComponentId_t>& group);
191 StatsConfig* getStatsConfig() { return stats_config_; }
192 StatsConfig* takeStatsConfig()
193 {
194 auto* ret = stats_config_;
195 stats_config_ = nullptr;
196 return ret;
197 }
198
199 void annotateCompRestartLocation(ComponentId_t cid, const std::string& filename, uint64_t offset);
200
201 void setComponentConfigGraphPointers();
202 void serialize_order(SST::Core::Serialization::serializer& ser) override
203 {
204 SST_SER(links_);
205 SST_SER(comps_);
206
207 if ( ser.mode() == SST::Core::Serialization::serializer::UNPACK ) {
208 // Need to reinitialize the ConfigGraph ptrs in the
209 // ConfigComponents
210 setComponentConfigGraphPointers();
211 }
212
213 // If we are serializing for checkpointing, we only needed the links and components
214 if ( serialize_for_checkpoint ) return;
215
216 SST_SER(stats_config_);
217
218 SST_SER(cpt_ranks);
219 SST_SER(cpt_currentSimCycle);
220 SST_SER(cpt_currentPriority);
221 SST_SER(cpt_minPart);
222 SST_SER(cpt_minPartTC);
223 SST_SER(cpt_max_event_id);
224 SST_SER(cpt_remap_partitions);
225 SST_SER(cpt_repartition);
226
227 SST_SER(*(cpt_libnames.get()));
228 SST_SER(*(cpt_shared_objects.get()));
229 SST_SER(*(cpt_stats_config.get()));
230 }
231
232 void restoreRestartData();
233
234 /********* vv Variables used on restarts only vv ***********/
235 RankInfo cpt_ranks;
236 SimTime_t cpt_currentSimCycle = 0;
237 int cpt_currentPriority = 0;
238 SimTime_t cpt_minPart = std::numeric_limits<SimTime_t>::max();
239 TimeConverter cpt_minPartTC;
240 uint64_t cpt_max_event_id = 0;
241 bool cpt_remap_partitions = false;
242 bool cpt_repartition = false;
243 std::string cpt_orig_configgraph; // Does not need to be serialized (only needed on rank 0)
244
245 std::shared_ptr<std::set<std::string>> cpt_libnames = std::make_shared<std::set<std::string>>();
246 std::shared_ptr<std::vector<char>> cpt_shared_objects = std::make_shared<std::vector<char>>();
247 std::shared_ptr<std::vector<char>> cpt_stats_config = std::make_shared<std::vector<char>>();
248
249 /********* ^^ Variables used on restarts only ^^ ***********/
250
251
252private:
253 friend class Simulation;
254
255 Output output;
256 LinkId_t link_rank_mask = 0;
257
258 ComponentId_t nextComponentId;
259
260 ConfigLinkMap_t links_; // SparseVectorMap
261 ConfigComponentMap_t comps_; // SparseVectorMap
262 ConfigComponentNameMap_t comps_by_name_; // std::map
263
264 std::map<std::string, LinkId_t> link_names_;
265
266 StatsConfig* stats_config_;
267
268 ImplementSerializable(SST::ConfigGraph)
269
270 // Filter class
271 class GraphFilter
272 {
273 ConfigGraph* ograph_;
274 ConfigGraph* ngraph_;
275 const std::set<uint32_t>& oset_;
276 const std::set<uint32_t>& nset_;
277
278 public:
279 GraphFilter(ConfigGraph* original_graph, ConfigGraph* new_graph, const std::set<uint32_t>& original_rank_set,
280 const std::set<uint32_t>& new_rank_set);
281
282 ConfigLink* operator()(ConfigLink* link);
283 ConfigComponent* operator()(ConfigComponent* comp);
284 };
285};
286
287class PartitionComponent
288{
289public:
290 ComponentId_t id;
291 float weight;
292 RankInfo rank;
293 LinkIdMap_t links;
294
295 ComponentIdMap_t group;
296
297 explicit PartitionComponent(const ConfigComponent* cc)
298 {
299 id = cc->id;
300 weight = cc->weight;
301 rank = cc->rank;
302 }
303
304 explicit PartitionComponent(LinkId_t id) :
305 id(id),
306 weight(0),
307 rank(RankInfo(RankInfo::UNASSIGNED, 0))
308 {}
309
310 // PartitionComponent(ComponentId_t id, ConfigGraph* graph, const ComponentIdMap_t& group);
311 void print(std::ostream& os, const PartitionGraph* graph) const;
312
313 inline ComponentId_t key() const { return id; }
314};
315
316using PartitionComponentMap_t = SparseVectorMap<ComponentId_t, PartitionComponent*>;
317using PartitionLinkMap_t = SparseVectorMap<LinkId_t, PartitionLink>;
318
320{
321private:
322 PartitionComponentMap_t comps_;
323 PartitionLinkMap_t links_;
324
325public:
326 /** Print the configuration graph */
327 void print(std::ostream& os) const
328 {
329 os << "Printing graph" << std::endl;
330 for ( PartitionComponentMap_t::const_iterator i = comps_.begin(); i != comps_.end(); ++i ) {
331 (*i)->print(os, this);
332 }
333 }
334
335 PartitionComponentMap_t& getComponentMap() { return comps_; }
336 PartitionLinkMap_t& getLinkMap() { return links_; }
337
338 const PartitionLink& getLink(LinkId_t id) const { return links_[id]; }
339
340 size_t getNumComponents() { return comps_.size(); }
341};
342
343} // namespace SST
344
345#endif // SST_CORE_MODEL_CONFIGGRAPH_H
Represents the configuration of a generic component.
Definition configComponent.h:83
float weight
Definition configComponent.h:92
ComponentId_t id
Definition configComponent.h:87
RankInfo rank
Definition configComponent.h:93
A Configuration Graph A graph representing Components and Links.
Definition configGraph.h:76
void setStatisticLoadLevel(uint8_t loadLevel)
Set the statistic system load level.
Definition configGraph.cc:359
ComponentId_t addComponent(const std::string &name, const std::string &type)
Create a new component.
Definition configGraph.cc:320
void addNonLocalLink(LinkId_t link_id, int rank, int thread)
Adds the remote rank info for nonlocal links.
Definition configGraph.cc:415
ConfigComponentMap_t & getComponentMap()
Return the map of components.
Definition configGraph.h:162
void setLinkNoCut(LinkId_t link_name)
Set a Link to be no-cut.
Definition configGraph.cc:450
bool checkForStructuralErrors()
Check the graph for Structural errors.
Definition configGraph.cc:238
void postCreationCleanup()
Perform any post-creation cleanup processes.
Definition configGraph.cc:202
void addSharedParam(const std::string &shared_set, const std::string &key, const std::string &value)
Add a parameter to a shared param set.
Definition configGraph.cc:335
bool checkRanks(RankInfo ranks)
Verify that all components have valid Ranks assigned.
Definition configGraph.cc:167
bool containsComponentInRank(RankInfo rank)
Checks to see if rank contains at least one component.
Definition configGraph.cc:158
void setStatisticOutputParams(const Params &p)
Set a set of parameter to the statistic output module.
Definition configGraph.cc:347
LinkId_t createLink(const char *name, const char *latency=nullptr)
Create link and return it's ID.
Definition configGraph.cc:435
void addStatisticOutputParameter(const std::string &param, const std::string &value)
Add parameter to the statistic output module.
Definition configGraph.cc:353
void addLink(ComponentId_t comp_id, LinkId_t link_id, const char *port, const char *latency_str)
Add a Link to a Component on a given Port.
Definition configGraph.cc:365
ConfigLinkMap_t & getLinkMap()
Return the map of links.
Definition configGraph.h:180
void setComponentRanks(RankInfo rank)
Helper function to set all the ranks to the same value.
Definition configGraph.cc:150
void print(std::ostream &os) const
Print the configuration graph.
Definition configGraph.h:82
void setStatisticOutput(const std::string &name)
Set the statistic output module.
Definition configGraph.cc:341
Definition configStatistic.h:82
Definition configStatistic.h:121
Definition configStatistic.h:41
Class to contain SST Simulation Configuration variables.
Definition config.h:52
Definition serializable.h:25
Parameter store.
Definition params.h:65
Definition configGraph.h:320
void print(std::ostream &os) const
Print the configuration graph.
Definition configGraph.h:327
Definition rankInfo.h:24
Main control class for a SST Simulation.
Definition simulation.h:121
Class that stores data in a vector, but can access the data similar to a map.
Definition sparseVectorMap.h:47
size_t size()
Returns the number of items in the SparseVectorMap.
Definition sparseVectorMap.h:278
Class for creating and managing TimeConverter objects.
Definition timeLord.h:41
Definition configStatistic.h:143