GCC Code Coverage Report


Directory: ./
File: tasks/korolev_k_matrix_mult/stl/src/ops_stl.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 14 36 38.9%
Functions: 5 7 71.4%
Branches: 9 48 18.8%

Line Branch Exec Source
1 #include "korolev_k_matrix_mult/stl/include/ops_stl.hpp"
2
3 #include <cstddef>
4 #include <functional>
5 #include <thread>
6 #include <vector>
7
8 #include "korolev_k_matrix_mult/common/include/common.hpp"
9 #include "korolev_k_matrix_mult/common/include/strassen_impl.hpp"
10
11 namespace korolev_k_matrix_mult {
12
13 namespace {
14
15 void ParallelInvokeThreads(std::vector<std::function<void()>> &tasks) {
16 std::vector<std::thread> threads;
17 threads.reserve(tasks.size());
18 for (auto &t : tasks) {
19 threads.emplace_back(t);
20 }
21 for (auto &th : threads) {
22 th.join();
23 }
24 }
25
26 void PadInputBlocks(const InType &in, size_t n, size_t np2, std::vector<double> &a_pad, std::vector<double> &b_pad) {
27 for (size_t i = 0; i < n; ++i) {
28 for (size_t j = 0; j < n; ++j) {
29 a_pad[(i * np2) + j] = in.A[(i * n) + j];
30 b_pad[(i * np2) + j] = in.B[(i * n) + j];
31 }
32 }
33 }
34
35 void CopyResultCorner(const std::vector<double> &c_pad, std::vector<double> &out, size_t n, size_t np2) {
36 for (size_t i = 0; i < n; ++i) {
37 for (size_t j = 0; j < n; ++j) {
38 out[(i * n) + j] = c_pad[(i * np2) + j];
39 }
40 }
41 }
42
43 } // namespace
44
45
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 KorolevKMatrixMultSTL::KorolevKMatrixMultSTL(const InType &in) {
46 SetTypeOfTask(GetStaticTypeOfTask());
47 GetInput() = in;
48 GetOutput().clear();
49 24 }
50
51 24 bool KorolevKMatrixMultSTL::ValidationImpl() {
52 const auto &in = GetInput();
53
4/8
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 24 times.
24 return in.n > 0 && in.A.size() == in.n * in.n && in.B.size() == in.n * in.n && GetOutput().empty();
54 }
55
56 24 bool KorolevKMatrixMultSTL::PreProcessingImpl() {
57 24 GetOutput().resize(GetInput().n * GetInput().n);
58 24 return true;
59 }
60
61
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 bool KorolevKMatrixMultSTL::RunImpl() {
62 const auto &in = GetInput();
63
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 size_t n = in.n;
64 size_t np2 = strassen_impl::NextPowerOf2(n);
65
66
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (np2 == n) {
67
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
48 strassen_impl::StrassenMultiply(in.A, in.B, GetOutput(), n, ParallelInvokeThreads);
68 } else {
69 std::vector<double> a_pad(np2 * np2, 0);
70 std::vector<double> b_pad(np2 * np2, 0);
71 std::vector<double> c_pad(np2 * np2, 0);
72 PadInputBlocks(in, n, np2, a_pad, b_pad);
73 strassen_impl::StrassenMultiply(a_pad, b_pad, c_pad, np2, ParallelInvokeThreads);
74 CopyResultCorner(c_pad, GetOutput(), n, np2);
75 }
76 24 return true;
77 }
78
79 24 bool KorolevKMatrixMultSTL::PostProcessingImpl() {
80 24 return !GetOutput().empty();
81 }
82
83 } // namespace korolev_k_matrix_mult
84