GCC Code Coverage Report


Directory: ./
File: tasks/baranov_a_mult_matrix_fox_algorithm/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 48 48 100.0%
Functions: 8 8 100.0%
Branches: 26 30 86.7%

Line Branch Exec Source
1 #include "baranov_a_mult_matrix_fox_algorithm/seq/include/ops_seq.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
10 namespace {
11
12 72 void ProcessBlock(const std::vector<double> &matrix_a, const std::vector<double> &matrix_b, std::vector<double> &output,
13 size_t n, size_t i_start, size_t i_end, size_t j_start, size_t j_end, size_t k_start, size_t k_end) {
14
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 72 times.
4680 for (size_t i = i_start; i < i_end; ++i) {
15
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 4608 times.
299520 for (size_t j = j_start; j < j_end; ++j) {
16 double sum = 0.0;
17
2/2
✓ Branch 0 taken 18874368 times.
✓ Branch 1 taken 294912 times.
19169280 for (size_t k = k_start; k < k_end; ++k) {
18 18874368 sum += matrix_a[(i * n) + k] * matrix_b[(k * n) + j];
19 }
20 294912 output[(i * n) + j] += sum;
21 }
22 }
23 72 }
24
25 } // namespace
26
27 namespace baranov_a_mult_matrix_fox_algorithm_seq {
28
29 160 BaranovAMultMatrixFoxAlgorithmSEQ::BaranovAMultMatrixFoxAlgorithmSEQ(
30
1/2
✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
160 const baranov_a_mult_matrix_fox_algorithm::InType &in) {
31 SetTypeOfTask(GetStaticTypeOfTask());
32 GetInput() = in;
33 160 GetOutput() = std::vector<double>();
34 160 }
35
36 160 bool BaranovAMultMatrixFoxAlgorithmSEQ::ValidationImpl() {
37 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
38
39
3/6
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 160 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 160 times.
160 return matrix_size > 0 && matrix_a.size() == matrix_size * matrix_size &&
40 160 matrix_b.size() == matrix_size * matrix_size;
41 }
42
43 160 bool BaranovAMultMatrixFoxAlgorithmSEQ::PreProcessingImpl() {
44 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
45 160 GetOutput() = std::vector<double>(matrix_size * matrix_size, 0.0);
46 160 return true;
47 }
48
49 144 void BaranovAMultMatrixFoxAlgorithmSEQ::StandardMultiplication(size_t n) {
50 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
51 auto &output = GetOutput();
52
53
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 144 times.
1104 for (size_t i = 0; i < n; ++i) {
54
2/2
✓ Branch 0 taken 13408 times.
✓ Branch 1 taken 960 times.
14368 for (size_t j = 0; j < n; ++j) {
55 double sum = 0.0;
56
2/2
✓ Branch 0 taken 314640 times.
✓ Branch 1 taken 13408 times.
328048 for (size_t k = 0; k < n; ++k) {
57 314640 sum += matrix_a[(i * n) + k] * matrix_b[(k * n) + j];
58 }
59 13408 output[(i * n) + j] = sum;
60 }
61 }
62 144 }
63
64 16 void BaranovAMultMatrixFoxAlgorithmSEQ::FoxBlockMultiplication(size_t n, size_t block_size) {
65 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
66 auto &output = GetOutput();
67
68 16 size_t num_blocks = (n + block_size - 1) / block_size;
69
70
2/2
✓ Branch 0 taken 163840 times.
✓ Branch 1 taken 16 times.
163856 for (size_t idx = 0; idx < n * n; ++idx) {
71 163840 output[idx] = 0.0;
72 }
73
74
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 16 times.
40 for (size_t bi = 0; bi < num_blocks; ++bi) {
75
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 24 times.
64 for (size_t bj = 0; bj < num_blocks; ++bj) {
76
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 40 times.
112 for (size_t bk = 0; bk < num_blocks; ++bk) {
77 72 size_t broadcast_block = (bi + bk) % num_blocks;
78
79 72 size_t i_start = bi * block_size;
80 72 size_t i_end = std::min(i_start + block_size, n);
81 72 size_t j_start = bj * block_size;
82 72 size_t j_end = std::min(j_start + block_size, n);
83 72 size_t k_start = broadcast_block * block_size;
84 72 size_t k_end = std::min(k_start + block_size, n);
85
86 72 ProcessBlock(matrix_a, matrix_b, output, n, i_start, i_end, j_start, j_end, k_start, k_end);
87 }
88 }
89 }
90 16 }
91
92 160 bool BaranovAMultMatrixFoxAlgorithmSEQ::RunImpl() {
93 const auto &[matrix_size, matrix_a, matrix_b] = GetInput();
94 160 size_t n = matrix_size;
95
96 size_t block_size = 64;
97
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 16 times.
160 if (n < block_size) {
98 144 StandardMultiplication(n);
99 } else {
100 16 FoxBlockMultiplication(n, block_size);
101 }
102
103 160 return true;
104 }
105
106 160 bool BaranovAMultMatrixFoxAlgorithmSEQ::PostProcessingImpl() {
107 160 return true;
108 }
109
110 } // namespace baranov_a_mult_matrix_fox_algorithm_seq
111