GCC Code Coverage Report


Directory: ./
File: tasks/zavyalov_a_complex_sparse_matrix_mult/tbb/src/ops_tbb.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 35 36 97.2%
Functions: 7 7 100.0%
Branches: 20 26 76.9%

Line Branch Exec Source
1 #include "zavyalov_a_complex_sparse_matrix_mult/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/tbb.h>
4
5 #include <cstddef>
6 #include <map>
7 #include <stdexcept>
8 #include <utility>
9 #include <vector>
10
11 #include "zavyalov_a_complex_sparse_matrix_mult/common/include/common.hpp"
12
13 namespace zavyalov_a_compl_sparse_matr_mult {
14
15 40 SparseMatrix ZavyalovAComplSparseMatrMultTBB::MultiplicateWithTbb(const SparseMatrix &matr_a,
16 const SparseMatrix &matr_b) {
17
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (matr_a.width != matr_b.height) {
18 throw std::invalid_argument("Incompatible matrix dimensions for multiplication");
19 }
20
21 40 tbb::enumerable_thread_specific<std::map<std::pair<size_t, size_t>, Complex>> local_maps;
22
23
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 tbb::parallel_for(tbb::blocked_range<size_t>(0, matr_a.Count()), [&](const tbb::blocked_range<size_t> &range) {
24 660 auto &my_map = local_maps.local();
25
2/2
✓ Branch 0 taken 660 times.
✓ Branch 1 taken 660 times.
1320 for (size_t i = range.begin(); i != range.end(); ++i) {
26 660 size_t row_a = matr_a.row_ind[i];
27 660 size_t col_a = matr_a.col_ind[i];
28 660 Complex val_a = matr_a.val[i];
29
30
2/2
✓ Branch 0 taken 10836 times.
✓ Branch 1 taken 660 times.
11496 for (size_t j = 0; j < matr_b.Count(); ++j) {
31
2/2
✓ Branch 0 taken 2364 times.
✓ Branch 1 taken 8472 times.
10836 if (col_a == matr_b.row_ind[j]) {
32 2364 my_map[{row_a, matr_b.col_ind[j]}] += val_a * matr_b.val[j];
33 }
34 }
35 }
36 660 });
37
38 std::map<std::pair<size_t, size_t>, Complex> mp;
39 for (auto &lm : local_maps) {
40
2/2
✓ Branch 0 taken 855 times.
✓ Branch 1 taken 61 times.
916 for (auto &[key, value] : lm) {
41
1/2
✓ Branch 1 taken 855 times.
✗ Branch 2 not taken.
855 mp[key] += value;
42 }
43 }
44
45 40 SparseMatrix res;
46 40 res.width = matr_b.width;
47 40 res.height = matr_a.height;
48
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 40 times.
628 for (const auto &[key, value] : mp) {
49
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 188 times.
588 res.val.push_back(value);
50
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 188 times.
588 res.row_ind.push_back(key.first);
51
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 188 times.
588 res.col_ind.push_back(key.second);
52 }
53
54 40 return res;
55 40 }
56
57
1/2
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 ZavyalovAComplSparseMatrMultTBB::ZavyalovAComplSparseMatrMultTBB(const InType &in) {
58 SetTypeOfTask(GetStaticTypeOfTask());
59 GetInput() = in;
60 40 }
61
62 40 bool ZavyalovAComplSparseMatrMultTBB::ValidationImpl() {
63 const auto &matr_a = std::get<0>(GetInput());
64 const auto &matr_b = std::get<1>(GetInput());
65 40 return matr_a.width == matr_b.height;
66 }
67
68 40 bool ZavyalovAComplSparseMatrMultTBB::PreProcessingImpl() {
69 40 return true;
70 }
71
72 40 bool ZavyalovAComplSparseMatrMultTBB::RunImpl() {
73 const auto &matr_a = std::get<0>(GetInput());
74 const auto &matr_b = std::get<1>(GetInput());
75
76 40 GetOutput() = MultiplicateWithTbb(matr_a, matr_b);
77
78 40 return true;
79 }
80
81 40 bool ZavyalovAComplSparseMatrMultTBB::PostProcessingImpl() {
82 40 return true;
83 }
84
85 } // namespace zavyalov_a_compl_sparse_matr_mult
86