GCC Code Coverage Report


Directory: ./
File: tasks/ovchinnikov_m_max_values_in_matrix_rows/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 46 46 100.0%
Functions: 5 5 100.0%
Branches: 28 46 60.9%

Line Branch Exec Source
1 #include "ovchinnikov_m_max_values_in_matrix_rows/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 "ovchinnikov_m_max_values_in_matrix_rows/common/include/common.hpp"
11
12 namespace ovchinnikov_m_max_values_in_matrix_rows {
13
14
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 OvchinnikovMMaxValuesInMatrixRowsMPI::OvchinnikovMMaxValuesInMatrixRowsMPI(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17 static_cast<void>(GetOutput());
18 12 }
19
20 12 bool OvchinnikovMMaxValuesInMatrixRowsMPI::ValidationImpl() {
21 12 return true;
22 }
23
24 12 bool OvchinnikovMMaxValuesInMatrixRowsMPI::PreProcessingImpl() {
25 12 return true;
26 }
27
28 12 bool OvchinnikovMMaxValuesInMatrixRowsMPI::RunImpl() {
29 12 int tmp_rank = 0;
30 12 int tmp_proc_amount = 0;
31 12 MPI_Comm_rank(MPI_COMM_WORLD, &tmp_rank);
32 12 MPI_Comm_size(MPI_COMM_WORLD, &tmp_proc_amount);
33 12 auto rank = static_cast<size_t>(tmp_rank);
34 12 auto proc_amount = static_cast<size_t>(tmp_proc_amount);
35
36 12 const size_t lines = std::get<0>(GetInput());
37 12 const size_t cols = std::get<1>(GetInput());
38
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
12 if (lines == 0 || cols == 0) {
39 return true;
40 }
41 const auto &matrix = std::get<2>(GetInput());
42
43 10 std::vector<int> elem_count(proc_amount);
44
1/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
10 std::vector<int> elem_offset(proc_amount);
45
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (rank == 0) {
46 5 const size_t chunk_base = lines / proc_amount;
47 5 const size_t chunk_extra = lines % proc_amount;
48
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 5 times.
15 for (size_t process = 0; process < proc_amount; process++) {
49
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 const size_t line_begin = (process * chunk_base) + std::min(process, chunk_extra);
50 10 size_t line_end = line_begin + chunk_base;
51
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 if (process < chunk_extra) {
52 3 line_end++;
53 }
54
55 10 size_t elems = (line_end - line_begin) * cols;
56 10 size_t offset = line_begin * cols;
57 10 elem_count[process] = static_cast<int>(elems);
58 10 elem_offset[process] = static_cast<int>(offset);
59 }
60 }
61
62
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Bcast(elem_count.data(), static_cast<int>(proc_amount), MPI_INT, 0, MPI_COMM_WORLD);
63
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Bcast(elem_offset.data(), static_cast<int>(proc_amount), MPI_INT, 0, MPI_COMM_WORLD);
64
65
1/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
10 std::vector<int> local_data(elem_count[rank]);
66
67 const int *matrix_buffer = nullptr;
68
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (rank == 0) {
69 matrix_buffer = matrix.data();
70 }
71
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Scatterv(matrix_buffer, // only for rank 0
72 elem_count.data(), elem_offset.data(), MPI_INT, local_data.data(), elem_count[rank], MPI_INT, 0,
73 MPI_COMM_WORLD);
74
75
1/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
10 std::vector<int> local_max(cols, std::numeric_limits<int>::min());
76
77 10 size_t local_lines = local_data.size() / cols;
78
79
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 10 times.
23 for (size_t i = 0; i < local_lines; i++) {
80 13 const size_t local_base = i * cols;
81
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 13 times.
78 for (size_t j = 0; j < cols; j++) {
82
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 21 times.
109 local_max[j] = std::max(local_max[j], local_data[local_base + j]);
83 }
84 }
85
1/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
10 std::vector<int> global_max(cols);
86
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 MPI_Allreduce(local_max.data(), global_max.data(), static_cast<int>(cols), MPI_INT, MPI_MAX, MPI_COMM_WORLD);
87
88
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 GetOutput() = global_max;
89 return true;
90 }
91
92 12 bool OvchinnikovMMaxValuesInMatrixRowsMPI::PostProcessingImpl() {
93 12 return true;
94 }
95
96 } // namespace ovchinnikov_m_max_values_in_matrix_rows
97