GCC Code Coverage Report


Directory: ./
File: tasks/levonychev_i_mult_matrix_vec/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 62 62 100.0%
Functions: 5 5 100.0%
Branches: 36 68 52.9%

Line Branch Exec Source
1 #include "levonychev_i_mult_matrix_vec/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstddef>
6 #include <vector>
7
8 #include "levonychev_i_mult_matrix_vec/common/include/common.hpp"
9
10 namespace levonychev_i_mult_matrix_vec {
11
12
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 LevonychevIMultMatrixVecMPI::LevonychevIMultMatrixVecMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
15 16 int rank = 0;
16
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
17
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (rank == 0) {
18 GetInput() = in;
19 }
20 GetOutput() = {};
21 16 }
22
23 16 bool LevonychevIMultMatrixVecMPI::ValidationImpl() {
24 16 int rank = 0;
25 16 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (rank == 0) {
27 const size_t matrix_size = std::get<0>(GetInput()).size();
28 8 const int rows = std::get<1>(GetInput());
29 8 const int cols = std::get<2>(GetInput());
30 8 bool is_correct_matrix_size = (matrix_size == static_cast<size_t>(rows) * static_cast<size_t>(cols));
31 bool is_correct_vector_size = (static_cast<size_t>(cols) == std::get<3>(GetInput()).size());
32
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 return matrix_size != 0 && rows != 0 && cols != 0 && is_correct_matrix_size && is_correct_vector_size;
33 }
34 return true;
35 }
36
37 16 bool LevonychevIMultMatrixVecMPI::PreProcessingImpl() {
38 16 int rank = 0;
39 16 int rows = 0;
40 16 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
41
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (rank == 0) {
42 8 rows = std::get<1>(GetInput());
43 }
44 16 MPI_Bcast(&rows, 1, MPI_INT, 0, MPI_COMM_WORLD);
45 16 GetOutput().resize(rows);
46 16 return true;
47 }
48
49 16 bool LevonychevIMultMatrixVecMPI::RunImpl() {
50 16 int proc_num = 0;
51 16 int proc_rank = 0;
52 16 MPI_Comm_size(MPI_COMM_WORLD, &proc_num);
53 16 MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank);
54
55 OutType &global_b = GetOutput();
56
57 16 int rows = 0;
58 16 int cols = 0;
59 16 std::vector<double> x;
60
61
1/4
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
16 std::vector<int> recvcounts_scatterv(proc_num);
62
1/4
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
16 std::vector<int> displs_scatterv(proc_num);
63
1/4
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
16 std::vector<int> recvcounts_gatherv(proc_num);
64
1/4
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
16 std::vector<int> displs_gatherv(proc_num);
65
66 16 rows = std::get<1>(GetInput());
67
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 cols = std::get<2>(GetInput());
68
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 x = std::get<3>(GetInput());
69
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 MPI_Bcast(&rows, 1, MPI_INT, 0, MPI_COMM_WORLD);
70
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 MPI_Bcast(&cols, 1, MPI_INT, 0, MPI_COMM_WORLD);
71
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 x.resize(cols);
72
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 MPI_Bcast(x.data(), cols, MPI_DOUBLE, 0, MPI_COMM_WORLD);
73
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 16 times.
48 for (int i = 0; i < proc_num; ++i) {
74
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 int local_count_of_rows = i == (proc_num - 1) ? ((rows / proc_num) + (rows % proc_num)) : (rows / proc_num);
75 32 recvcounts_scatterv[i] = local_count_of_rows * cols;
76 32 recvcounts_gatherv[i] = local_count_of_rows;
77 32 int start = i * (rows / proc_num);
78 32 displs_scatterv[i] = start * cols;
79 32 displs_gatherv[i] = start;
80 }
81
82
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 int local_count_of_rows = (proc_rank == (proc_num - 1)) ? ((rows / proc_num) + (rows % proc_num)) : (rows / proc_num);
83 16 int recvcount = local_count_of_rows * cols;
84
2/6
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
16 OutType local_matrix(recvcount);
85
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 MPI_Scatterv(std::get<0>(GetInput()).data(), recvcounts_scatterv.data(), displs_scatterv.data(), MPI_DOUBLE,
86 local_matrix.data(), recvcount, MPI_DOUBLE, 0, MPI_COMM_WORLD);
87
1/4
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
16 OutType local_b(local_count_of_rows);
88
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 16 times.
37 for (int i = 0; i < local_count_of_rows; ++i) {
89 21 const int start = cols * i;
90 double scalar_product = 0;
91
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 21 times.
103 for (int j = 0; j < cols; ++j) {
92 82 scalar_product += local_matrix[start + j] * x[j];
93 }
94 21 local_b[i] = scalar_product;
95 }
96
97
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 MPI_Allgatherv(local_b.data(), local_count_of_rows, MPI_DOUBLE, global_b.data(), recvcounts_gatherv.data(),
98 displs_gatherv.data(), MPI_DOUBLE, MPI_COMM_WORLD);
99 16 return true;
100 }
101
102 16 bool LevonychevIMultMatrixVecMPI::PostProcessingImpl() {
103 16 return true;
104 }
105
106 } // namespace levonychev_i_mult_matrix_vec
107