GCC Code Coverage Report


Directory: ./
File: tasks/safronov_m_multiplication_matrix_blockscheme_cannon/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 42 47 89.4%
Functions: 7 10 70.0%
Branches: 32 54 59.3%

Line Branch Exec Source
1 #include "safronov_m_multiplication_matrix_blockscheme_cannon/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <utility>
6 #include <vector>
7
8 #include "safronov_m_multiplication_matrix_blockscheme_cannon/common/include/common.hpp"
9
10 namespace safronov_m_multiplication_matrix_blocksscheme_cannon {
11
12
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
32 SafronovMMultiplicationMatrixBlockSchemeCannonOMP::SafronovMMultiplicationMatrixBlockSchemeCannonOMP(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 32 }
16
17 32 bool SafronovMMultiplicationMatrixBlockSchemeCannonOMP::ValidationImpl() {
18 const auto &in = GetInput();
19 32 int size_block = std::get<0>(in);
20 const auto &matrix_a = std::get<1>(in);
21 const auto &matrix_b = std::get<2>(in);
22
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 32 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 32 times.
32 return (size_block > 0) && (!matrix_a.empty() && !matrix_b.empty()) && (matrix_a.size() == matrix_a[0].size()) &&
23
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
64 (matrix_b.size() == matrix_b[0].size()) && (matrix_a.size() == matrix_b.size()) &&
24
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 (matrix_a.size() % size_block == 0);
25 }
26
27
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 bool SafronovMMultiplicationMatrixBlockSchemeCannonOMP::PreProcessingImpl() {
28 GetOutput().clear();
29 32 return true;
30 }
31
32 304 void SafronovMMultiplicationMatrixBlockSchemeCannonOMP::MultiplyingBlocks(std::vector<std::vector<double>> &block_a,
33 std::vector<std::vector<double>> &block_b,
34 std::vector<std::vector<double>> &block_c,
35 int size_block) {
36
2/2
✓ Branch 0 taken 784 times.
✓ Branch 1 taken 304 times.
1088 for (int i = 0; i < size_block; i++) {
37
2/2
✓ Branch 0 taken 2224 times.
✓ Branch 1 taken 784 times.
3008 for (int j = 0; j < size_block; j++) {
38
2/2
✓ Branch 0 taken 6736 times.
✓ Branch 1 taken 2224 times.
8960 for (int k = 0; k < size_block; k++) {
39 6736 block_c[i][j] += block_a[i][k] * block_b[k][j];
40 }
41 }
42 }
43 304 }
44
45 void SafronovMMultiplicationMatrixBlockSchemeCannonOMP::ShiftingBlocksMatrixALeft(
46 std::vector<std::vector<std::vector<std::vector<double>>>> &matrix_blocks_a, int columns) {
47 32 #pragma omp parallel for default(none) shared(matrix_blocks_a, columns)
48 for (int i = 0; i < columns; i++) {
49 std::vector<std::vector<double>> tmp = std::move(matrix_blocks_a[i][0]);
50 for (int j = 1; j < columns; j++) {
51 matrix_blocks_a[i][j - 1] = std::move(matrix_blocks_a[i][j]);
52 }
53 matrix_blocks_a[i][columns - 1] = std::move(tmp);
54 }
55 }
56
57 void SafronovMMultiplicationMatrixBlockSchemeCannonOMP::ShiftingBlocksMatrixBUp(
58 std::vector<std::vector<std::vector<std::vector<double>>>> &matrix_blocks_b, int columns) {
59 32 #pragma omp parallel for default(none) shared(matrix_blocks_b, columns)
60 for (int i = 0; i < columns; i++) {
61 std::vector<std::vector<double>> tmp = std::move(matrix_blocks_b[0][i]);
62 for (int j = 1; j < columns; j++) {
63 matrix_blocks_b[j - 1][i] = std::move(matrix_blocks_b[j][i]);
64 }
65 matrix_blocks_b[columns - 1][i] = std::move(tmp);
66 }
67 32 }
68
69 32 void SafronovMMultiplicationMatrixBlockSchemeCannonOMP::AlgorithmCannon(
70 std::vector<std::vector<std::vector<std::vector<double>>>> &matrix_blocks_a,
71 std::vector<std::vector<std::vector<std::vector<double>>>> &matrix_blocks_b,
72 std::vector<std::vector<std::vector<std::vector<double>>>> &matrix_blocks_c, int size_block, int columns_blocks) {
73
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
96 for (int i = 0; i < columns_blocks; i++) {
74 64 #pragma omp parallel for collapse(2) default(none) \
75 shared(matrix_blocks_a, matrix_blocks_b, matrix_blocks_c, size_block, columns_blocks)
76 for (int j = 0; j < columns_blocks; j++) {
77 for (int k = 0; k < columns_blocks; k++) {
78 SafronovMMultiplicationMatrixBlockSchemeCannonOMP::MultiplyingBlocks(
79 matrix_blocks_a[j][k], matrix_blocks_b[j][k], matrix_blocks_c[j][k], size_block);
80 }
81 }
82
83
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 32 times.
64 if (i < columns_blocks - 1) {
84 SafronovMMultiplicationMatrixBlockSchemeCannonOMP::ShiftingBlocksMatrixALeft(matrix_blocks_a, columns_blocks);
85 SafronovMMultiplicationMatrixBlockSchemeCannonOMP::ShiftingBlocksMatrixBUp(matrix_blocks_b, columns_blocks);
86 }
87 }
88 32 }
89
90 void SafronovMMultiplicationMatrixBlockSchemeCannonOMP::FillingResultingMatrix(
91 std::vector<std::vector<std::vector<std::vector<double>>>> &matrix_blocks_c,
92 std::vector<std::vector<double>> &matrix_c, int size_block, int columns_blocks) {
93 32 #pragma omp parallel for collapse(2) default(none) shared(matrix_blocks_c, matrix_c, size_block, columns_blocks)
94 for (int i = 0; i < columns_blocks; i++) {
95 for (int j = 0; j < columns_blocks; j++) {
96 for (int k = 0; k < size_block; k++) {
97 for (int col = 0; col < size_block; col++) {
98 matrix_c[(i * size_block) + k][(j * size_block) + col] = matrix_blocks_c[i][j][k][col];
99 }
100 }
101 }
102 }
103 }
104
105 32 bool SafronovMMultiplicationMatrixBlockSchemeCannonOMP::RunImpl() {
106 const auto &in = GetInput();
107 32 int size_block = std::get<0>(in);
108 const auto &matrix_a = std::get<1>(in);
109 const auto &matrix_b = std::get<2>(in);
110 32 int n = static_cast<int>(matrix_a.size());
111 32 int columns_blocks = n / size_block;
112 std::vector<std::vector<std::vector<std::vector<double>>>> matrix_blocks_a(
113 columns_blocks,
114 32 std::vector<std::vector<std::vector<double>>>(
115
3/6
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 32 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 32 times.
✗ Branch 9 not taken.
64 columns_blocks, std::vector<std::vector<double>>(size_block, std::vector<double>(size_block))));
116 std::vector<std::vector<std::vector<std::vector<double>>>> matrix_blocks_b(
117 columns_blocks,
118 32 std::vector<std::vector<std::vector<double>>>(
119
4/8
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 32 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 32 times.
✗ Branch 11 not taken.
64 columns_blocks, std::vector<std::vector<double>>(size_block, std::vector<double>(size_block))));
120 std::vector<std::vector<std::vector<std::vector<double>>>> matrix_blocks_c(
121 columns_blocks,
122 32 std::vector<std::vector<std::vector<double>>>(
123
4/8
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 32 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 32 times.
✗ Branch 11 not taken.
64 columns_blocks, std::vector<std::vector<double>>(size_block, std::vector<double>(size_block, 0.0))));
124
125 32 #pragma omp parallel for collapse(2) default(none) \
126 shared(matrix_blocks_a, matrix_blocks_b, matrix_a, matrix_b, size_block, columns_blocks)
127 for (int i = 0; i < columns_blocks; i++) {
128 for (int j = 0; j < columns_blocks; j++) {
129 int shift = (i + j) % columns_blocks;
130 for (int k = 0; k < size_block; k++) {
131 for (int col = 0; col < size_block; col++) {
132 matrix_blocks_a[i][j][k][col] = matrix_a[(i * size_block) + k][(shift * size_block) + col];
133 matrix_blocks_b[i][j][k][col] = matrix_b[(shift * size_block) + k][(j * size_block) + col];
134 }
135 }
136 }
137 }
138 32 SafronovMMultiplicationMatrixBlockSchemeCannonOMP::AlgorithmCannon(matrix_blocks_a, matrix_blocks_b, matrix_blocks_c,
139 size_block, columns_blocks);
140
141
2/4
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
64 std::vector<std::vector<double>> matrix_c(n, std::vector<double>(n));
142 SafronovMMultiplicationMatrixBlockSchemeCannonOMP::FillingResultingMatrix(matrix_blocks_c, matrix_c, size_block,
143 columns_blocks);
144 32 GetOutput() = std::move(matrix_c);
145 32 return true;
146 32 }
147
148 32 bool SafronovMMultiplicationMatrixBlockSchemeCannonOMP::PostProcessingImpl() {
149 32 return true;
150 }
151
152 } // namespace safronov_m_multiplication_matrix_blocksscheme_cannon
153