GCC Code Coverage Report


Directory: ./
File: tasks/cheremkhin_a_matr_mult_cannon_alg/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 49 49 100.0%
Functions: 6 6 100.0%
Branches: 30 44 68.2%

Line Branch Exec Source
1 #include "cheremkhin_a_matr_mult_cannon_alg/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <utility>
6 #include <vector>
7
8 #include "cheremkhin_a_matr_mult_cannon_alg/common/include/common.hpp"
9
10 namespace cheremkhin_a_matr_mult_cannon_alg {
11
12 namespace {
13
14 inline std::size_t Idx(std::size_t n, std::size_t r, std::size_t c) {
15 6464 return (r * n) + c;
16 }
17
18 std::size_t ChooseQ(std::size_t n) {
19 56 if (n <= 1) {
20 return 1;
21 }
22 48 const auto root = static_cast<std::size_t>(std::sqrt(static_cast<double>(n)));
23
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 return (root == 0) ? 1 : root;
24 }
25
26 std::size_t CeilDiv(std::size_t a, std::size_t b) {
27 56 return (a + b - 1) / b;
28 }
29
30 584 void MulAddBlock(const std::vector<double> &a, const std::vector<double> &b, std::vector<double> &c, std::size_t n,
31 std::size_t bs, std::size_t bi, std::size_t bk, std::size_t bj) {
32 584 const std::size_t i0 = bi * bs;
33 584 const std::size_t k0 = bk * bs;
34 584 const std::size_t j0 = bj * bs;
35
36
2/2
✓ Branch 0 taken 2376 times.
✓ Branch 1 taken 584 times.
2960 for (std::size_t ii = 0; ii < bs; ++ii) {
37 2376 const std::size_t i = i0 + ii;
38 2376 const std::size_t a_row = i * n;
39 const std::size_t c_row = i * n;
40
2/2
✓ Branch 0 taken 10248 times.
✓ Branch 1 taken 2376 times.
12624 for (std::size_t kk = 0; kk < bs; ++kk) {
41 10248 const std::size_t k = k0 + kk;
42 10248 const double aik = a[a_row + k];
43 10248 const std::size_t b_row = k * n;
44
2/2
✓ Branch 0 taken 45720 times.
✓ Branch 1 taken 10248 times.
55968 for (std::size_t jj = 0; jj < bs; ++jj) {
45 45720 const std::size_t j = j0 + jj;
46 45720 c[c_row + j] += aik * b[b_row + j];
47 }
48 }
49 }
50 584 }
51
52 } // namespace
53
54
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 CheremkhinAMatrMultCannonAlgSEQ::CheremkhinAMatrMultCannonAlgSEQ(const InType &in) {
55 SetTypeOfTask(GetStaticTypeOfTask());
56 GetInput() = in;
57 GetOutput() = {};
58 56 }
59
60 56 bool CheremkhinAMatrMultCannonAlgSEQ::ValidationImpl() {
61 56 const std::size_t n = std::get<0>(GetInput());
62 const auto &a = std::get<1>(GetInput());
63 const auto &b = std::get<2>(GetInput());
64
3/6
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 56 times.
56 return n > 0 && a.size() == n * n && b.size() == n * n;
65 }
66
67 56 bool CheremkhinAMatrMultCannonAlgSEQ::PreProcessingImpl() {
68 GetOutput() = {};
69 56 return true;
70 }
71
72 56 bool CheremkhinAMatrMultCannonAlgSEQ::RunImpl() {
73
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 48 times.
56 const std::size_t n = std::get<0>(GetInput());
74 const auto &a_in = std::get<1>(GetInput());
75 const auto &b_in = std::get<2>(GetInput());
76
77 const std::size_t q = ChooseQ(n);
78 const std::size_t bs = CeilDiv(n, q);
79 56 const std::size_t np = q * bs;
80
81 56 std::vector<double> a(np * np, 0.0);
82
1/4
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
56 std::vector<double> b(np * np, 0.0);
83
1/4
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
56 std::vector<double> c(np * np, 0.0);
84
85
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 56 times.
392 for (std::size_t i = 0; i < n; ++i) {
86
2/2
✓ Branch 0 taken 3232 times.
✓ Branch 1 taken 336 times.
3568 for (std::size_t j = 0; j < n; ++j) {
87 3232 a[Idx(np, i, j)] = a_in[Idx(n, i, j)];
88 3232 b[Idx(np, i, j)] = b_in[Idx(n, i, j)];
89 }
90 }
91
92
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 56 times.
160 for (std::size_t bi = 0; bi < q; ++bi) {
93
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 104 times.
336 for (std::size_t bj = 0; bj < q; ++bj) {
94
2/2
✓ Branch 0 taken 584 times.
✓ Branch 1 taken 232 times.
816 for (std::size_t step = 0; step < q; ++step) {
95 584 const std::size_t bk = (bj + bi + step) % q;
96 584 MulAddBlock(a, b, c, np, bs, bi, bk, bj);
97 }
98 }
99 }
100
101
1/4
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
56 std::vector<double> out(n * n, 0.0);
102
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 56 times.
392 for (std::size_t i = 0; i < n; ++i) {
103
2/2
✓ Branch 0 taken 3232 times.
✓ Branch 1 taken 336 times.
3568 for (std::size_t j = 0; j < n; ++j) {
104 3232 out[Idx(n, i, j)] = c[Idx(np, i, j)];
105 }
106 }
107
108 GetOutput() = std::move(out);
109 56 return true;
110 }
111
112 56 bool CheremkhinAMatrMultCannonAlgSEQ::PostProcessingImpl() {
113 56 return true;
114 }
115
116 } // namespace cheremkhin_a_matr_mult_cannon_alg
117