Skip to content

Commit 7f8aacd

Browse files
committed
added to_string, removed duplicate comment.
1 parent b4710ae commit 7f8aacd

File tree

2 files changed

+33
-57
lines changed

2 files changed

+33
-57
lines changed

include/osp/bsp/model/BspArchitecture.hpp

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,36 @@ enum class MEMORY_CONSTRAINT_TYPE {
4949
LOCAL_SOURCES_INC_EDGES /** Memory constraints are local source incident edges. Experimental. */
5050
};
5151

52-
inline std::ostream &operator<<(std::ostream &os, MEMORY_CONSTRAINT_TYPE type) {
52+
/**
53+
* @brief Converts the enum to a string literal.
54+
* Returns const char* to avoid std::string allocation overhead.
55+
*/
56+
inline const char *to_string(MEMORY_CONSTRAINT_TYPE type) {
5357
switch (type) {
5458
case MEMORY_CONSTRAINT_TYPE::NONE:
55-
os << "NONE";
56-
break;
59+
return "NONE";
5760
case MEMORY_CONSTRAINT_TYPE::LOCAL:
58-
os << "LOCAL";
59-
break;
61+
return "LOCAL";
6062
case MEMORY_CONSTRAINT_TYPE::GLOBAL:
61-
os << "GLOBAL";
62-
break;
63+
return "GLOBAL";
6364
case MEMORY_CONSTRAINT_TYPE::PERSISTENT_AND_TRANSIENT:
64-
os << "PERSISTENT_AND_TRANSIENT";
65-
break;
65+
return "PERSISTENT_AND_TRANSIENT";
6666
case MEMORY_CONSTRAINT_TYPE::LOCAL_IN_OUT:
67-
os << "LOCAL_IN_OUT";
68-
break;
67+
return "LOCAL_IN_OUT";
6968
case MEMORY_CONSTRAINT_TYPE::LOCAL_INC_EDGES:
70-
os << "LOCAL_INC_EDGES";
71-
break;
69+
return "LOCAL_INC_EDGES";
7270
case MEMORY_CONSTRAINT_TYPE::LOCAL_SOURCES_INC_EDGES:
73-
os << "LOCAL_SOURCES_INC_EDGES";
74-
break;
71+
return "LOCAL_SOURCES_INC_EDGES";
7572
default:
76-
os << "UNKNOWN";
77-
break;
73+
return "UNKNOWN";
7874
}
79-
return os;
75+
}
76+
77+
/**
78+
* @brief Stream operator overload using the helper function.
79+
*/
80+
inline std::ostream &operator<<(std::ostream &os, MEMORY_CONSTRAINT_TYPE type) {
81+
return os << to_string(type);
8082
}
8183

8284
/**
@@ -113,54 +115,34 @@ class BspArchitecture {
113115
static_assert(is_computational_dag_v<Graph_t>, "BspSchedule can only be used with computational DAGs.");
114116

115117
private:
116-
/**
117-
* @brief The number of processors in the architecture. Must be at least 1.
118-
*
119-
*/
118+
/** @brief The number of processors in the architecture. Must be at least 1. */
120119
unsigned numberOfProcessors_;
121120

122-
/**
123-
* @brief The number of processor types in the architecture. See processorTypes_ for more details.
124-
*
125-
*/
121+
/** @brief The number of processor types in the architecture. See processorTypes_ for more details. */
126122
unsigned numberOfProcessorTypes_;
127123

128-
/**
129-
* @brief The communication costs, typically denoted 'g' for the BSP model.
130-
*/
124+
/** @brief The communication costs, typically denoted 'g' for the BSP model. */
131125
v_commw_t<Graph_t> communicationCosts_;
132126

133-
/**
134-
* @brief The synchronisation costs, typically denoted 'L' for the BSP model.
135-
*/
127+
/** @brief The synchronisation costs, typically denoted 'L' for the BSP model. */
136128
v_commw_t<Graph_t> synchronisationCosts_;
137129

138-
/**
139-
* @brief The architecture allows to specify memory bounds per processor.
140-
*/
130+
/** @brief The architecture allows to specify memory bounds per processor. */
141131
std::vector<v_memw_t<Graph_t>> memoryBound_;
142132

143-
/**
144-
* @brief Flag to indicate whether the architecture is NUMA , i.e., whether the send costs are different for different pairs of processors.
145-
*/
133+
/** @brief Flag to indicate whether the architecture is NUMA , i.e., whether the send costs are different for different pairs of processors. */
146134
bool isNuma_;
147135

148-
/**
149-
* @brief The architecture allows to specify processor types. Processor types are used to express compatabilities, which can be specified in the BspInstance, regarding node types.
150-
*/
136+
/** @brief The architecture allows to specify processor types. Processor types are used to express compatabilities, which can be specified in the BspInstance, regarding node types. */
151137
std::vector<unsigned> processorTypes_;
152138

153-
/**
154-
* @brief A flattened p x p matrix of send costs.
155-
* Access via index [i * numberOfProcessors_ + j].
156-
*/
139+
/** @brief A flattened p x p matrix of send costs. Access via index [i * numberOfProcessors_ + j]. */
157140
std::vector<v_commw_t<Graph_t>> sendCosts_;
158141

159-
/**
160-
* @brief The memory constraint type.
161-
*/
142+
/** @brief The memory constraint type. */
162143
MEMORY_CONSTRAINT_TYPE memoryConstraintType_ = MEMORY_CONSTRAINT_TYPE::NONE;
163144

145+
/** @brief Helper function to calculate the index of a flattened p x p matrix. */
164146
std::size_t FlatIndex(const unsigned row, const unsigned col) const {
165147
return static_cast<std::size_t>(row) * numberOfProcessors_ + col;
166148
}
@@ -184,15 +166,15 @@ class BspArchitecture {
184166
void UpdateNumberOfProcessorTypes() {
185167
numberOfProcessorTypes_ = 0U;
186168
for (unsigned p = 0U; p < numberOfProcessors_; p++) {
187-
if (processorTypes_.at(p) >= numberOfProcessorTypes_) {
188-
numberOfProcessorTypes_ = processorTypes_.at(p) + 1U;
169+
if (processorTypes_[p] >= numberOfProcessorTypes_) {
170+
numberOfProcessorTypes_ = processorTypes_[p] + 1U;
189171
}
190172
}
191173
}
192174

193175
void SetSendCostDiagonalToZero() {
194176
for (unsigned i = 0U; i < numberOfProcessors_; i++) {
195-
sendCosts_.at(FlatIndex(i, i)) = 0U;
177+
sendCosts_[FlatIndex(i, i)] = 0U;
196178
}
197179
}
198180

include/osp/bsp/model/BspInstance.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,6 @@ class BspInstance {
205205

206206
/**
207207
* @brief Returns a copy of the send costs matrix.
208-
*
209-
* @return A copy of the send costs matrix.
210-
*/
211-
/**
212-
* @brief Returns a copy of the send costs matrix.
213-
*
214208
* @return A copy of the send costs matrix.
215209
*/
216210
inline std::vector<std::vector<v_commw_t<Graph_t>>> sendCostMatrix() const {

0 commit comments

Comments
 (0)