SST 16.0.0
Structural Simulation Toolkit
configLink.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_CONFIGLINK_H
15#define SST_CORE_MODEL_CONFIGLINK_H
16
17#include "sst/core/rankInfo.h"
18#include "sst/core/sst_types.h"
19
20#include <climits>
21#include <cstddef>
22#include <cstdint>
23#include <map>
24#include <memory>
25#include <ostream>
26#include <set>
27#include <string>
28#include <vector>
29
30namespace SST {
31namespace Core::Serialization {
32class serializer;
33}
34
35/** Represents the configuration of a generic Link */
36class ConfigLink
37{
38 // Static data structures to map latency string to an index that
39 // will hold the SimTime_t for the latency once the atomic
40 // timebase has been set.
41 static std::map<std::string, uint32_t> lat_to_index;
42
43 static uint32_t getIndexForLatency(const char* latency);
44 static std::vector<SimTime_t> initializeLinkLatencyVector();
45 SimTime_t getLatencyFromIndex(uint32_t index);
46
47 /********* vv Member variables vv ***********/
48
49public:
50 /**
51 Components that are connected to this link. They are filled in
52 the order they are attached in. If the link is marked as
53 non-local, then component[1] holds the rank of the remote
54 component.
55 */
56 ComponentId_t component_[2] = { UNSET_COMPONENT_ID, UNSET_COMPONENT_ID }; /*!< IDs of the connected components */
57
58 /**
59 This is a dual purpose data member.
60
61 Graph construction - during graph construction, it holds the
62 index into the LinkLatencyVector, which maps the stored index
63 to the actual latency string. This is done to reduce memory
64 usage because we assume there will be a small number of
65 different latencies specified.
66
67 Post graph construction - after graph construction, the latency
68 index is replaced with the SimTime_t value representing the
69 specified latency that will be used by the link to add the
70 specified latency to the event.
71
72 In both cases, the indices match the indices found in the
73 component array, and represent the latency of the link for
74 events sent from the corresponding component.
75
76 If the link is marked as non-local, then latency[1] holds the
77 thread of the remote component.
78 */
79 SimTime_t latency_[2] = { 0, 0 };
80
81 /**
82 Name of the link. This is used in two ways:
83
84 Errors - if an error is found in the graph construction, the
85 name is used to report the error to the user
86
87 Parallel load - for parallel load, links that cross partition
88 boundaries are connected by matching link names
89
90 Link names are not carried over to the simulation objects
91 */
92 std::string name_;
93
94 /**
95 id of the link. This is used primarily to find the link in ConfigGraph::links. For parallel loads, the link ID
96 is only unique on a given rank, not globally.
97
98 The ID's are not carried over to the simulation objects
99 */
100 LinkId_t id_ = 0;
101
102 /**
103 Name of the ports the link is connected to. The indices match
104 the ones used in the component array
105 */
106 std::string port_[2];
107
108 /**
109 Whether or not this link is set to be no-cut
110 */
111 bool no_cut_ = false;
112
113 /**
114 Whether this link crosses the graph boundary and is connected
115 on one end to a non-local component. If set to true, there
116 will only be one component connected (information in index 0
117 for the arrays) and the rank for the remote component will be
118 stored in component[1] and the thread in latency[1].
119 */
120 bool nonlocal_ = false;
121
122 /**
123 Set to true if this is a cross rank link
124 */
125 bool cross_rank_ = false;
126
127 /**
128 Set to true if this is a cross thread link on same rank
129 */
130 bool cross_thread_ = false;
131
132 /********* ^^ Member variables ^^ ***********/
133
134
135 /**
136 Function used when storing ConfigLinks in a SparseVectorMap
137 */
138 inline LinkId_t key() const { return id_; }
139
140 /**
141 Return the minimum latency of this link (from both sides). For non local links, it will return the local latency
142 */
143 SimTime_t getMinLatency() const
144 {
145 if ( nonlocal_ ) return latency_[0];
146 if ( latency_[0] < latency_[1] ) return latency_[0];
147 return latency_[1];
148 }
149
150 /**
151 Gets the latency as a string from the id stored in latency[]. This is only allowed to be called during graph
152 construction. After post-graph construction checks, the latency[] array no longer hold indices to the strings.
153
154 @see latency_
155 */
156 std::string latency_str(uint32_t index) const;
157
158 /**
159 Sets the link as a non-local link. After the call, the local information will be held in index 0 of the various
160 arrays, regardless of which component index holds the local information before the call.
161
162 @param which_local specifies which index is for the local side of the link
163
164 @param remote_rank_info Rank of the remote side of the link
165 */
166 void setAsNonLocal(int which_local, RankInfo remote_rank_info);
167
168 /**
169 Print the Link information
170 */
171 void print(std::ostream& os) const
172 {
173 os << "Link " << name_ << " (id = " << id_ << ")" << std::endl;
174 os << " nonlocal = " << nonlocal_ << std::endl;
175 os << " component[0] = " << component_[0] << std::endl;
176 os << " port[0] = " << port_[0] << std::endl;
177 os << " latency[0] = " << latency_[0] << std::endl;
178 os << " component[1] = " << component_[1] << std::endl;
179 os << " port[1] = " << port_[1] << std::endl;
180 os << " latency[1] = " << latency_[1] << std::endl;
181 }
182
183 /* Do not use. For serialization only */
184 ConfigLink() {}
185
186 /**
187 Serializes the ConfigLink
188 */
190 {
191 SST_SER(id_);
192 SST_SER(name_);
193 SST_SER(component_);
194 SST_SER(port_);
195 SST_SER(latency_);
196 SST_SER(nonlocal_);
197 SST_SER(no_cut_);
198 SST_SER(cross_rank_);
199 SST_SER(cross_thread_);
200 }
201
202private:
203 friend class ConfigGraph;
204 explicit ConfigLink(LinkId_t id) :
205 id_(id),
206 no_cut_(false)
207 {}
208
209 ConfigLink(LinkId_t id, const std::string& n) :
210 name_(n),
211 id_(id),
212 no_cut_(false)
213 {}
214
215 void updateLatencies();
216};
217
218
219class PartitionLink
220{
221public:
222 LinkId_t id_;
223 ComponentId_t component_[2];
224 SimTime_t latency_[2];
225 bool no_cut_;
226
227 PartitionLink(const ConfigLink& cl)
228 {
229 id_ = cl.id_;
230 component_[0] = cl.component_[0];
231 component_[1] = cl.component_[1];
232 latency_[0] = cl.latency_[0];
233 latency_[1] = cl.latency_[1];
234 no_cut_ = cl.no_cut_;
235 }
236
237 inline LinkId_t key() const { return id_; }
238
239 /** Return the minimum latency of this link (from both sides) */
240 SimTime_t getMinLatency() const
241 {
242 if ( latency_[0] < latency_[1] ) return latency_[0];
243 return latency_[1];
244 }
245
246 /** Print the Link information */
247 void print(std::ostream& os) const
248 {
249 os << " Link " << id_ << std::endl;
250 os << " component[0] = " << component_[0] << std::endl;
251 os << " latency[0] = " << latency_[0] << std::endl;
252 os << " component[1] = " << component_[1] << std::endl;
253 os << " latency[1] = " << latency_[1] << std::endl;
254 }
255};
256
257} // namespace SST
258
259#endif // SST_CORE_MODEL_CONFIGLINK_H
A Configuration Graph A graph representing Components and Links.
Definition configGraph.h:76
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Definition rankInfo.h:24