| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "alekseev_a_mult_matrix_crs/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/tbb.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cmath> | ||
| 7 | #include <cstddef> | ||
| 8 | #include <utility> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "alekseev_a_mult_matrix_crs/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace alekseev_a_mult_matrix_crs { | ||
| 14 | |||
| 15 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | AlekseevAMultMatrixCRSTBB::AlekseevAMultMatrixCRSTBB(const InType &in) { |
| 16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 17 | GetInput() = in; | ||
| 18 | 24 | } | |
| 19 | |||
| 20 | 24 | bool AlekseevAMultMatrixCRSTBB::ValidationImpl() { | |
| 21 | const auto &a = std::get<0>(GetInput()); | ||
| 22 | const auto &b = std::get<1>(GetInput()); | ||
| 23 |
3/6✓ 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.
|
24 | return a.cols == b.rows && !a.row_ptr.empty() && !b.row_ptr.empty(); |
| 24 | } | ||
| 25 | |||
| 26 | 24 | bool AlekseevAMultMatrixCRSTBB::PreProcessingImpl() { | |
| 27 | 24 | GetOutput() = {}; | |
| 28 | 24 | return true; | |
| 29 | } | ||
| 30 | |||
| 31 | 48 | void AlekseevAMultMatrixCRSTBB::ProcessRow(std::size_t i, const CRSMatrix &a, const CRSMatrix &b, | |
| 32 | std::vector<double> &temp_v, std::vector<std::size_t> &temp_c, | ||
| 33 | std::vector<double> &accum, std::vector<int> &touched_flag, | ||
| 34 | std::vector<std::size_t> &touched_cols) { | ||
| 35 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 48 times.
|
100 | for (std::size_t pos_a = a.row_ptr[i]; pos_a < a.row_ptr[i + 1]; ++pos_a) { |
| 36 | 52 | std::size_t k = a.col_indices[pos_a]; | |
| 37 | 52 | double val_a = a.values[pos_a]; | |
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 52 times.
|
132 | for (std::size_t pos_b = b.row_ptr[k]; pos_b < b.row_ptr[k + 1]; ++pos_b) { |
| 40 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 60 times.
|
80 | std::size_t j = b.col_indices[pos_b]; |
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 60 times.
|
80 | if (std::cmp_not_equal(touched_flag[j], i)) { |
| 43 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
60 | touched_flag[j] = static_cast<int>(i); |
| 44 | touched_cols.push_back(j); | ||
| 45 | 60 | accum[j] = 0.0; | |
| 46 | } | ||
| 47 | 80 | accum[j] += val_a * b.values[pos_b]; | |
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | std::ranges::sort(touched_cols); | ||
| 52 | |||
| 53 |
3/4✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 48 times.
|
108 | for (auto col : touched_cols) { |
| 54 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
60 | if (std::abs(accum[col]) > 1e-15) { |
| 55 | temp_v.push_back(accum[col]); | ||
| 56 | temp_c.push_back(col); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | touched_cols.clear(); | ||
| 60 | 48 | } | |
| 61 | |||
| 62 | 24 | bool AlekseevAMultMatrixCRSTBB::RunImpl() { | |
| 63 | const auto &a = std::get<0>(GetInput()); | ||
| 64 | const auto &b = std::get<1>(GetInput()); | ||
| 65 | auto &c = GetOutput(); | ||
| 66 | |||
| 67 | 24 | c.rows = a.rows; | |
| 68 | 24 | c.cols = b.cols; | |
| 69 | 24 | c.row_ptr.assign(c.rows + 1, 0); | |
| 70 | |||
| 71 | 24 | std::vector<std::vector<double>> temp_values(c.rows); | |
| 72 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | std::vector<std::vector<std::size_t>> temp_cols(c.rows); |
| 73 | |||
| 74 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | tbb::parallel_for(tbb::blocked_range<std::size_t>(0, a.rows), [&](const tbb::blocked_range<std::size_t> &range) { |
| 75 | 48 | std::vector<double> accum(c.cols, 0.0); | |
| 76 |
1/4✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
48 | std::vector<int> touched_flag(c.cols, -1); |
| 77 | 48 | std::vector<std::size_t> touched_cols; | |
| 78 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | touched_cols.reserve(c.cols); |
| 79 | |||
| 80 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
|
96 | for (std::size_t i = range.begin(); i != range.end(); ++i) { |
| 81 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | ProcessRow(i, a, b, temp_values[i], temp_cols[i], accum, touched_flag, touched_cols); |
| 82 | } | ||
| 83 | 48 | }); | |
| 84 | |||
| 85 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
|
72 | for (std::size_t i = 0; i < c.rows; ++i) { |
| 86 | 48 | c.row_ptr[i + 1] = c.row_ptr[i] + temp_values[i].size(); | |
| 87 | } | ||
| 88 | |||
| 89 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | c.values.reserve(c.row_ptr[c.rows]); |
| 90 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | c.col_indices.reserve(c.row_ptr[c.rows]); |
| 91 | |||
| 92 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
|
72 | for (std::size_t i = 0; i < c.rows; ++i) { |
| 93 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | c.values.insert(c.values.end(), temp_values[i].begin(), temp_values[i].end()); |
| 94 | 48 | c.col_indices.insert(c.col_indices.end(), temp_cols[i].begin(), temp_cols[i].end()); | |
| 95 | } | ||
| 96 | |||
| 97 | 24 | return true; | |
| 98 | 24 | } | |
| 99 | |||
| 100 | 24 | bool AlekseevAMultMatrixCRSTBB::PostProcessingImpl() { | |
| 101 | 24 | return true; | |
| 102 | } | ||
| 103 | |||
| 104 | } // namespace alekseev_a_mult_matrix_crs | ||
| 105 |