GCC Code Coverage Report


Directory: ./
File: tasks/tochilin_e_vertical_ribbon_scheme/mpi/src/ops_mpi.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 55 56 98.2%
Functions: 5 5 100.0%
Branches: 30 58 51.7%

Line Branch Exec Source
1 #include "tochilin_e_vertical_ribbon_scheme/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstddef>
6 #include <utility>
7 #include <vector>
8
9 #include "tochilin_e_vertical_ribbon_scheme/common/include/common.hpp"
10
11 namespace tochilin_e_vertical_ribbon_scheme {
12
13
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 TochilinEVerticalRibbonSchemeMPI::TochilinEVerticalRibbonSchemeMPI(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 GetInput() = in;
16 GetOutput() = {};
17 6 }
18
19 6 bool TochilinEVerticalRibbonSchemeMPI::ValidationImpl() {
20 6 int rank = 0;
21 6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (rank == 0) {
23 const auto &input = GetInput();
24
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (input.rows <= 0 || input.cols <= 0) {
25 return false;
26 }
27
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (std::cmp_not_equal(input.matrix.size(), static_cast<std::size_t>(input.rows) * input.cols)) {
28 return false;
29 }
30 if (std::cmp_not_equal(input.vector.size(), input.cols)) {
31 return false;
32 }
33 }
34 return true;
35 }
36
37 6 bool TochilinEVerticalRibbonSchemeMPI::PreProcessingImpl() {
38 6 int rank = 0;
39 6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
40
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (rank == 0) {
41 const auto &input = GetInput();
42 3 rows_ = input.rows;
43 3 cols_ = input.cols;
44 3 matrix_ = input.matrix;
45 3 vector_ = input.vector;
46 }
47 6 return true;
48 }
49
50 6 bool TochilinEVerticalRibbonSchemeMPI::RunImpl() {
51 6 int rank = 0;
52 6 int size = 0;
53 6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
54 6 MPI_Comm_size(MPI_COMM_WORLD, &size);
55
56 6 MPI_Bcast(&rows_, 1, MPI_INT, 0, MPI_COMM_WORLD);
57 6 MPI_Bcast(&cols_, 1, MPI_INT, 0, MPI_COMM_WORLD);
58
59 6 int base_cols = cols_ / size;
60 6 int extra_cols = cols_ % size;
61
62 6 std::vector<int> send_counts(size);
63
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<int> displs(size);
64
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<int> vec_counts(size);
65
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<int> vec_displs(size);
66
67 int offset = 0;
68 int vec_offset = 0;
69
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for (int i = 0; i < size; i++) {
70
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 int local_cols = base_cols + (i < extra_cols ? 1 : 0);
71 12 send_counts[i] = local_cols * rows_;
72 12 displs[i] = offset;
73 12 vec_counts[i] = local_cols;
74 12 vec_displs[i] = vec_offset;
75 12 offset += send_counts[i];
76 12 vec_offset += local_cols;
77 }
78
79
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 int local_cols = base_cols + (rank < extra_cols ? 1 : 0);
80
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<double> local_matrix(static_cast<std::size_t>(local_cols) * rows_);
81
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<double> local_vector(local_cols);
82
83
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Scatterv(matrix_.data(), send_counts.data(), displs.data(), MPI_DOUBLE, local_matrix.data(), send_counts[rank],
84 MPI_DOUBLE, 0, MPI_COMM_WORLD);
85
86
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Scatterv(vector_.data(), vec_counts.data(), vec_displs.data(), MPI_DOUBLE, local_vector.data(), vec_counts[rank],
87 MPI_DOUBLE, 0, MPI_COMM_WORLD);
88
89
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<double> local_result(rows_, 0.0);
90
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6 times.
21 for (int j = 0; j < local_cols; j++) {
91
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 15 times.
98 for (int i = 0; i < rows_; i++) {
92 83 local_result[i] += local_matrix[static_cast<std::size_t>(j * rows_) + i] * local_vector[j];
93 }
94 }
95
96
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 result_.resize(rows_);
97
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Reduce(local_result.data(), result_.data(), rows_, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
98
99
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Bcast(result_.data(), rows_, MPI_DOUBLE, 0, MPI_COMM_WORLD);
100
101 6 return true;
102 }
103
104 6 bool TochilinEVerticalRibbonSchemeMPI::PostProcessingImpl() {
105 6 GetOutput() = result_;
106 6 return true;
107 }
108
109 } // namespace tochilin_e_vertical_ribbon_scheme
110