GCC Code Coverage Report


Directory: ./
File: tasks/baranov_a_mult_matrix_fox_algorithm/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 45 47 95.7%
Functions: 8 9 88.9%
Branches: 21 28 75.0%

Line Branch Exec Source
1 #include "baranov_a_mult_matrix_fox_algorithm/tbb/include/ops_tbb.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <vector>
7
8 #include "baranov_a_mult_matrix_fox_algorithm/common/include/common.hpp"
9 #include "oneapi/tbb.h"
10
11 namespace baranov_a_mult_matrix_fox_algorithm_tbb {
12
13 80 BaranovAMultMatrixFoxAlgorithmTBB::BaranovAMultMatrixFoxAlgorithmTBB(
14
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 const baranov_a_mult_matrix_fox_algorithm::InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17 80 GetOutput() = std::vector<double>();
18 80 }
19
20 80 bool BaranovAMultMatrixFoxAlgorithmTBB::ValidationImpl() {
21 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
22
3/6
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 80 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 80 times.
80 return matrix_size > 0 && matrix_a.size() == matrix_size * matrix_size &&
23 80 matrix_b.size() == matrix_size * matrix_size;
24 }
25
26 80 bool BaranovAMultMatrixFoxAlgorithmTBB::PreProcessingImpl() {
27 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
28 80 GetOutput() = std::vector<double>(matrix_size * matrix_size, 0.0);
29 80 return true;
30 }
31
32 void BaranovAMultMatrixFoxAlgorithmTBB::StandardMultiplication(size_t n) {
33 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
34 auto &output = GetOutput();
35
36 72 tbb::parallel_for(static_cast<size_t>(0), n, [&](size_t i) {
37
2/2
✓ Branch 0 taken 6704 times.
✓ Branch 1 taken 480 times.
7184 for (size_t j = 0; j < n; ++j) {
38 double sum = 0.0;
39
2/2
✓ Branch 0 taken 157320 times.
✓ Branch 1 taken 6704 times.
164024 for (size_t k = 0; k < n; ++k) {
40 157320 sum += matrix_a[(i * n) + k] * matrix_b[(k * n) + j];
41 }
42 6704 output[(i * n) + j] = sum;
43 }
44 480 });
45 }
46
47 8 void BaranovAMultMatrixFoxAlgorithmTBB::FoxBlockMultiplication(size_t n, size_t block_size) {
48 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
49 auto &output = GetOutput();
50
51 8 size_t num_blocks = (n + block_size - 1) / block_size;
52
53 81928 tbb::parallel_for(static_cast<size_t>(0), n * n, [&](size_t idx) { output[idx] = 0.0; });
54
55
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
20 for (size_t bk = 0; bk < num_blocks; ++bk) {
56 12 tbb::parallel_for(static_cast<size_t>(0), num_blocks * num_blocks, [&](size_t linear_idx) {
57 36 size_t bi = linear_idx / num_blocks;
58 36 size_t bj = linear_idx % num_blocks;
59
60 36 size_t broadcast_block = (bi + bk) % num_blocks;
61
62 36 size_t i_start = bi * block_size;
63
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 size_t i_end = std::min(i_start + block_size, n);
64 36 size_t j_start = bj * block_size;
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 size_t j_end = std::min(j_start + block_size, n);
66 36 size_t k_start = broadcast_block * block_size;
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 size_t k_end = std::min(k_start + block_size, n);
68
69
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 36 times.
2340 for (size_t i = i_start; i < i_end; ++i) {
70
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 2304 times.
149760 for (size_t j = j_start; j < j_end; ++j) {
71 double sum = 0.0;
72
2/2
✓ Branch 0 taken 9437184 times.
✓ Branch 1 taken 147456 times.
9584640 for (size_t k = k_start; k < k_end; ++k) {
73 9437184 sum += matrix_a[(i * n) + k] * matrix_b[(k * n) + j];
74 }
75 147456 output[(i * n) + j] += sum;
76 }
77 }
78 36 });
79 }
80 8 }
81
82 80 bool BaranovAMultMatrixFoxAlgorithmTBB::RunImpl() {
83 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
84 80 size_t n = matrix_size;
85 size_t block_size = 64;
86
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 8 times.
80 if (n < block_size) {
87 72 StandardMultiplication(n);
88 } else {
89 8 FoxBlockMultiplication(n, block_size);
90 }
91
92 80 return true;
93 }
94
95 80 bool BaranovAMultMatrixFoxAlgorithmTBB::PostProcessingImpl() {
96 80 return true;
97 }
98
99 } // namespace baranov_a_mult_matrix_fox_algorithm_tbb
100