GCC Code Coverage Report


Directory: ./
File: tasks/luzan_e_double_sparse_matrix_mult/omp/src/ops_omp.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 6 6 100.0%
Branches: 19 30 63.3%

Line Branch Exec Source
1 #include "luzan_e_double_sparse_matrix_mult/omp/include/ops_omp.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <vector>
6
7 #include "luzan_e_double_sparse_matrix_mult/common/include/common.hpp"
8
9 namespace luzan_e_double_sparse_matrix_mult {
10 24 SparseMatrix LuzanEDoubleSparseMatrixMultOMP::CalcProdOMP(const SparseMatrix &a, const SparseMatrix &b) {
11
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 SparseMatrix c(a.rows, b.cols);
12
13 /// tmp storage
14
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 std::vector<std::vector<double>> values_per_col(b.cols);
15
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 std::vector<std::vector<unsigned>> rowsper_col(b.cols);
16
17 24 #pragma omp parallel for shared(a, b, values_per_col, rowsper_col, kEPS) schedule(static) default(none)
18 for (unsigned b_col = 0; b_col < static_cast<unsigned>(b.cols); b_col++) {
19 std::vector<double> tmp_col(a.rows, 0.0);
20
21 unsigned b_rowsstart = b.col_index[b_col];
22 unsigned b_rowsend = b.col_index[b_col + 1];
23
24 for (unsigned b_pos = b_rowsstart; b_pos < b_rowsend; b_pos++) {
25 double b_val = b.value[b_pos];
26 unsigned b_row = b.row[b_pos];
27
28 unsigned a_rowsstart = a.col_index[b_row];
29 unsigned a_rowsend = a.col_index[b_row + 1];
30
31 for (unsigned a_pos = a_rowsstart; a_pos < a_rowsend; a_pos++) {
32 double a_val = a.value[a_pos];
33 unsigned a_row = a.row[a_pos];
34
35 tmp_col[a_row] += a_val * b_val;
36 }
37 }
38
39 for (unsigned i = 0; i < a.rows; i++) {
40 if (fabs(tmp_col[i]) > kEPS) {
41 values_per_col[b_col].push_back(tmp_col[i]);
42 rowsper_col[b_col].push_back(i);
43 }
44 }
45 }
46
47
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 c.col_index.push_back(0);
48
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 24 times.
88 for (unsigned j = 0; j < b.cols; j++) {
49
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 64 times.
184 for (size_t k = 0; k < values_per_col[j].size(); k++) {
50
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 68 times.
120 c.value.push_back(values_per_col[j][k]);
51
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 68 times.
120 c.row.push_back(rowsper_col[j][k]);
52 }
53
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 c.col_index.push_back(c.value.size());
54 }
55
56 24 return c;
57 24 }
58
59
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 LuzanEDoubleSparseMatrixMultOMP::LuzanEDoubleSparseMatrixMultOMP(const InType &in) {
60 SetTypeOfTask(GetStaticTypeOfTask());
61 GetInput() = in;
62 // GetOutput() = 0;
63 24 }
64
65
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 bool LuzanEDoubleSparseMatrixMultOMP::ValidationImpl() {
66 const auto &a = std::get<0>(GetInput());
67 const auto &b = std::get<1>(GetInput());
68
4/8
✓ 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.
✗ Branch 6 not taken.
✓ Branch 7 taken 24 times.
24 return a.GetCols() == b.GetRows() && a.GetCols() != 0 && a.GetRows() != 0 && b.GetCols() != 0;
69 }
70
71 24 bool LuzanEDoubleSparseMatrixMultOMP::PreProcessingImpl() {
72 24 return true;
73 }
74
75 24 bool LuzanEDoubleSparseMatrixMultOMP::RunImpl() {
76 const auto &a = std::get<0>(GetInput());
77 const auto &b = std::get<1>(GetInput());
78
79 24 GetOutput() = CalcProdOMP(a, b);
80 24 return true;
81 }
82
83 24 bool LuzanEDoubleSparseMatrixMultOMP::PostProcessingImpl() {
84 24 return true;
85 }
86
87 } // namespace luzan_e_double_sparse_matrix_mult
88