GCC Code Coverage Report


Directory: ./
File: tasks/romanov_m_matrix_ccs/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 44 44 100.0%
Functions: 7 7 100.0%
Branches: 22 34 64.7%

Line Branch Exec Source
1 #include "romanov_m_matrix_ccs/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/parallel_for.h>
4
5 #include <algorithm>
6 #include <cmath>
7 #include <cstddef>
8 #include <vector>
9
10 #include "romanov_m_matrix_ccs/common/include/common.hpp"
11
12 namespace romanov_m_matrix_ccs {
13
14
1/2
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 RomanovMMatrixCCSTBB::RomanovMMatrixCCSTBB(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17 12 }
18
19 12 bool RomanovMMatrixCCSTBB::ValidationImpl() {
20 12 return GetInput().first.cols_num == GetInput().second.rows_num;
21 }
22
23 12 bool RomanovMMatrixCCSTBB::PreProcessingImpl() {
24 12 return true;
25 }
26
27 20 void RomanovMMatrixCCSTBB::MultiplyColumn(size_t col_index, const MatrixCCS &a, const MatrixCCS &b,
28 std::vector<double> &temp_v, std::vector<size_t> &temp_r) {
29 20 std::vector<double> accumulator(a.rows_num, 0.0);
30
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 std::vector<bool> row_mask(a.rows_num, false);
31 20 std::vector<size_t> active_rows;
32
33
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 for (size_t kb = b.col_ptrs[col_index]; kb < b.col_ptrs[col_index + 1]; ++kb) {
34 20 size_t k = b.row_inds[kb];
35 20 double v_b = b.vals[kb];
36
37
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 for (size_t ka = a.col_ptrs[k]; ka < a.col_ptrs[k + 1]; ++ka) {
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 size_t i = a.row_inds[ka];
39
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
20 if (!row_mask[i]) {
40 row_mask[i] = true;
41 active_rows.push_back(i);
42 }
43 20 accumulator[i] += a.vals[ka] * v_b;
44 }
45 }
46
47 std::ranges::sort(active_rows);
48
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 20 times.
32 for (size_t row_idx : active_rows) {
49
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (std::abs(accumulator[row_idx]) > 1e-12) {
50 temp_v.push_back(accumulator[row_idx]);
51 temp_r.push_back(row_idx);
52 }
53 }
54 20 }
55
56 12 bool RomanovMMatrixCCSTBB::RunImpl() {
57 12 const auto &a = GetInput().first;
58 12 const auto &b = GetInput().second;
59 auto &c = GetOutput();
60
61 12 c.rows_num = a.rows_num;
62 12 c.cols_num = b.cols_num;
63 12 c.col_ptrs.assign(c.cols_num + 1, 0);
64
65 12 std::vector<std::vector<double>> temp_vals(c.cols_num);
66
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 std::vector<std::vector<size_t>> temp_rows(c.cols_num);
67
68 12 tbb::parallel_for(static_cast<size_t>(0), b.cols_num,
69
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
32 [&](size_t j) { MultiplyColumn(j, a, b, temp_vals[j], temp_rows[j]); });
70
71 size_t total_nnz = 0;
72
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 12 times.
32 for (size_t j = 0; j < b.cols_num; ++j) {
73 20 c.col_ptrs[j] = total_nnz;
74 20 total_nnz += temp_vals[j].size();
75 }
76 12 c.col_ptrs[b.cols_num] = total_nnz;
77 12 c.nnz = total_nnz;
78
79
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 c.vals.reserve(total_nnz);
80
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 c.row_inds.reserve(total_nnz);
81
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 12 times.
32 for (size_t j = 0; j < b.cols_num; ++j) {
82
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 c.vals.insert(c.vals.end(), temp_vals[j].begin(), temp_vals[j].end());
83 20 c.row_inds.insert(c.row_inds.end(), temp_rows[j].begin(), temp_rows[j].end());
84 }
85
86 12 return true;
87 12 }
88
89 12 bool RomanovMMatrixCCSTBB::PostProcessingImpl() {
90 12 return true;
91 }
92
93 } // namespace romanov_m_matrix_ccs
94