Skip to content

Commit 559181f

Browse files
committed
Apply fixes
1 parent fcc305b commit 559181f

File tree

8 files changed

+74
-45
lines changed

8 files changed

+74
-45
lines changed

tasks/klimov_m_torus/common/include/common.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
namespace klimov_m_torus {
99

1010
struct TransferRequest {
11-
int sender;
12-
int receiver;
13-
std::vector<int> data;
11+
int sender;
12+
int receiver;
13+
std::vector<int> data;
1414
};
1515

1616
struct TransferResult {
17-
std::vector<int> received_data;
18-
std::vector<int> route;
17+
std::vector<int> received_data;
18+
std::vector<int> route;
1919
};
2020

2121
using InType = TransferRequest;
2222
using OutType = TransferResult;
23-
using TestParam = std::tuple<int>;
23+
using TestParam = std::tuple<int>;
2424
using BaseTask = ppc::task::Task<InType, OutType>;
2525

26-
} // namespace klimov_m_torus
26+
} // namespace klimov_m_torus

tasks/klimov_m_torus/mpi/include/ops_mpi.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class TorusMeshCommunicator : public BaseTask {
3030
void DistributeSenderReceiver(int &src, int &dst);
3131
void DistributeDataLength(int src, int &len) const;
3232
std::vector<int> AssembleSendBuffer(int src, int len) const;
33-
void RelayMessage(int src, int dst, const std::vector<int> &route,
34-
const std::vector<int> &buffer, std::vector<int> &output) const;
33+
void RelayMessage(int src, int dst, const std::vector<int> &route, const std::vector<int> &buffer,
34+
std::vector<int> &output) const;
3535
void SaveFinalResult(int dst, const std::vector<int> &output, const std::vector<int> &route);
3636

3737
InType local_request_{};
@@ -44,4 +44,4 @@ class TorusMeshCommunicator : public BaseTask {
4444
int grid_cols_{1};
4545
};
4646

47-
} // namespace klimov_m_torus
47+
} // namespace klimov_m_torus

tasks/klimov_m_torus/mpi/src/ops_mpi.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ std::pair<int, int> TorusMeshCommunicator::CalculateGridSize(int totalProcesses)
2323
while (rows > 1 && (totalProcesses % rows != 0)) {
2424
--rows;
2525
}
26-
if (rows <= 0) rows = 1;
26+
if (rows <= 0) {
27+
rows = 1;
28+
}
2729
int cols = totalProcesses / rows;
28-
if (cols <= 0) cols = 1;
30+
if (cols <= 0) {
31+
cols = 1;
32+
}
2933
return {rows, cols};
3034
}
3135

