Skip to content

Commit fa33d6f

Browse files
committed
Fix newly appeared clang-tidy readability-function-cognitive-complexity errors
1 parent 3fb6776 commit fa33d6f

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

tasks/mpi/example/src/ops_mpi.cpp

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,37 @@ bool nesterov_a_test_task_mpi::TestTaskMPI::ValidationImpl() {
2525
}
2626

2727
bool nesterov_a_test_task_mpi::TestTaskMPI::RunImpl() {
28-
int rank = -1;
29-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30-
31-
auto multiply = [this](bool row_major) {
32-
for (int i = 0; i < rc_size_; ++i) {
33-
for (int j = 0; j < rc_size_; ++j) {
34-
int sum = 0;
35-
for (int k = 0; k < rc_size_; ++k) {
36-
int a = input_[(row_major ? i : k) * rc_size_ + (row_major ? k : i)];
37-
int b = input_[(row_major ? k : j) * rc_size_ + (row_major ? j : k)];
38-
sum += a * b;
39-
}
40-
output_[(i * rc_size_) + j] += sum;
28+
MultiplyMatrixBasedOnRank();
29+
return true;
30+
}
31+
32+
void nesterov_a_test_task_mpi::TestTaskMPI::MultiplyMatrixBasedOnRank() {
33+
if (world_.rank() == 0) {
34+
MultiplyRowMajor();
35+
} else {
36+
MultiplyColumnMajor();
37+
}
38+
world_.barrier();
39+
}
40+
41+
void nesterov_a_test_task_mpi::TestTaskMPI::MultiplyRowMajor() {
42+
for (int i = 0; i < rc_size_; ++i) {
43+
for (int j = 0; j < rc_size_; ++j) {
44+
for (int k = 0; k < rc_size_; ++k) {
45+
output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j];
4146
}
4247
}
43-
};
48+
}
49+
}
4450

45-
multiply(rank == 0);
46-
MPI_Barrier(MPI_COMM_WORLD);
47-
return true;
51+
void nesterov_a_test_task_mpi::TestTaskMPI::MultiplyColumnMajor() {
52+
for (int j = 0; j < rc_size_; ++j) {
53+
for (int k = 0; k < rc_size_; ++k) {
54+
for (int i = 0; i < rc_size_; ++i) {
55+
output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j];
56+
}
57+
}
58+
}
4859
}
4960

5061
bool nesterov_a_test_task_mpi::TestTaskMPI::PostProcessingImpl() {

0 commit comments

Comments
 (0)