GCC Code Coverage Report


Directory: ./
File: tasks/potashnik_m_matrix_mult_complex/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 43 43 100.0%
Functions: 6 6 100.0%
Branches: 20 30 66.7%

Line Branch Exec Source
1 #include "potashnik_m_matrix_mult_complex/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/tbb.h>
4
5 #include <cstddef>
6 #include <map>
7 #include <utility>
8 #include <vector>
9
10 #include "potashnik_m_matrix_mult_complex/common/include/common.hpp"
11
12 namespace potashnik_m_matrix_mult_complex {
13
14
1/2
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 PotashnikMMatrixMultComplexTBB::PotashnikMMatrixMultComplexTBB(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17 40 }
18
19 40 bool PotashnikMMatrixMultComplexTBB::ValidationImpl() {
20 const auto &matrix_left = std::get<0>(GetInput());
21 const auto &matrix_right = std::get<1>(GetInput());
22 40 return matrix_left.width == matrix_right.height;
23 }
24
25 40 bool PotashnikMMatrixMultComplexTBB::PreProcessingImpl() {
26 40 return true;
27 }
28
29 40 bool PotashnikMMatrixMultComplexTBB::RunImpl() {
30 const auto &matrix_left = std::get<0>(GetInput());
31 const auto &matrix_right = std::get<1>(GetInput());
32
33 40 const auto &val_left = matrix_left.val;
34 40 const auto &row_ind_left = matrix_left.row_ind;
35 40 const auto &col_ptr_left = matrix_left.col_ptr;
36 40 size_t height_left = matrix_left.height;
37
38 40 const auto &val_right = matrix_right.val;
39 40 const auto &row_ind_right = matrix_right.row_ind;
40 40 const auto &col_ptr_right = matrix_right.col_ptr;
41 40 size_t width_right = matrix_right.width;
42
43 size_t left_count = matrix_left.Count();
44 size_t right_count = matrix_right.Count();
45
46 using Key = std::pair<size_t, size_t>;
47 using LocalMap = std::map<Key, Complex>;
48
49 40 tbb::enumerable_thread_specific<LocalMap> local_buffers;
50
51 const size_t grain_i = 64;
52 const size_t grain_j = 256;
53
54 40 tbb::parallel_for(tbb::blocked_range2d<size_t>(0, left_count, grain_i, 0, right_count, grain_j),
55
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 [&](const tbb::blocked_range2d<size_t> &r) {
56 48 auto &local_buffer = local_buffers.local();
57
58
2/2
✓ Branch 0 taken 1684 times.
✓ Branch 1 taken 48 times.
1732 for (size_t i = r.rows().begin(); i != r.rows().end(); ++i) {
59 1684 size_t row_left = row_ind_left[i];
60 1684 size_t col_left = col_ptr_left[i];
61 1684 Complex left_val = val_left[i];
62
63
2/2
✓ Branch 0 taken 96352 times.
✓ Branch 1 taken 1684 times.
98036 for (size_t j = r.cols().begin(); j != r.cols().end(); ++j) {
64
2/2
✓ Branch 0 taken 11936 times.
✓ Branch 1 taken 84416 times.
96352 if (col_left == row_ind_right[j]) {
65 11936 local_buffer[{row_left, col_ptr_right[j]}] += left_val * val_right[j];
66 }
67 }
68 }
69 48 });
70
71 std::map<Key, Complex> buffer;
72 for (const auto &local : local_buffers) {
73
2/2
✓ Branch 0 taken 2259 times.
✓ Branch 1 taken 46 times.
2305 for (const auto &[key, value] : local) {
74
1/2
✓ Branch 1 taken 2259 times.
✗ Branch 2 not taken.
2259 buffer[key] += value;
75 }
76 }
77
78 40 CCSMatrix matrix_res;
79 40 matrix_res.width = width_right;
80
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 matrix_res.height = height_left;
81
82
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 matrix_res.val.reserve(buffer.size());
83
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 matrix_res.row_ind.reserve(buffer.size());
84
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 matrix_res.col_ptr.reserve(buffer.size());
85
86
2/2
✓ Branch 0 taken 1716 times.
✓ Branch 1 taken 40 times.
1756 for (const auto &[key, value] : buffer) {
87 matrix_res.val.push_back(value);
88
1/2
✓ Branch 0 taken 1716 times.
✗ Branch 1 not taken.
1716 matrix_res.row_ind.push_back(key.first);
89
1/2
✓ Branch 0 taken 1716 times.
✗ Branch 1 not taken.
1716 matrix_res.col_ptr.push_back(key.second);
90 }
91
92
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 GetOutput() = matrix_res;
93 40 return true;
94 80 }
95
96 40 bool PotashnikMMatrixMultComplexTBB::PostProcessingImpl() {
97 40 return true;
98 }
99
100 } // namespace potashnik_m_matrix_mult_complex
101