@@ -83,16 +87,17 @@ std::vector<int> TorusMeshCommunicator::BuildMessageRoute(int rows, int cols, in
8387
bool TorusMeshCommunicator::ValidationImpl() {
8488
int initialized = 0;
8589
MPI_Initialized(&initialized);
86-
if (initialized == 0) return false;
90+
if (initialized == 0) {
91+
return false;
92+
}
8793

8894
MPI_Comm_rank(MPI_COMM_WORLD, &current_rank_);
8995
MPI_Comm_size(MPI_COMM_WORLD, &total_ranks_);
9096

9197
int valid = 0;
9298
if (current_rank_ == 0) {
9399
const auto &req = GetInput();
94-
if (req.sender >= 0 && req.receiver >= 0 &&
95-
req.sender < total_ranks_ && req.receiver < total_ranks_) {
100+
if (req.sender >= 0 && req.receiver >= 0 && req.sender < total_ranks_ && req.receiver < total_ranks_) {
96101
valid = 1;
97102
}
98103
}
@@ -156,8 +161,7 @@ std::vector<int> TorusMeshCommunicator::AssembleSendBuffer(int src, int len) con
156161
}
157162

158163
void TorusMeshCommunicator::RelayMessage(int src, int dst, const std::vector<int> &route,
159-
const std::vector<int> &buffer,
160-
std::vector<int> &output) const {
164+
const std::vector<int> &buffer, std::vector<int> &output) const {
161165
const int route_len = static_cast<int>(route.size());
162166
auto it = std::find(route.begin(), route.end(), current_rank_);
163167
bool on_route = (it != route.end());
@@ -196,8 +200,7 @@ void TorusMeshCommunicator::RelayMessage(int src, int dst, const std::vector<int
196200
}
197201
}
198202

199-
void TorusMeshCommunicator::SaveFinalResult(int dst, const std::vector<int> &output,
200-
const std::vector<int> &route) {
203+
void TorusMeshCommunicator::SaveFinalResult(int dst, const std::vector<int> &output, const std::vector<int> &route) {
201204
if (current_rank_ == dst) {
202205
local_response_.received_data = output;
203206
local_response_.route = route;
@@ -211,4 +214,4 @@ bool TorusMeshCommunicator::PostProcessingImpl() {
211214
return true;
212215
}
213216

214-
} // namespace klimov_m_torus
217+
} // namespace klimov_m_torus

tasks/klimov_m_torus/seq/include/ops_seq.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ class TorusReferenceImpl : public BaseTask {
2222
OutType local_response_{};
2323
};
2424

25-
} // namespace klimov_m_torus
25+
} // namespace klimov_m_torus

tasks/klimov_m_torus/seq/src/ops_seq.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ bool TorusReferenceImpl::PostProcessingImpl() {
4040
return true;
4141
}
4242

43-
} // namespace klimov_m_torus
43+
} // namespace klimov_m_torus

tasks/klimov_m_torus/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"tasks_type": "processes",
32
"tasks": {
43
"mpi": "enabled",
54
"seq": "enabled"
6-
}
5+
},
6+
"tasks_type": "processes"
77
}

tasks/klimov_m_torus/tests/functional/main.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,37 @@ class TorusFunctionalTest : public ppc::util::BaseRunFuncTests<InType, OutType,
6060

6161
private:
6262
[[nodiscard]] bool CheckSequential(const OutType &out) const {
63-
if (out.received_data != expected_payload_) return false;
64-
if (out.route.empty()) return false;
65-
if (out.route.front() != source_) return false;
66-
if (out.route.back() != dest_) return false;
63+
if (out.received_data != expected_payload_) {
64+
return false;
65+
}
66+
if (out.route.empty()) {
67+
return false;
68+
}
69+
if (out.route.front() != source_) {
70+
return false;
71+
}
72+
if (out.route.back() != dest_) {
73+
return false;
74+
}
6775
return true;
6876
}
6977

7078
[[nodiscard]] bool CheckParallel(const OutType &out) const {
7179
if (rank_ != dest_) {
7280
return out.received_data.empty() && out.route.empty();
7381
}
74-
if (out.received_data != expected_payload_) return false;
75-
if (out.route.empty()) return false;
76-
if (out.route.front() != source_) return false;
77-
if (out.route.back() != dest_) return false;
82+
if (out.received_data != expected_payload_) {
83+
return false;
84+
}
85+
if (out.route.empty()) {
86+
return false;
87+
}
88+
if (out.route.front() != source_) {
89+
return false;
90+
}
91+
if (out.route.back() != dest_) {
92+
return false;
93+
}
7894
return true;
7995
}
8096

@@ -92,9 +108,9 @@ const std::array<TestParam, 5> kTestParams = {
92108
std::make_tuple(1), std::make_tuple(4), std::make_tuple(8), std::make_tuple(16), std::make_tuple(32),
93109
};
94110

