GCC Code Coverage Report


Directory: ./
File: tasks/shvetsova_k_mult_matrix_complex_col/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 38 38 100.0%
Functions: 7 7 100.0%
Branches: 23 36 63.9%

Line Branch Exec Source
1 #include "../../tbb/include/ops_tbb.hpp"
2
3 #include <tbb/tbb.h>
4
5 #include <algorithm>
6 #include <complex>
7 #include <cstddef>
8 #include <utility>
9 #include <vector>
10
11 #include "oneapi/tbb/blocked_range.h"
12 #include "oneapi/tbb/parallel_for.h"
13 #include "shvetsova_k_mult_matrix_complex_col/common/include/common.hpp"
14
15 namespace shvetsova_k_mult_matrix_complex_col {
16
17 struct SparseColumn {
18 std::vector<int> rows;
19 std::vector<std::complex<double>> vals;
20 };
21
22
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 ShvetsovaKMultMatrixComplexTBB::ShvetsovaKMultMatrixComplexTBB(const InType &in) {
23 SetTypeOfTask(GetStaticTypeOfTask());
24 GetInput() = in;
25
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 GetOutput() = MatrixCCS(0, 0, std::vector<int>{0}, std::vector<int>{}, std::vector<std::complex<double>>{});
26 20 }
27
28 20 bool ShvetsovaKMultMatrixComplexTBB::ValidationImpl() {
29 20 return true;
30 }
31
32 20 bool ShvetsovaKMultMatrixComplexTBB::PreProcessingImpl() {
33 const auto &matrix_a = std::get<0>(GetInput());
34 const auto &matrix_b = std::get<1>(GetInput());
35
36 auto &matrix_c = GetOutput();
37 20 matrix_c.rows = matrix_a.rows;
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 matrix_c.cols = matrix_b.cols;
39 matrix_c.row_ind.clear();
40 matrix_c.values.clear();
41 matrix_c.col_ptr.clear();
42 20 matrix_c.col_ptr.push_back(0);
43 20 return true;
44 }
45
46 20 bool ShvetsovaKMultMatrixComplexTBB::RunImpl() {
47 const MatrixCCS &matrix_a = std::get<0>(GetInput());
48 const MatrixCCS &matrix_b = std::get<1>(GetInput());
49
50 auto &matrix_c = GetOutput();
51
52 20 std::vector<SparseColumn> columns_c(matrix_b.cols);
53
54
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 auto compute_column = [&](int i, std::vector<std::complex<double>> &column_c) {
55 std::ranges::fill(column_c, std::complex<double>{0.0, 0.0});
56
57
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 36 times.
76 for (int j = matrix_b.col_ptr[i]; j < matrix_b.col_ptr[i + 1]; j++) {
58 40 int tmp_ind = matrix_b.row_ind[j];
59 40 std::complex<double> tmp_val = matrix_b.values[j];
60
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 40 times.
80 for (int ind = matrix_a.col_ptr[tmp_ind]; ind < matrix_a.col_ptr[tmp_ind + 1]; ind++) {
61 40 int row = matrix_a.row_ind[ind];
62 40 std::complex<double> val_a = matrix_a.values[ind];
63 40 column_c[row] += tmp_val * val_a;
64 }
65 }
66
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 for (int index = 0; std::cmp_less(index, column_c.size()); ++index) {
67
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 36 times.
68 if (column_c[index].real() != 0.0 || column_c[index].imag() != 0.0) {
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 columns_c[i].rows.push_back(index);
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 columns_c[i].vals.push_back(column_c[index]);
70 }
71 }
72 56 };
73
74 size_t grain_size = 100;
75
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 tbb::parallel_for(tbb::blocked_range<int>(0, matrix_b.cols, grain_size), [&](const tbb::blocked_range<int> &r) {
76 20 std::vector<std::complex<double>> column_c_local(matrix_a.rows, {0.0, 0.0});
77
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 20 times.
56 for (int i = r.begin(); i != r.end(); ++i) {
78
1/2
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
36 compute_column(i, column_c_local);
79 }
80 20 }, tbb::static_partitioner());
81
82
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 20 times.
56 for (int i = 0; i < matrix_b.cols; i++) {
83
1/2
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
36 matrix_c.row_ind.insert(matrix_c.row_ind.end(), columns_c[i].rows.begin(), columns_c[i].rows.end());
84
1/2
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
36 matrix_c.values.insert(matrix_c.values.end(), columns_c[i].vals.begin(), columns_c[i].vals.end());
85
1/2
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
36 matrix_c.col_ptr.push_back(static_cast<int>(matrix_c.row_ind.size()));
86 }
87
88 20 return true;
89 20 }
90
91 20 bool ShvetsovaKMultMatrixComplexTBB::PostProcessingImpl() {
92 20 return true;
93 }
94
95 } // namespace shvetsova_k_mult_matrix_complex_col
96