GCC Code Coverage Report


Directory: ./
File: tasks/boltenkov_s_max_in_matrix/mpi/src/ops_mpi.cpp
Date: 2026-01-09 01:27:18
Exec Total Coverage
Lines: 57 57 100.0%
Functions: 5 5 100.0%
Branches: 38 60 63.3%

Line Branch Exec Source
1 #include "boltenkov_s_max_in_matrix/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cmath>
6 #include <limits>
7 #include <vector>
8
9 #include "boltenkov_s_max_in_matrix/common/include/common.hpp"
10
11 namespace boltenkov_s_max_in_matrix {
12
13
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 BoltenkovSMaxInMatrixkMPI::BoltenkovSMaxInMatrixkMPI(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 6 int rank = 0;
16
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
17
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (rank == 0) {
18 GetInput() = in;
19 } else {
20 3 GetInput() = InType{};
21 }
22 6 GetOutput() = -std::numeric_limits<double>::max();
23 6 }
24
25 6 bool BoltenkovSMaxInMatrixkMPI::ValidationImpl() {
26 6 int rank = 0;
27 6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
28
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (rank == 0) {
29
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 return std::get<0>(GetInput()) > 0 && !std::get<1>(GetInput()).empty() &&
30
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 std::get<1>(GetInput()).size() % std::get<0>(GetInput()) == 0;
31 }
32 return true;
33 }
34
35 6 bool BoltenkovSMaxInMatrixkMPI::PreProcessingImpl() {
36 6 int rank = 0;
37 6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
38
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (rank == 0) {
39
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 return std::get<0>(GetInput()) > 0 && !std::get<1>(GetInput()).empty() &&
40
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 std::get<1>(GetInput()).size() % std::get<0>(GetInput()) == 0;
41 }
42 return true;
43 }
44
45 6 bool BoltenkovSMaxInMatrixkMPI::RunImpl() {
46 6 int size = 0;
47 6 int rank = 0;
48 6 MPI_Comm_size(MPI_COMM_WORLD, &size);
49 6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
50
51 6 std::vector<int> sendcounts(size, 0);
52
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<int> displs(size, 0);
53 6 std::vector<double> data;
54
2/6
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6 std::vector<double> all_maxs(size, std::numeric_limits<double>::lowest());
55
56 OutType &mx = GetOutput();
57 std::vector<double> &v = std::get<1>(GetInput());
58
59 MPI_Datatype datatype = MPI_DOUBLE;
60
61 6 int len = static_cast<int>(v.size());
62
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
63
64 int cur_disp = 0;
65 6 int cnt_item = len / size;
66 6 int r = len % size;
67
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for (int i = 0; i < size; ++i) {
68
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 int cur_cnt = cnt_item + (i < r ? 1 : 0);
69 12 sendcounts[i] = cur_cnt;
70 12 displs[i] = cur_disp;
71 12 cur_disp += sendcounts[i];
72 }
73
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 data.resize(sendcounts[rank]);
74
75
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
9 MPI_Scatterv((rank == 0) ? v.data() : nullptr, sendcounts.data(), displs.data(), datatype, data.data(),
76
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 sendcounts[rank], datatype, 0, MPI_COMM_WORLD);
77
78 bool flag = false;
79 6 OutType tmp_mx = std::numeric_limits<double>::lowest();
80
2/2
✓ Branch 0 taken 9438208 times.
✓ Branch 1 taken 6 times.
9438214 for (int i = 0; i < sendcounts[rank]; ++i) {
81 9438208 flag = data[i] > tmp_mx;
82 9438208 tmp_mx = (static_cast<double>(flag) * data[i]) + (static_cast<double>(!flag) * tmp_mx);
83 }
84
85
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for (int i = 0; i < size; ++i) {
86 12 sendcounts[i] = 1;
87 12 displs[i] = i;
88 }
89
90
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Gatherv(&tmp_mx, 1, datatype, all_maxs.data(), sendcounts.data(), displs.data(), datatype, 0, MPI_COMM_WORLD);
91
92
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (rank == 0) {
93
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for (int i = 0; i < size; ++i) {
94 6 flag = all_maxs[i] > mx;
95 6 mx = (static_cast<double>(flag) * all_maxs[i]) + (static_cast<double>(!flag) * mx);
96 }
97 }
98
99
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Bcast(&mx, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
100
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Barrier(MPI_COMM_WORLD);
101 6 return true;
102 }
103
104 6 bool BoltenkovSMaxInMatrixkMPI::PostProcessingImpl() {
105 6 return true;
106 }
107
108 } // namespace boltenkov_s_max_in_matrix
109