GCC Code Coverage Report


Directory: ./
File: tasks/goriacheva_k_mult_sparse_complex_matrix_ccs/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 43 44 97.7%
Functions: 7 7 100.0%
Branches: 28 46 60.9%

Line Branch Exec Source
1 #include "goriacheva_k_mult_sparse_complex_matrix_ccs/tbb/include/ops_tbb.hpp"
2
3 #include <algorithm>
4 #include <ranges>
5 #include <vector>
6
7 #include "goriacheva_k_mult_sparse_complex_matrix_ccs/common/include/common.hpp"
8 #include "oneapi/tbb/parallel_for.h"
9
10 namespace goriacheva_k_mult_sparse_complex_matrix_ccs {
11
12
1/2
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
56 GoriachevaKMultSparseComplexMatrixCcsTBB::GoriachevaKMultSparseComplexMatrixCcsTBB(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 56 }
16
17 56 bool GoriachevaKMultSparseComplexMatrixCcsTBB::ValidationImpl() {
18 auto &[a, b] = GetInput();
19
20
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 if (a.cols != b.rows) {
21 return false;
22 }
23
24
2/4
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
56 if (a.col_ptr.empty() || b.col_ptr.empty()) {
25 return false;
26 }
27
28 return true;
29 }
30
31 56 bool GoriachevaKMultSparseComplexMatrixCcsTBB::PreProcessingImpl() {
32 56 GetOutput() = {};
33 56 return true;
34 }
35
36 namespace {
37
38 164 void ProcessColumn(int j, const SparseMatrixCCS &a, const SparseMatrixCCS &b, std::vector<Complex> &values,
39 std::vector<int> &rows) {
40 164 std::vector<Complex> accumulator(a.rows);
41
1/4
✓ Branch 1 taken 164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
164 std::vector<int> marker(a.rows, -1);
42 164 std::vector<int> used_rows;
43
44
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 164 times.
276 for (int bi = b.col_ptr[j]; bi < b.col_ptr[j + 1]; bi++) {
45 112 int k = b.row_ind[bi];
46 112 Complex b_val = b.values[bi];
47
48
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 112 times.
220 for (int ai = a.col_ptr[k]; ai < a.col_ptr[k + 1]; ai++) {
49
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 int i = a.row_ind[ai];
50
51
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if (marker[i] != j) {
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 marker[i] = j;
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 accumulator[i] = Complex(0.0, 0.0);
54 used_rows.push_back(i);
55 }
56
57 accumulator[i] += a.values[ai] * b_val;
58 }
59 }
60
61 std::ranges::sort(used_rows);
62
63
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 164 times.
272 for (int r : used_rows) {
64
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 96 times.
108 if (accumulator[r] != Complex(0.0, 0.0)) {
65 rows.push_back(r);
66 values.push_back(accumulator[r]);
67 }
68 }
69 164 }
70
71 } // namespace
72
73 56 bool GoriachevaKMultSparseComplexMatrixCcsTBB::RunImpl() {
74 auto &a = std::get<0>(GetInput());
75 auto &b = std::get<1>(GetInput());
76 auto &c = GetOutput();
77
78 56 c.rows = a.rows;
79 56 c.cols = b.cols;
80 56 c.col_ptr.resize(c.cols + 1);
81
82 56 std::vector<std::vector<Complex>> local_values(c.cols);
83
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 std::vector<std::vector<int>> local_rows(c.cols);
84
85
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
220 oneapi::tbb::parallel_for(0, b.cols, [&](int j) { ProcessColumn(j, a, b, local_values[j], local_rows[j]); });
86
87 int nnz = 0;
88
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 56 times.
220 for (int j = 0; j < c.cols; j++) {
89 164 c.col_ptr[j] = nnz;
90 164 nnz += static_cast<int>(local_values[j].size());
91 }
92
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 c.col_ptr[c.cols] = nnz;
93
94
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 c.values.reserve(nnz);
95
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 c.row_ind.reserve(nnz);
96
97
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 56 times.
220 for (int j = 0; j < c.cols; j++) {
98
2/4
✓ Branch 1 taken 164 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 164 times.
✗ Branch 5 not taken.
164 c.values.insert(c.values.end(), local_values[j].begin(), local_values[j].end());
99
100 164 c.row_ind.insert(c.row_ind.end(), local_rows[j].begin(), local_rows[j].end());
101 }
102
103 56 return true;
104 56 }
105
106 56 bool GoriachevaKMultSparseComplexMatrixCcsTBB::PostProcessingImpl() {
107 56 return true;
108 }
109
110 } // namespace goriacheva_k_mult_sparse_complex_matrix_ccs
111