SST 16.0.0
Structural Simulation Toolkit
configComponent.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_CONFIGCOMPONENT_H
15#define SST_CORE_MODEL_CONFIGCOMPONENT_H
16
17#include "sst/core/model/configStatistic.h"
18#include "sst/core/params.h"
19#include "sst/core/rankInfo.h"
20#include "sst/core/serialization/serializable.h"
21#include "sst/core/sparseVectorMap.h"
22#include "sst/core/sst_types.h"
23#include "sst/core/statapi/statbase.h"
24#include "sst/core/statapi/statoutput.h"
25#include "sst/core/timeConverter.h"
26#include "sst/core/unitAlgebra.h"
27
28#include <climits>
29#include <cstddef>
30#include <cstdint>
31#include <map>
32#include <memory>
33#include <ostream>
34#include <set>
35#include <string>
36#include <utility>
37#include <vector>
38
39using namespace SST::Statistics;
40
41namespace SST {
42
43class ConfigGraph;
44class ConfigLink;
45
46/**
47 Class that represents a PortModule in ConfigGraph
48 */
49class ConfigPortModule
50{
51public:
52 std::string type;
53 Params params;
54 uint8_t stat_load_level = STATISTICLOADLEVELUNINITIALIZED;
55 Params all_stat_config; /*!< If all stats are enabled, the config information for the stats */
56 std::map<std::string, Params> per_stat_configs;
57
58 ConfigPortModule() = default;
59 ConfigPortModule(const std::string& type, const Params& params) :
60 type(type),
61 params(params)
62 {}
63
64 void addParameter(const std::string& key, const std::string& value);
65 void addSharedParamSet(const std::string& set);
66 void setStatisticLoadLevel(const uint8_t level);
67 void enableAllStatistics(const SST::Params& params);
68 void enableStatistic(const std::string& statistic_name, const SST::Params& params);
69
70 void serialize_order(SST::Core::Serialization::serializer& ser)
71 {
72 SST_SER(type);
73 SST_SER(params);
74 SST_SER(stat_load_level);
75 SST_SER(all_stat_config);
76 SST_SER(per_stat_configs);
77 }
78};
79
80
81/** Represents the configuration of a generic component */
82class ConfigComponent : public SST::Core::Serialization::serializable
83{
84 friend class ComponentInfo;
85
86public:
87 ComponentId_t id; /*!< Unique ID of this component */
88 ConfigGraph* graph; /*!< Graph that this component belongs to */
89 std::string name; /*!< Name of this component, or slot name for subcomp */
90 int slot_num; /*!< Slot number. Only valid for subcomponents */
91 std::string type; /*!< Type of this component */
92 float weight; /*!< Partitioning weight for this component */
93 RankInfo rank; /*!< Parallel Rank for this component */
94 std::vector<LinkId_t> links; /*!< List of links connected */
95 Params params; /*!< Set of Parameters */
96 uint8_t statLoadLevel; /*!< Statistic load level for this component */
97
98 std::map<std::string, std::vector<ConfigPortModule>>
99 port_modules; /*!< Map of port names to port modules loaded on that port */
100 std::map<std::string, StatisticId_t>
101 enabledStatNames; /*!< Map of explicitly enabled statistic names to unique IDs */
102 bool enabledAllStats; /*!< Whether all stats in this (sub)component have been enabled */
103 ConfigStatistic allStatConfig; /*!< If all stats are enabled, the config information for the stats */
104
105 std::vector<ConfigComponent*> subComponents; /*!< List of subcomponents */
106 std::vector<double> coords;
107 uint16_t nextSubID; /*!< Next subID to use for children, if component, if subcomponent, subid of parent */
108 uint64_t next_stat_id = 1; /*!< Next statID to use */
109 bool visited; /*! Used when traversing graph to indicate component was visited already */
110
111 static constexpr ComponentId_t null_id = std::numeric_limits<ComponentId_t>::max();
112
113 inline const ComponentId_t& key() const { return id; }
114
115 /** Print Component information */
116 void print(std::ostream& os) const;
117
118 void setConfigGraphPointer(ConfigGraph* graph_ptr);
119
122 id(null_id),
123 statLoadLevel(STATISTICLOADLEVELUNINITIALIZED),
124 enabledAllStats(false),
125 nextSubID(1),
126 visited(false)
127 {}
128
129 StatisticId_t getNextStatisticID();
130
131 ConfigComponent* getParent() const;
132 std::string getFullName() const;
133
134 void setRank(RankInfo r);
135 void setWeight(double w);
136 void setCoordinates(const std::vector<double>& c);
137 void addParameter(const std::string& key, const std::string& value, bool overwrite);
138 ConfigComponent* addSubComponent(const std::string& name, const std::string& type, int slot);
139 ConfigComponent* findSubComponent(ComponentId_t);
140 const ConfigComponent* findSubComponent(ComponentId_t) const;
141 ConfigComponent* findSubComponentByName(const std::string& name);
142 ConfigStatistic* findStatistic(const std::string& name) const;
143 ConfigStatistic* insertStatistic(StatisticId_t id);
144 ConfigStatistic* findStatistic(StatisticId_t) const;
145 ConfigStatistic* enableStatistic(
146 const std::string& statisticName, const SST::Params& params, bool recursively = false);
147 ConfigStatistic* createStatistic();
148 bool reuseStatistic(const std::string& statisticName, StatisticId_t sid);
149 void addStatisticParameter(
150 const std::string& statisticName, const std::string& param, const std::string& value, bool recursively = false);
151 void setStatisticParameters(const std::string& statisticName, const Params& params, bool recursively = false);
152 void setStatisticLoadLevel(uint8_t level, bool recursively = false);
153
154 void addSharedParamSet(const std::string& set) { params.addSharedParamSet(set); }
155 [[deprecated(
156 "addGlobalParamSet() has been deprecated and will be removed in SST 16. Please use addSharedParamSet()")]]
157 void addGlobalParamSet(const std::string& set)
158 {
159 params.addSharedParamSet(set);
160 }
161 std::vector<std::string> getParamsLocalKeys() const { return params.getLocalKeys(); }
162 std::vector<std::string> getSubscribedSharedParamSets() const { return params.getSubscribedSharedParamSets(); }
163
164 [[deprecated("getSubscribedGlobalParamSets() has been deprecated and will be removed in SST 16. Please use "
165 "getSubscribedSharedParamSets()")]]
166 std::vector<std::string> getSubscribedGlobalParamSets() const
167 {
168 return params.getSubscribedSharedParamSets();
169 }
170
171 /**
172 Adds a PortModule on the port 'port' of the associated component. Returns the index of the module in the
173 component's vector of PortModules for the given port.
174 */
175 size_t addPortModule(const std::string& port, const std::string& type, const Params& params);
176
177 std::vector<LinkId_t> allLinks() const;
178
179 /**
180 Gets all the links to return, then clears links from self and
181 all subcomponents. Used when splitting graphs.
182 */
183 std::vector<LinkId_t> clearAllLinks();
184
185 /**
186 Update a Link that has had its ID changed
187
188 @param old_id Old id to replace
189
190 @param new_id New id to use
191 */
192 void replaceLinkId(LinkId_t old_id, LinkId_t new_id);
193
194 void serialize_order(SST::Core::Serialization::serializer& ser) override;
195
196 ImplementSerializable(SST::ConfigComponent)
197
198private:
199 std::map<StatisticId_t, ConfigStatistic>
200 statistics_; /* Map of explicitly enabled stat IDs to config info for each stat */
201
202 ComponentId_t getNextSubComponentID();
203
204 friend class ConfigGraph;
205 /** Checks to make sure port names are valid and that a port isn't used twice
206 */
207 void checkPorts() const;
208
209 /** Create a new Component */
210 ConfigComponent(ComponentId_t id, ConfigGraph* graph, const std::string& name, const std::string& type,
211 float weight, RankInfo rank) :
212 id(id),
213 graph(graph),
214 name(name),
215 slot_num(0),
216 type(type),
217 weight(weight),
218 rank(rank),
219 statLoadLevel(STATISTICLOADLEVELUNINITIALIZED),
220 enabledAllStats(false),
221 nextSubID(1)
222 {
223 coords.resize(3, 0.0);
224 }
225
226 ConfigComponent(ComponentId_t id, ConfigGraph* graph, uint16_t parent_subid, const std::string& name, int slot_num,
227 const std::string& type, float weight, RankInfo rank) :
228 id(id),
229 graph(graph),
230 name(name),
232 type(type),
233 weight(weight),
234 rank(rank),
235 statLoadLevel(STATISTICLOADLEVELUNINITIALIZED),
236 enabledAllStats(false),
237 nextSubID(parent_subid)
238 {
239 coords.resize(3, 0.0);
240 }
241};
242
243} // namespace SST
244
245#endif // SST_CORE_MODEL_CONFIGCOMPONENT_H
Represents the configuration of a generic component.
Definition configComponent.h:83
void replaceLinkId(LinkId_t old_id, LinkId_t new_id)
Update a Link that has had its ID changed.
Definition configComponent.cc:572
static constexpr ComponentId_t null_id
Definition configComponent.h:111
float weight
Definition configComponent.h:92
std::vector< LinkId_t > links
Definition configComponent.h:94
size_t addPortModule(const std::string &port, const std::string &type, const Params &params)
Adds a PortModule on the port 'port' of the associated component.
Definition configComponent.cc:540
std::vector< ConfigComponent * > subComponents
Definition configComponent.h:105
bool enabledAllStats
Definition configComponent.h:102
int slot_num
Definition configComponent.h:90
std::string name
Definition configComponent.h:89
uint16_t nextSubID
Definition configComponent.h:107
std::string type
Definition configComponent.h:91
ConfigStatistic allStatConfig
Definition configComponent.h:103
ComponentId_t id
Definition configComponent.h:87
void print(std::ostream &os) const
Print Component information.
Definition configComponent.cc:144
std::map< std::string, std::vector< ConfigPortModule > > port_modules
Definition configComponent.h:99
Params params
Definition configComponent.h:95
ConfigGraph * graph
Definition configComponent.h:88
uint64_t next_stat_id
Definition configComponent.h:108
ConfigComponent(ComponentId_t id, ConfigGraph *graph, const std::string &name, const std::string &type, float weight, RankInfo rank)
Create a new Component.
Definition configComponent.h:210
void checkPorts() const
Checks to make sure port names are valid and that a port isn't used twice.
Definition configComponent.cc:611
std::map< std::string, StatisticId_t > enabledStatNames
Definition configComponent.h:101
uint8_t statLoadLevel
Definition configComponent.h:96
RankInfo rank
Definition configComponent.h:93
std::vector< LinkId_t > clearAllLinks()
Gets all the links to return, then clears links from self and all subcomponents.
Definition configComponent.cc:559
A Configuration Graph A graph representing Components and Links.
Definition configGraph.h:76
Params all_stat_config
Definition configComponent.h:55
Definition configStatistic.h:41
Definition serializable.h:25
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Parameter store.
Definition params.h:65
Definition rankInfo.h:24