Skip to content

Commit 738f9e6

Browse files
committed
arch constructor
1 parent 78cf005 commit 738f9e6

2 files changed

Lines changed: 25 additions & 64 deletions

File tree

include/osp/bsp/model/BspArchitecture.hpp

Lines changed: 24 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,37 @@ class BspArchitecture {
194194
* @param CommunicationCost The communication cost between processors. Default: 1.
195195
* @param SynchronisationCost The synchronization cost between processors. Default: 2.
196196
* @param MemoryBound The memory bound for each processor (default: 100).
197+
* @param SendCosts The matrix of send costs between processors. Needs to be a processors x processors matrix. Diagonal entries are forced to zero. Default: empty (uniform costs).
197198
*/
198199
BspArchitecture(const unsigned NumberOfProcessors = 2U, const v_commw_t<Graph_t> CommunicationCost = 1U, const v_commw_t<Graph_t> SynchronisationCost = 2U,
199-
const v_memw_t<Graph_t> MemoryBound = 100U)
200+
const v_memw_t<Graph_t> MemoryBound = 100U, const std::vector<std::vector<v_commw_t<Graph_t>>> &SendCosts = {})
200201
: numberOfProcessors_(NumberOfProcessors), numberOfProcessorTypes_(1U), communicationCosts_(CommunicationCost),
201202
synchronisationCosts_(SynchronisationCost),
202203
memoryBound_(NumberOfProcessors, MemoryBound), isNuma_(false),
203-
processorTypes_(NumberOfProcessors, 0U), sendCosts_(NumberOfProcessors * NumberOfProcessors, 1U) {
204+
processorTypes_(NumberOfProcessors, 0U) {
204205
if (NumberOfProcessors == 0U) {
205206
throw std::runtime_error("BspArchitecture: Number of processors must be greater than 0.");
206207
}
207-
SetSendCostDiagonalToZero();
208+
209+
if (SendCosts.empty()) {
210+
InitializeUniformSendCosts();
211+
} else {
212+
if (NumberOfProcessors != SendCosts.size()) {
213+
throw std::invalid_argument("sendCosts_ needs to be a processors x processors matrix.\n");
214+
}
215+
if (std::any_of(SendCosts.begin(), SendCosts.end(),
216+
[NumberOfProcessors](const auto &thing) { return thing.size() != NumberOfProcessors; })) {
217+
throw std::invalid_argument("sendCosts_ needs to be a processors x processors matrix.\n");
218+
}
219+
220+
sendCosts_.reserve(NumberOfProcessors * NumberOfProcessors);
221+
for (const auto &row : SendCosts) {
222+
sendCosts_.insert(sendCosts_.end(), row.begin(), row.end());
223+
}
224+
225+
SetSendCostDiagonalToZero();
226+
isNuma_ = AreSendCostsNuma();
227+
}
208228
}
209229

210230
BspArchitecture(const BspArchitecture &other) = default;
@@ -246,62 +266,7 @@ class BspArchitecture {
246266
*/
247267
BspArchitecture(const unsigned NumberOfProcessors, const v_commw_t<Graph_t> CommunicationCost, const v_commw_t<Graph_t> SynchronisationCost,
248268
const std::vector<std::vector<v_commw_t<Graph_t>>> &SendCosts)
249-
: numberOfProcessors_(NumberOfProcessors), numberOfProcessorTypes_(1U), communicationCosts_(CommunicationCost),
250-
synchronisationCosts_(SynchronisationCost), memoryBound_(NumberOfProcessors, 100U),
251-
processorTypes_(NumberOfProcessors, 0U) {
252-
if (NumberOfProcessors == 0U) {
253-
throw std::runtime_error("BspArchitecture: Number of processors must be greater than 0.");
254-
}
255-
if (NumberOfProcessors != SendCosts.size()) {
256-
throw std::invalid_argument("sendCosts_ needs to be a processors x processors matrix.\n");
257-
}
258-
if (std::any_of(SendCosts.begin(), SendCosts.end(),
259-
[NumberOfProcessors](const auto &thing) { return thing.size() != NumberOfProcessors; })) {
260-
throw std::invalid_argument("sendCosts_ needs to be a processors x processors matrix.\n");
261-
}
262-
263-
sendCosts_.reserve(NumberOfProcessors * NumberOfProcessors);
264-
for (const auto &row : SendCosts) {
265-
sendCosts_.insert(sendCosts_.end(), row.begin(), row.end());
266-
}
267-
268-
SetSendCostDiagonalToZero();
269-
isNuma_ = AreSendCostsNuma();
270-
}
271-
272-
/**
273-
* @brief Constructs a BspArchitecture object with custom send costs and memory bound.
274-
*
275-
* @param NumberOfProcessors The number of processors. Must be greater than 0.
276-
* @param CommunicationCost The communication cost.
277-
* @param SynchronisationCost The synchronization cost.
278-
* @param MemoryBound The memory bound for each processor.
279-
* @param SendCosts The matrix of send costs between processors. Needs to be a processors x processors matrix. Diagonal entries are forced to zero.
280-
*/
281-
BspArchitecture(const unsigned NumberOfProcessors, const v_commw_t<Graph_t> CommunicationCost, const v_commw_t<Graph_t> SynchronisationCost,
282-
const v_memw_t<Graph_t> MemoryBound, const std::vector<std::vector<v_commw_t<Graph_t>>> &SendCosts)
283-
: numberOfProcessors_(NumberOfProcessors), numberOfProcessorTypes_(1U), communicationCosts_(CommunicationCost),
284-
synchronisationCosts_(SynchronisationCost), memoryBound_(NumberOfProcessors, MemoryBound),
285-
processorTypes_(NumberOfProcessors, 0U) {
286-
if (NumberOfProcessors == 0U) {
287-
throw std::runtime_error("BspArchitecture: Number of processors must be greater than 0.");
288-
}
289-
if (NumberOfProcessors != SendCosts.size()) {
290-
throw std::invalid_argument("sendCosts_ needs to be a processors x processors matrix.\n");
291-
}
292-
if (std::any_of(SendCosts.begin(), SendCosts.end(),
293-
[NumberOfProcessors](const auto &thing) { return thing.size() != NumberOfProcessors; })) {
294-
throw std::invalid_argument("sendCosts_ needs to be a processors x processors matrix.\n");
295-
}
296-
297-
sendCosts_.reserve(NumberOfProcessors * NumberOfProcessors);
298-
for (const auto &row : SendCosts) {
299-
sendCosts_.insert(sendCosts_.end(), row.begin(), row.end());
300-
}
301-
302-
SetSendCostDiagonalToZero();
303-
isNuma_ = AreSendCostsNuma();
304-
}
269+
: BspArchitecture(NumberOfProcessors, CommunicationCost, SynchronisationCost, 100U, SendCosts) {}
305270

306271
/**
307272
* @brief Sets the uniform send cost for each pair of processors.

include/osp/bsp/model/BspInstance.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,10 @@ class BspInstance {
271271
}
272272

273273
/**
274-
* @brief Sets the node-processor compatibility matrix. The matrix is copied.
274+
* @brief Sets the node-processor compatibility matrix. The matrix is copied. Dimensions are not checked.
275275
* @param compatibility_ The compatibility matrix.
276-
* @throw std::runtime_error if the compatibility matrix size does not match the number of node types and processor types.
277276
*/
278277
void setNodeProcessorCompatibility(const std::vector<std::vector<bool>> &compatibility_) {
279-
if (compatibility_.size() < cdag.num_vertex_types() || compatibility_[0].size() < architecture.getNumberOfProcessorTypes()) {
280-
throw std::runtime_error("Compatibility matrix size does not match the number of node types and processor types.");
281-
}
282278
nodeProcessorCompatibility = compatibility_;
283279
}
284280

0 commit comments

Comments
 (0)