GCC Code Coverage Report


Directory: ./
File: tasks/shakirova_e_elem_matrix_sum/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 44 44 100.0%
Functions: 5 5 100.0%
Branches: 22 34 64.7%

Line Branch Exec Source
1 #include "shakirova_e_elem_matrix_sum/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstddef>
6 #include <cstdint>
7 #include <utility>
8 #include <vector>
9
10 #include "shakirova_e_elem_matrix_sum/common/include/common.hpp"
11 #include "shakirova_e_elem_matrix_sum/common/include/matrix.hpp"
12
13 namespace shakirova_e_elem_matrix_sum {
14
15
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 ShakirovaEElemMatrixSumMPI::ShakirovaEElemMatrixSumMPI(const InType &in) {
16 SetTypeOfTask(GetStaticTypeOfTask());
17 GetInput() = in;
18 18 GetOutput() = 0;
19 18 }
20
21 18 bool ShakirovaEElemMatrixSumMPI::ValidationImpl() {
22 18 int rank = -1;
23
24 18 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
25
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (rank == 0) {
26 return GetInput().IsValid();
27 }
28
29 return true;
30 }
31
32 18 bool ShakirovaEElemMatrixSumMPI::PreProcessingImpl() {
33 18 GetOutput() = 0;
34 18 return true;
35 }
36
37 18 bool ShakirovaEElemMatrixSumMPI::RunImpl() {
38 18 int rank = 0;
39 18 int p_count = 0;
40
41 18 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
42 18 MPI_Comm_size(MPI_COMM_WORLD, &p_count);
43
44
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (p_count <= 0) {
45 return false;
46 }
47
48 18 size_t row_count = GetInput().rows;
49 18 size_t col_count = GetInput().cols;
50
51 18 MPI_Bcast(&row_count, 1, MPI_UINT64_T, 0, MPI_COMM_WORLD);
52 18 MPI_Bcast(&col_count, 1, MPI_UINT64_T, 0, MPI_COMM_WORLD);
53
54 18 size_t rows_per_process = row_count / p_count;
55 18 size_t remaining_rows = row_count % p_count;
56
57 size_t my_rows = rows_per_process;
58
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (std::cmp_less(rank, remaining_rows)) {
59 3 my_rows = my_rows + 1;
60 }
61
62 18 size_t elements_count = my_rows * col_count;
63 18 std::vector<int64_t> my_data(elements_count);
64
65
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (rank == 0) {
66
1/4
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
9 std::vector<int> send_counts(p_count);
67
1/4
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
9 std::vector<int> displacements(p_count, 0);
68
69
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for (int i = 0; i < p_count; i++) {
70 size_t proc_rows = rows_per_process;
71 if (std::cmp_less(i, remaining_rows)) {
72 3 proc_rows = proc_rows + 1;
73 }
74
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 send_counts[i] = static_cast<int>(proc_rows * col_count);
75
76
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (i > 0) {
77 9 displacements[i] = displacements[i - 1] + send_counts[i - 1];
78 }
79 }
80
81
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 MPI_Scatterv(GetInput().data.data(), send_counts.data(), displacements.data(), MPI_INT64_T, my_data.data(),
82 static_cast<int>(elements_count), MPI_INT64_T, 0, MPI_COMM_WORLD);
83 } else {
84
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 MPI_Scatterv(nullptr, nullptr, nullptr, MPI_INT64_T, my_data.data(), static_cast<int>(elements_count), MPI_INT64_T,
85 0, MPI_COMM_WORLD);
86 }
87
88 18 int64_t local_sum = 0;
89
2/2
✓ Branch 0 taken 2491 times.
✓ Branch 1 taken 18 times.
2509 for (const auto &value : my_data) {
90 2491 local_sum = local_sum + value;
91 }
92
93 18 int64_t total_sum = 0;
94
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 MPI_Allreduce(&local_sum, &total_sum, 1, MPI_INT64_T, MPI_SUM, MPI_COMM_WORLD);
95
96
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 times.
18 GetOutput() = total_sum;
97
98 return true;
99 }
100
101 18 bool ShakirovaEElemMatrixSumMPI::PostProcessingImpl() {
102 18 return true;
103 }
104
105 } // namespace shakirova_e_elem_matrix_sum
106