GCC Code Coverage Report


Directory: ./
File: tasks/olesnitskiy_v_striped_matrix_multiplication/seq/src/ops_seq.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 62 65 95.4%
Functions: 9 9 100.0%
Branches: 43 62 69.4%

Line Branch Exec Source
1 #include "olesnitskiy_v_striped_matrix_multiplication/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cstddef>
5 #include <tuple>
6 #include <vector>
7
8 #include "olesnitskiy_v_striped_matrix_multiplication/common/include/common.hpp"
9
10 namespace olesnitskiy_v_striped_matrix_multiplication {
11
12 namespace {
13 120 int FindCommonDivisor(int a, int b, int max_divisor) {
14
2/4
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 120 times.
120 if (a <= 0 || b <= 0 || max_divisor <= 1) {
15 return 1;
16 }
17
18
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 224 times.
344 for (int divisor = std::min({a, b, max_divisor}); divisor >= 1; --divisor) {
19
4/4
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 120 times.
224 if (a % divisor == 0 && b % divisor == 0) {
20 return divisor;
21 }
22 }
23
24 return 1;
25 }
26 } // namespace
27
28
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 OlesnitskiyVStripedMatrixMultiplicationSEQ::OlesnitskiyVStripedMatrixMultiplicationSEQ(const InType &in) {
29 SetTypeOfTask(GetStaticTypeOfTask());
30 GetInput() = in;
31 120 GetOutput() = std::make_tuple(0, 0, std::vector<double>());
32 120 }
33
34 120 bool OlesnitskiyVStripedMatrixMultiplicationSEQ::ValidationImpl() {
35 const auto &[rows_a, cols_a, data_a, rows_b, cols_b, data_b] = GetInput();
36 const auto &[out_rows, out_cols, out_data] = GetOutput();
37 120 rows_a_ = rows_a;
38 120 cols_a_ = cols_a;
39 120 data_a_ = data_a;
40 120 rows_b_ = rows_b;
41 120 cols_b_ = cols_b;
42 120 data_b_ = data_b;
43
4/8
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 120 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 120 times.
✗ Branch 7 not taken.
120 if (rows_a == 0 || cols_a == 0 || rows_b == 0 || cols_b == 0) {
44 return false;
45 }
46
2/4
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✗ Branch 3 not taken.
120 if (data_a.size() != rows_a * cols_a || data_b.size() != rows_b * cols_b) {
47 return false;
48 }
49
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 if (cols_a != rows_b) {
50 return false;
51 }
52
3/6
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 120 times.
120 if (out_rows != 0 || out_cols != 0 || !out_data.empty()) {
53 return false;
54 }
55
56 return true;
57 }
58
59 120 bool OlesnitskiyVStripedMatrixMultiplicationSEQ::PreProcessingImpl() {
60 120 rows_c_ = rows_a_;
61 120 cols_c_ = cols_b_;
62 int max_stripes = 8;
63 120 num_stripes_ = FindCommonDivisor(static_cast<int>(rows_a_), static_cast<int>(cols_b_), max_stripes);
64
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 96 times.
120 if (num_stripes_ < 2) {
65 24 num_stripes_ = 1;
66 }
67 120 result_c_.resize(rows_c_ * cols_c_, 0.0);
68 120 GetOutput() = std::make_tuple(0, 0, std::vector<double>());
69 120 return true;
70 }
71
72 120 bool OlesnitskiyVStripedMatrixMultiplicationSEQ::RunImpl() {
73
2/4
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 120 times.
120 if (rows_a_ == 0 || cols_b_ == 0) {
74 GetOutput() = std::make_tuple(rows_c_, cols_c_, std::vector<double>());
75 return true;
76 }
77
78 120 result_c_.resize(rows_c_ * cols_c_, 0.0);
79
80 bool success = false;
81
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 96 times.
120 if (num_stripes_ == 1) {
82 24 success = MultiplySimple();
83 } else {
84 96 success = MultiplyStriped();
85 }
86
87
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if (success) {
88 120 GetOutput() = std::make_tuple(rows_c_, cols_c_, result_c_);
89 }
90
91 return success;
92 }
93
94 24 bool OlesnitskiyVStripedMatrixMultiplicationSEQ::MultiplySimple() {
95
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 24 times.
88 for (size_t i = 0; i < rows_a_; ++i) {
96
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 64 times.
216 for (size_t j = 0; j < cols_b_; ++j) {
97 double sum = 0.0;
98
2/2
✓ Branch 0 taken 776 times.
✓ Branch 1 taken 152 times.
928 for (size_t k = 0; k < cols_a_; ++k) {
99 776 sum += data_a_[(i * cols_a_) + k] * data_b_[(k * cols_b_) + j];
100 }
101 152 result_c_[(i * cols_b_) + j] = sum;
102 }
103 }
104 24 return true;
105 }
106
107 2288 bool OlesnitskiyVStripedMatrixMultiplicationSEQ::ProcessStripePair(int stripe_a, int stripe_b, size_t rows_per_stripe,
108 size_t cols_per_stripe) {
109 2288 const size_t start_row_a = static_cast<size_t>(stripe_a) * rows_per_stripe;
110 2288 const size_t start_col_b = static_cast<size_t>(stripe_b) * cols_per_stripe;
111
112
2/2
✓ Branch 0 taken 2920 times.
✓ Branch 1 taken 2288 times.
5208 for (size_t i = 0; i < rows_per_stripe; ++i) {
113 2920 const size_t row_idx = start_row_a + i;
114
2/2
✓ Branch 0 taken 4328 times.
✓ Branch 1 taken 2920 times.
7248 for (size_t j = 0; j < cols_per_stripe; ++j) {
115 4328 const size_t col_idx = start_col_b + j;
116 double sum = 0.0;
117
118
2/2
✓ Branch 0 taken 38328 times.
✓ Branch 1 taken 4328 times.
42656 for (size_t k = 0; k < cols_a_; ++k) {
119 38328 sum += data_a_[(row_idx * cols_a_) + k] * data_b_[(k * cols_b_) + col_idx];
120 }
121 4328 result_c_[(row_idx * cols_b_) + col_idx] = sum;
122 }
123 }
124 2288 return true;
125 }
126
127 96 bool OlesnitskiyVStripedMatrixMultiplicationSEQ::MultiplyStriped() {
128
2/4
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
96 if (rows_a_ % static_cast<size_t>(num_stripes_) != 0 || cols_b_ % static_cast<size_t>(num_stripes_) != 0) {
129 return false;
130 }
131
132 96 const size_t rows_per_stripe = rows_a_ / static_cast<size_t>(num_stripes_);
133 96 const size_t cols_per_stripe = cols_b_ / static_cast<size_t>(num_stripes_);
134
135
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 96 times.
528 for (int stripe_a = 0; stripe_a < num_stripes_; ++stripe_a) {
136
2/2
✓ Branch 0 taken 2288 times.
✓ Branch 1 taken 432 times.
2720 for (int stripe_b = 0; stripe_b < num_stripes_; ++stripe_b) {
137 2288 if (!ProcessStripePair(stripe_a, stripe_b, rows_per_stripe, cols_per_stripe)) {
138 return false;
139 }
140 }
141 }
142 return true;
143 }
144
145 120 bool OlesnitskiyVStripedMatrixMultiplicationSEQ::PostProcessingImpl() {
146 120 return true;
147 }
148 } // namespace olesnitskiy_v_striped_matrix_multiplication
149