GCC Code Coverage Report


Directory: ./
File: tasks/kurpiakov_a_vert_tape_mat_vec_mul/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 46 46 100.0%
Functions: 5 5 100.0%
Branches: 27 36 75.0%

Line Branch Exec Source
1 #include "kurpiakov_a_vert_tape_mat_vec_mul/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstddef>
6 #include <vector>
7
8 #include "kurpiakov_a_vert_tape_mat_vec_mul/common/include/common.hpp"
9
10 namespace kurpiakov_a_vert_tape_mat_vec_mul {
11
12
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 KurpiakovAVretTapeMulMPI::KurpiakovAVretTapeMulMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 GetOutput() = {};
16
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Comm_rank(MPI_COMM_WORLD, &rank_);
17
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MPI_Comm_size(MPI_COMM_WORLD, &world_size_);
18 20 }
19
20 20 bool KurpiakovAVretTapeMulMPI::ValidationImpl() {
21
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank_ != 0) {
22 return true;
23 }
24
25 const auto &input = GetInput();
26 const auto &size = std::get<0>(input);
27 const auto &matrix = std::get<1>(input);
28 const auto &vector = std::get<2>(input);
29
30
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (size < 0) {
31 return false;
32 }
33
34
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if (size == 0) {
35
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 return matrix.empty() && vector.empty();
36 }
37
38
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 auto expected_matrix_size = static_cast<size_t>(size) * static_cast<size_t>(size);
39
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (matrix.size() != expected_matrix_size) {
40 return false;
41 }
42
43
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (vector.size() != static_cast<size_t>(size)) {
44 return false;
45 }
46
47 return true;
48 }
49
50 20 bool KurpiakovAVretTapeMulMPI::PreProcessingImpl() {
51
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (rank_ == 0) {
52 const auto &input = GetInput();
53 const auto &size = std::get<0>(input);
54 const auto &matrix = std::get<1>(input);
55 const auto &vector = std::get<2>(input);
56 10 matrix_size_ = size;
57 10 matrix_data_ = matrix;
58 10 vector_data_ = vector;
59 }
60 20 return true;
61 }
62
63 20 bool KurpiakovAVretTapeMulMPI::RunImpl() {
64 20 MPI_Bcast(&matrix_size_, 1, MPI_INT, 0, MPI_COMM_WORLD);
65
66
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 if (matrix_size_ == 0) {
67 GetOutput() = {};
68 2 return true;
69 }
70
71 const int n = matrix_size_;
72
73 18 vector_data_.resize(static_cast<size_t>(n));
74 18 MPI_Bcast(vector_data_.data(), n, MPI_INT, 0, MPI_COMM_WORLD);
75
76 18 matrix_data_.resize(static_cast<size_t>(n) * static_cast<size_t>(n));
77 18 MPI_Bcast(matrix_data_.data(), n * n, MPI_INT, 0, MPI_COMM_WORLD);
78
79 18 const int base_cols = n / world_size_;
80 18 const int extra_cols = n % world_size_;
81
82 int col_start = 0;
83
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for (int i = 0; i < rank_; ++i) {
84
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
15 col_start += base_cols + (i < extra_cols ? 1 : 0);
85 }
86
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 local_cols_ = base_cols + (rank_ < extra_cols ? 1 : 0);
87
88 18 local_result_.assign(static_cast<size_t>(n), 0);
89
90
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 18 times.
37 for (int local_col = 0; local_col < local_cols_; ++local_col) {
91 19 int global_col = col_start + local_col;
92 19 int vec_val = vector_data_[global_col];
93
94
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 19 times.
62 for (int row = 0; row < n; ++row) {
95 43 local_result_[row] +=
96 43 matrix_data_[(static_cast<size_t>(row) * static_cast<size_t>(n)) + static_cast<size_t>(global_col)] * vec_val;
97 }
98 }
99
100 18 result_.resize(static_cast<size_t>(n));
101 18 MPI_Reduce(local_result_.data(), result_.data(), n, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
102
103 18 MPI_Bcast(result_.data(), n, MPI_INT, 0, MPI_COMM_WORLD);
104
105 18 GetOutput() = result_;
106 18 MPI_Barrier(MPI_COMM_WORLD);
107 18 return true;
108 }
109
110 20 bool KurpiakovAVretTapeMulMPI::PostProcessingImpl() {
111 20 return true;
112 }
113
114 } // namespace kurpiakov_a_vert_tape_mat_vec_mul
115