GCC Code Coverage Report


Directory: ./
File: tasks/alekseev_a_mult_matrix_crs/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 6 6 100.0%
Branches: 25 36 69.4%

Line Branch Exec Source
1 #include "alekseev_a_mult_matrix_crs/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <algorithm>
6 #include <cmath>
7 #include <cstddef>
8 #include <utility>
9 #include <vector>
10
11 #include "alekseev_a_mult_matrix_crs/common/include/common.hpp"
12
13 namespace alekseev_a_mult_matrix_crs {
14
15
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 AlekseevAMultMatrixCRSOMP::AlekseevAMultMatrixCRSOMP(const InType &in) {
16 SetTypeOfTask(GetStaticTypeOfTask());
17 GetInput() = in;
18 24 }
19
20 24 bool AlekseevAMultMatrixCRSOMP::ValidationImpl() {
21 const auto &a = std::get<0>(GetInput());
22 const auto &b = std::get<1>(GetInput());
23
3/6
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
24 return a.cols == b.rows && !a.row_ptr.empty() && !b.row_ptr.empty();
24 }
25
26 24 bool AlekseevAMultMatrixCRSOMP::PreProcessingImpl() {
27 24 GetOutput() = {};
28 24 return true;
29 }
30
31 48 void AlekseevAMultMatrixCRSOMP::ProcessRow(std::size_t i, const CRSMatrix &a, const CRSMatrix &b,
32 std::vector<double> &temp_v, std::vector<std::size_t> &temp_c,
33 std::vector<double> &accum, std::vector<int> &touched_flag,
34 std::vector<std::size_t> &touched_cols) {
35
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 48 times.
100 for (std::size_t pos_a = a.row_ptr[i]; pos_a < a.row_ptr[i + 1]; ++pos_a) {
36 52 std::size_t k = a.col_indices[pos_a];
37 52 double val_a = a.values[pos_a];
38
39
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 52 times.
132 for (std::size_t pos_b = b.row_ptr[k]; pos_b < b.row_ptr[k + 1]; ++pos_b) {
40
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 55 times.
80 std::size_t j = b.col_indices[pos_b];
41
42
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 55 times.
80 if (std::cmp_not_equal(touched_flag[j], i)) {
43
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 touched_flag[j] = static_cast<int>(i);
44 touched_cols.push_back(j);
45 60 accum[j] = 0.0;
46 }
47 80 accum[j] += val_a * b.values[pos_b];
48 }
49 }
50
51 std::ranges::sort(touched_cols);
52
53
3/4
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 48 times.
108 for (auto col : touched_cols) {
54
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if (std::abs(accum[col]) > 1e-15) {
55 temp_v.push_back(accum[col]);
56 temp_c.push_back(col);
57 }
58 }
59 touched_cols.clear();
60 48 }
61
62 24 bool AlekseevAMultMatrixCRSOMP::RunImpl() {
63 const auto &a = std::get<0>(GetInput());
64 const auto &b = std::get<1>(GetInput());
65 auto &c = GetOutput();
66
67 24 c.rows = a.rows;
68 24 c.cols = b.cols;
69 24 c.row_ptr.assign(c.rows + 1, 0);
70
71 24 std::vector<std::vector<double>> temp_values(c.rows);
72
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 std::vector<std::vector<std::size_t>> temp_cols(c.rows);
73
74 24 const int rows_limit = static_cast<int>(a.rows);
75
76 24 #pragma omp parallel default(none) shared(a, b, c, temp_values, temp_cols, rows_limit)
77 {
78 std::vector<double> accum(c.cols, 0.0);
79 std::vector<int> touched_flag(c.cols, -1);
80 std::vector<std::size_t> touched_cols;
81 touched_cols.reserve(c.cols);
82
83 #pragma omp for schedule(dynamic)
84 for (int i = 0; i < rows_limit; ++i) {
85 ProcessRow(static_cast<std::size_t>(i), a, b, temp_values[i], temp_cols[i], accum, touched_flag, touched_cols);
86 }
87 }
88
89
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (std::size_t i = 0; i < c.rows; ++i) {
90 48 c.row_ptr[i + 1] = c.row_ptr[i] + temp_values[i].size();
91 }
92
93
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 c.values.reserve(c.row_ptr[c.rows]);
94
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 c.col_indices.reserve(c.row_ptr[c.rows]);
95
96
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (std::size_t i = 0; i < c.rows; ++i) {
97
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 c.values.insert(c.values.end(), temp_values[i].begin(), temp_values[i].end());
98 48 c.col_indices.insert(c.col_indices.end(), temp_cols[i].begin(), temp_cols[i].end());
99 }
100
101 24 return true;
102 24 }
103
104 24 bool AlekseevAMultMatrixCRSOMP::PostProcessingImpl() {
105 24 return true;
106 }
107
108 } // namespace alekseev_a_mult_matrix_crs
109