GCC Code Coverage Report


Directory: ./
File: tasks/buzulukskiy_d_max_value_matrix_elements/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 40 42 95.2%
Functions: 5 5 100.0%
Branches: 26 42 61.9%

Line Branch Exec Source
1 #include "buzulukskiy_d_max_value_matrix_elements/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm>
6 #include <cstddef>
7 #include <limits>
8 #include <vector>
9
10 #include "buzulukskiy_d_max_value_matrix_elements/common/include/common.hpp"
11
12 namespace buzulukskiy_d_max_value_matrix_elements {
13
14
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 BuzulukskiyDMaxValueMatrixElementsMPI::BuzulukskiyDMaxValueMatrixElementsMPI(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17 20 GetOutput() = 0;
18 20 }
19
20 20 bool BuzulukskiyDMaxValueMatrixElementsMPI::ValidationImpl() {
21 const Matrix &inputdata = GetInput();
22 20 const int rows = inputdata.rows;
23
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 const int columns = inputdata.columns;
24 const std::vector<int> &matrix = inputdata.data;
25
26
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
20 return !matrix.empty() && rows > 0 && columns > 0 &&
27
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 matrix.size() == static_cast<size_t>(rows) * static_cast<size_t>(columns);
28 }
29
30 20 bool BuzulukskiyDMaxValueMatrixElementsMPI::PreProcessingImpl() {
31 20 return true;
32 }
33
34 20 bool BuzulukskiyDMaxValueMatrixElementsMPI::RunImpl() {
35 const Matrix &inputdata = GetInput();
36 20 const int rows = inputdata.rows;
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 const int columns = inputdata.columns;
38 const std::vector<int> &matrix = inputdata.data;
39
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (matrix.empty()) {
41 GetOutput() = 0;
42 return true;
43 }
44
45 20 int rank = 0;
46 20 int size = 1;
47 20 MPI_Comm_size(MPI_COMM_WORLD, &size);
48 20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
49
50 20 const int rows_at_one_process = rows / size;
51 20 const int remaining_rows = rows % size;
52 20 std::vector<int> counts_per_process(size, rows_at_one_process * columns);
53
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> displacements(size, 0);
54
55
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12 times.
20 if (remaining_rows != 0) {
56
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for (int process_index = 0; process_index < remaining_rows; ++process_index) {
57 8 counts_per_process[process_index] += columns;
58 }
59 }
60
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 for (int process_index = 1; process_index < size; ++process_index) {
61 20 displacements[process_index] = displacements[process_index - 1] + counts_per_process[process_index - 1];
62 }
63
64
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> recvbuf(counts_per_process[rank]);
65
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Scatterv(matrix.data(), counts_per_process.data(), displacements.data(), MPI_INT, recvbuf.data(),
66
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 counts_per_process[rank], MPI_INT, 0, MPI_COMM_WORLD);
67
68
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2 times.
20 int local_max = std::numeric_limits<int>::min();
69
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2 times.
20 if (!recvbuf.empty()) {
70 18 local_max = recvbuf[0];
71
2/2
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 18 times.
71 for (size_t index = 1; index < recvbuf.size(); ++index) {
72 53 local_max = std::max(local_max, recvbuf[index]);
73 }
74 }
75
76 20 int global_max = 0;
77
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Allreduce(&local_max, &global_max, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
78
79
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2 times.
20 GetOutput() = global_max;
80 return true;
81 }
82
83 20 bool BuzulukskiyDMaxValueMatrixElementsMPI::PostProcessingImpl() {
84 20 return true;
85 }
86
87 } // namespace buzulukskiy_d_max_value_matrix_elements
88