95-
const auto kTasksList =
96-
std::tuple_cat(ppc::util::AddFuncTask<TorusMeshCommunicator, InType>(kTestParams, "tasks/klimov_m_torus/settings.json"),
97-
ppc::util::AddFuncTask<TorusReferenceImpl, InType>(kTestParams, "tasks/klimov_m_torus/settings.json"));
111+
const auto kTasksList = std::tuple_cat(
112+
ppc::util::AddFuncTask<TorusMeshCommunicator, InType>(kTestParams, "tasks/klimov_m_torus/settings.json"),
113+
ppc::util::AddFuncTask<TorusReferenceImpl, InType>(kTestParams, "tasks/klimov_m_torus/settings.json"));
98114

99115
const auto kValues = ppc::util::ExpandToValues(kTasksList);
100116
const auto kNamePrinter = TorusFunctionalTest::PrintFuncTestName<TorusFunctionalTest>;
@@ -106,4 +122,4 @@ TEST_P(TorusFunctionalTest, TorusDataTransfer) {
106122
INSTANTIATE_TEST_SUITE_P(TorusFunctionalTests, TorusFunctionalTest, kValues, kNamePrinter);
107123

108124
} // namespace
109-
} // namespace klimov_m_torus
125+
} // namespace klimov_m_torus

tasks/klimov_m_torus/tests/performance/main.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ class TorusPerformanceTest : public ppc::util::BaseRunPerfTests<InType, OutType>
3333
}
3434

3535
void PrepareTestData() {
36-
if (data_ready_) return;
36+
if (data_ready_) {
37+
return;
38+
}
3739

38-
const int data_size = 10000000;
40+
const int data_size = 10000000;
3941

4042
test_data_.sender = 0;
4143
if (is_seq_mode_) {
@@ -64,15 +66,23 @@ class TorusPerformanceTest : public ppc::util::BaseRunPerfTests<InType, OutType>
6466
if (rank_ != test_data_.receiver) {
6567
return out.received_data.empty() && out.route.empty();
6668
}
67-
if (out.received_data.size() != test_data_.data.size()) return false;
68-
if (out.received_data.empty()) return true;
69+
if (out.received_data.size() != test_data_.data.size()) {
70+
return false;
71+
}
72+
if (out.received_data.empty()) {
73+
return true;
74+
}
6975
return (out.received_data.front() == test_data_.data.front() &&
7076
out.received_data.back() == test_data_.data.back());
7177
}
7278

7379
if (rank_ == 0) {
74-
if (out.received_data.size() != test_data_.data.size()) return false;
75-
if (out.received_data.empty()) return true;
80+
if (out.received_data.size() != test_data_.data.size()) {
81+
return false;
82+
}
83+
if (out.received_data.empty()) {
84+
return true;
85+
}
7686
return (out.received_data.front() == test_data_.data.front() &&
7787
out.received_data.back() == test_data_.data.back());
7888
}
@@ -82,8 +92,8 @@ class TorusPerformanceTest : public ppc::util::BaseRunPerfTests<InType, OutType>
8292

8393
namespace {
8494

85-
const auto kPerfTasksTuples =
86-
ppc::util::MakeAllPerfTasks<InType, TorusMeshCommunicator, TorusReferenceImpl>("tasks/klimov_m_torus/settings.json");
95+
const auto kPerfTasksTuples = ppc::util::MakeAllPerfTasks<InType, TorusMeshCommunicator, TorusReferenceImpl>(
96+
"tasks/klimov_m_torus/settings.json");
8797

8898
const auto kPerfValues = ppc::util::TupleToGTestValues(kPerfTasksTuples);
8999
const auto kPerfNamePrinter = TorusPerformanceTest::CustomPerfTestName;
@@ -95,4 +105,4 @@ TEST_P(TorusPerformanceTest, TorusPerformance) {
95105
INSTANTIATE_TEST_SUITE_P(TorusPerformanceTests, TorusPerformanceTest, kPerfValues, kPerfNamePrinter);
96106

97107
} // namespace
98-
} // namespace klimov_m_torus
108+
} // namespace klimov_m_torus

0 commit comments

Comments
 (0)