GCC Code Coverage Report


Directory: ./
File: tasks/pylaeva_s_max_elem_matrix/mpi/src/ops_mpi.cpp
Date: 2025-12-13 04:24:21
Exec Total Coverage
Lines: 43 43 100.0%
Functions: 5 5 100.0%
Branches: 27 46 58.7%

Line Branch Exec Source
1 #include "pylaeva_s_max_elem_matrix/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <algorithm> // для std::max
6 #include <cstddef> // для size_t
7 #include <limits> // для std::numeric_limits
8 #include <vector>
9
10 #include "pylaeva_s_max_elem_matrix/common/include/common.hpp"
11
12 namespace pylaeva_s_max_elem_matrix {
13
14
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 PylaevaSMaxElemMatrixMPI::PylaevaSMaxElemMatrixMPI(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17 20 GetOutput() = std::numeric_limits<int>::min();
18 20 }
19
20 20 bool PylaevaSMaxElemMatrixMPI::ValidationImpl() {
21 20 const auto rows = static_cast<size_t>(std::get<0>(GetInput()));
22 20 const auto columns = static_cast<size_t>(std::get<1>(GetInput()));
23
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 size_t matrix_size = rows * columns;
24
25
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 return (matrix_size == std::get<2>(GetInput()).size()) && (rows > 0) && (columns > 0);
26 }
27
28 20 bool PylaevaSMaxElemMatrixMPI::PreProcessingImpl() {
29 20 return true;
30 }
31
32 20 bool PylaevaSMaxElemMatrixMPI::RunImpl() {
33 20 int rank = 0;
34 20 int size = 0;
35 20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
36 20 MPI_Comm_size(MPI_COMM_WORLD, &size);
37
38 20 size_t matrix_size = 0;
39 20 std::vector<int> matrix_data;
40
41
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank == 0) {
42 10 const auto matrix_rows = static_cast<size_t>(std::get<0>(GetInput()));
43 10 const auto matrix_columns = static_cast<size_t>(std::get<1>(GetInput()));
44
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 matrix_size = matrix_rows * matrix_columns;
45
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 matrix_data = std::get<2>(GetInput());
46 }
47
48
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Bcast(&matrix_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
49
50
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> sendcounts(size, 0);
51
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<int> displs(size, 0);
52
53 20 int local_size = static_cast<int>(matrix_size / size);
54 20 int remainder = static_cast<int>(matrix_size % size);
55
56 int offset = 0;
57
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 20 times.
60 for (int i = 0; i < size; i++) {
58
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 6 times.
74 sendcounts[i] = local_size + (i < remainder ? 1 : 0);
59 40 displs[i] = offset;
60 40 offset += sendcounts[i];
61 }
62
63
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 int local_elements = sendcounts[rank];
64
3/6
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
20 std::vector<int> local_data(local_elements);
65
66
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
30 MPI_Scatterv(rank == 0 ? matrix_data.data() : nullptr, sendcounts.data(), displs.data(), MPI_INT, local_data.data(),
67 local_elements, MPI_INT, 0, MPI_COMM_WORLD);
68
69 20 int local_max = std::numeric_limits<int>::min();
70
2/2
✓ Branch 0 taken 3067655 times.
✓ Branch 1 taken 20 times.
3067675 for (int i = 0; i < local_elements; i++) {
71
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 3067614 times.
3067696 local_max = std::max(local_max, local_data[i]);
72 }
73
74 20 int global_max = std::numeric_limits<int>::min();
75
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);
76
77
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 GetOutput() = global_max;
78
79 20 return true;
80 }
81
82 20 bool PylaevaSMaxElemMatrixMPI::PostProcessingImpl() {
83 20 return true;
84 }
85
86 } // namespace pylaeva_s_max_elem_matrix
87