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