Skip to content

Commit b4710ae

Browse files
committed
update architecture
1 parent b9482a9 commit b4710ae

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

include/osp/bsp/model/BspArchitecture.hpp

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ class BspArchitecture {
211211
*/
212212
BspArchitecture()
213213
: numberOfProcessors_(2U), numberOfProcessorTypes_(1U), communicationCosts_(1U), synchronisationCosts_(2U),
214-
memoryBound_(std::vector<v_memw_t<Graph_t>>(numberOfProcessors_, 100U)), isNuma_(false),
215-
processorTypes_(std::vector<unsigned>(numberOfProcessors_, 0U)), sendCosts_(numberOfProcessors_ * numberOfProcessors_, 1U) {
214+
memoryBound_(numberOfProcessors_, 100U), isNuma_(false),
215+
processorTypes_(numberOfProcessors_, 0U), sendCosts_(numberOfProcessors_ * numberOfProcessors_, 1U) {
216216
SetSendCostDiagonalToZero();
217217
}
218218

@@ -235,8 +235,8 @@ class BspArchitecture {
235235
const v_memw_t<Graph_t> MemoryBound = 100U)
236236
: numberOfProcessors_(NumberOfProcessors), numberOfProcessorTypes_(1U), communicationCosts_(CommunicationCost),
237237
synchronisationCosts_(SynchronisationCost),
238-
memoryBound_(std::vector<v_memw_t<Graph_t>>(NumberOfProcessors, MemoryBound)), isNuma_(false),
239-
processorTypes_(std::vector<unsigned>(NumberOfProcessors, 0U)), sendCosts_(numberOfProcessors_ * numberOfProcessors_, 1U) {
238+
memoryBound_(NumberOfProcessors, MemoryBound), isNuma_(false),
239+
processorTypes_(NumberOfProcessors, 0U), sendCosts_(NumberOfProcessors * NumberOfProcessors, 1U) {
240240
if (NumberOfProcessors == 0U) {
241241
throw std::runtime_error("BspArchitecture: Number of processors must be greater than 0.");
242242
}
@@ -277,8 +277,8 @@ class BspArchitecture {
277277
BspArchitecture(const unsigned NumberOfProcessors, const v_commw_t<Graph_t> CommunicationCost, const v_commw_t<Graph_t> SynchronisationCost,
278278
const std::vector<std::vector<v_commw_t<Graph_t>>> &SendCosts)
279279
: numberOfProcessors_(NumberOfProcessors), numberOfProcessorTypes_(1U), communicationCosts_(CommunicationCost),
280-
synchronisationCosts_(SynchronisationCost), memoryBound_(std::vector<v_memw_t<Graph_t>>(NumberOfProcessors, 100U)),
281-
processorTypes_(std::vector<unsigned>(NumberOfProcessors, 0U)) {
280+
synchronisationCosts_(SynchronisationCost), memoryBound_(NumberOfProcessors, 100U),
281+
processorTypes_(NumberOfProcessors, 0U) {
282282
if (NumberOfProcessors == 0U) {
283283
throw std::runtime_error("BspArchitecture: Number of processors must be greater than 0.");
284284
}
@@ -311,9 +311,8 @@ class BspArchitecture {
311311
BspArchitecture(const unsigned NumberOfProcessors, const v_commw_t<Graph_t> CommunicationCost, const v_commw_t<Graph_t> SynchronisationCost,
312312
const v_memw_t<Graph_t> MemoryBound, const std::vector<std::vector<v_commw_t<Graph_t>>> &SendCosts)
313313
: numberOfProcessors_(NumberOfProcessors), numberOfProcessorTypes_(1U), communicationCosts_(CommunicationCost),
314-
synchronisationCosts_(SynchronisationCost),
315-
memoryBound_(std::vector<v_memw_t<Graph_t>>(NumberOfProcessors, MemoryBound)),
316-
processorTypes_(std::vector<unsigned>(NumberOfProcessors, 0U)) {
314+
synchronisationCosts_(SynchronisationCost), memoryBound_(NumberOfProcessors, MemoryBound),
315+
processorTypes_(NumberOfProcessors, 0U) {
317316
if (NumberOfProcessors == 0U) {
318317
throw std::runtime_error("BspArchitecture: Number of processors must be greater than 0.");
319318
}
@@ -441,7 +440,7 @@ class BspArchitecture {
441440
* @param MemoryBound The new memory bound for all processors.
442441
*/
443442
void setMemoryBound(const v_memw_t<Graph_t> MemoryBound) {
444-
memoryBound_ = std::vector<v_memw_t<Graph_t>>(numberOfProcessors_, MemoryBound);
443+
memoryBound_.assign(numberOfProcessors_, MemoryBound);
445444
}
446445

447446
/**
@@ -499,12 +498,12 @@ class BspArchitecture {
499498
}
500499
numberOfProcessors_ = numberOfProcessors;
501500
numberOfProcessorTypes_ = 1U;
502-
processorTypes_ = std::vector<unsigned>(numberOfProcessors_, 0U);
501+
processorTypes_.assign(numberOfProcessors_, 0U);
503502

504503
InitializeUniformSendCosts();
505504

506505
// initialize memory bound to 100 for all processors
507-
memoryBound_.resize(numberOfProcessors_, 100U);
506+
memoryBound_.assign(numberOfProcessors_, 100U);
508507
}
509508

510509
/**
@@ -525,7 +524,7 @@ class BspArchitecture {
525524
InitializeUniformSendCosts();
526525

527526
// initialize memory bound to 100 for all processors
528-
memoryBound_.resize(numberOfProcessors_, 100U);
527+
memoryBound_.assign(numberOfProcessors_, 100U);
529528
UpdateNumberOfProcessorTypes();
530529
}
531530

@@ -551,8 +550,8 @@ class BspArchitecture {
551550
numberOfProcessors_ = std::accumulate(processorTypeCount.begin(), processorTypeCount.end(), 0U);
552551

553552
// initialize processor types and memory bound
554-
processorTypes_ = std::vector<v_type_t<Graph_t>>(numberOfProcessors_, 0U);
555-
memoryBound_ = std::vector<v_memw_t<Graph_t>>(numberOfProcessors_, 0U);
553+
processorTypes_.assign(numberOfProcessors_, 0U);
554+
memoryBound_.assign(numberOfProcessors_, 0U);
556555

557556
unsigned offset = 0U;
558557
for (unsigned i = 0U; i < processorTypeCount.size(); i++) {
@@ -620,14 +619,14 @@ class BspArchitecture {
620619
[[nodiscard]] v_commw_t<Graph_t> synchronisationCosts() const { return synchronisationCosts_; }
621620

622621
/**
623-
* @brief Returns the send costs matrix.
622+
* @brief Returns a the send costs matrix. Internally the matrix is stored as a flattened matrix. The allocates, computes and returns the matrix on the fly.
624623
* @return The send costs matrix.
625624
*/
626-
[[nodiscard]] std::vector<std::vector<v_commw_t<Graph_t>>> sendCostMatrix() const {
625+
[[nodiscard]] std::vector<std::vector<v_commw_t<Graph_t>>> sendCost() const {
627626
std::vector<std::vector<v_commw_t<Graph_t>>> matrix(numberOfProcessors_, std::vector<v_commw_t<Graph_t>>(numberOfProcessors_));
628627
for (unsigned i = 0; i < numberOfProcessors_; ++i) {
629628
for (unsigned j = 0; j < numberOfProcessors_; ++j) {
630-
matrix[i][j] = sendCosts_[FlatIndex(i, j)];
629+
matrix[i][j] = sendCosts_.at(FlatIndex(i, j));
631630
}
632631
}
633632
return matrix;
@@ -666,12 +665,6 @@ class BspArchitecture {
666665
*/
667666
[[nodiscard]] v_commw_t<Graph_t> sendCosts(const unsigned p1, const unsigned p2) const { return sendCosts_.at(FlatIndex(p1, p2)); }
668667

669-
/**
670-
* @brief Returns the send costs matrix.
671-
* @return The send costs matrix.
672-
*/
673-
[[nodiscard]] std::vector<std::vector<v_commw_t<Graph_t>>> sendCosts() const { return sendCostMatrix(); }
674-
675668
/**
676669
* @brief Returns the type of a specific processor.
677670
* @param p1 The processor index.

tests/bsp_architecture.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ BOOST_AUTO_TEST_CASE(ParameterizedConstructorTest) {
6161

6262
BOOST_CHECK_EQUAL(architecture.maxMemoryBoundProcType(0), 100);
6363

64-
BOOST_TEST(architecture.sendCostMatrix() == uniform_sent_costs);
64+
BOOST_TEST(architecture.sendCost() == uniform_sent_costs);
6565

6666
std::vector<std::vector<int>> expectedSendCosts = {{0, 2, 2, 2}, {2, 0, 2, 2}, {2, 2, 0, 2}, {2, 2, 2, 0}};
6767

6868
architecture.SetSendCosts(expectedSendCosts);
69-
BOOST_TEST(architecture.sendCostMatrix() == expectedSendCosts);
69+
BOOST_TEST(architecture.sendCost() == expectedSendCosts);
7070

7171
BOOST_CHECK_EQUAL(architecture.communicationCosts(0, 1), 4);
7272
BOOST_CHECK_EQUAL(architecture.communicationCosts(0, 0), 0);
7373

7474
architecture.SetUniformSendCost();
75-
BOOST_TEST(architecture.sendCostMatrix() == uniform_sent_costs);
75+
BOOST_TEST(architecture.sendCost() == uniform_sent_costs);
7676

7777
BOOST_CHECK_EQUAL(architecture.communicationCosts(0, 1), 2);
7878
BOOST_CHECK_EQUAL(architecture.communicationCosts(0, 0), 0);

0 commit comments

Comments
 (0)