| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "luzan_e_double_sparse_matrix_mult/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | // #include <tbb/parallel_for.h> | ||
| 9 | // #include <tbb/blocked_range.h> | ||
| 10 | #include <tbb/tbb.h> | ||
| 11 | |||
| 12 | #include "luzan_e_double_sparse_matrix_mult/common/include/common.hpp" | ||
| 13 | |||
| 14 | namespace luzan_e_double_sparse_matrix_mult { | ||
| 15 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | void LuzanEDoubleSparseMatrixMultTBB::MultiplyColumn(const SparseMatrix &a, const SparseMatrix &b, unsigned b_col, |
| 16 | std::vector<double> &tmp_col) { | ||
| 17 | std::ranges::fill(tmp_col, 0.0); | ||
| 18 | |||
| 19 | 64 | unsigned b_start = b.col_index[b_col]; | |
| 20 | 64 | unsigned b_end = b.col_index[b_col + 1]; | |
| 21 | |||
| 22 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 64 times.
|
144 | for (unsigned b_pos = b_start; b_pos < b_end; ++b_pos) { |
| 23 | 80 | double b_val = b.value[b_pos]; | |
| 24 | 80 | unsigned k = b.row[b_pos]; | |
| 25 | |||
| 26 |
2/2✓ Branch 0 taken 188 times.
✓ Branch 1 taken 80 times.
|
268 | for (unsigned a_pos = a.col_index[k]; a_pos < a.col_index[k + 1]; ++a_pos) { |
| 27 | 188 | tmp_col[a.row[a_pos]] += a.value[a_pos] * b_val; | |
| 28 | } | ||
| 29 | } | ||
| 30 | 64 | } | |
| 31 | |||
| 32 | 64 | void LuzanEDoubleSparseMatrixMultTBB::CompressColumn(const std::vector<double> &tmp_col, std::vector<double> &values, | |
| 33 | std::vector<unsigned> &rows) { | ||
| 34 |
2/2✓ Branch 0 taken 240 times.
✓ Branch 1 taken 64 times.
|
304 | for (unsigned i = 0; i < tmp_col.size(); ++i) { |
| 35 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 120 times.
|
240 | if (fabs(tmp_col[i]) > kEPS) { |
| 36 | values.push_back(tmp_col[i]); | ||
| 37 | rows.push_back(i); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | 64 | } | |
| 41 | |||
| 42 | 24 | SparseMatrix LuzanEDoubleSparseMatrixMultTBB::CalcProdTBB(const SparseMatrix &a, const SparseMatrix &b) { | |
| 43 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | SparseMatrix c(a.rows, b.cols); |
| 44 | |||
| 45 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | std::vector<std::vector<double>> values_per_col(b.cols); |
| 46 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | std::vector<std::vector<unsigned>> rows_per_col(b.cols); |
| 47 | |||
| 48 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
49 | tbb::enumerable_thread_specific<std::vector<double>> tls_tmp([&] { return std::vector<double>(a.rows, 0.0); }); |
| 49 | |||
| 50 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
88 | tbb::parallel_for(tbb::blocked_range<unsigned>(0, b.cols), [&](const tbb::blocked_range<unsigned> &range) { |
| 51 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 64 times.
|
128 | for (unsigned b_col = range.begin(); b_col < range.end(); ++b_col) { |
| 52 | 64 | auto &tmp_col = tls_tmp.local(); | |
| 53 | |||
| 54 | 64 | MultiplyColumn(a, b, b_col, tmp_col); | |
| 55 | 64 | CompressColumn(tmp_col, values_per_col[b_col], rows_per_col[b_col]); | |
| 56 | } | ||
| 57 | 64 | }); | |
| 58 | |||
| 59 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | BuildResult(c, values_per_col, rows_per_col); |
| 60 | |||
| 61 | 24 | return c; | |
| 62 | 24 | } | |
| 63 | |||
| 64 | 24 | void LuzanEDoubleSparseMatrixMultTBB::BuildResult(SparseMatrix &c, | |
| 65 | const std::vector<std::vector<double>> &values_per_col, | ||
| 66 | const std::vector<std::vector<unsigned>> &rows_per_col) { | ||
| 67 | 24 | c.col_index.push_back(0); | |
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 24 times.
|
88 | for (unsigned j = 0; j < values_per_col.size(); ++j) { |
| 70 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 64 times.
|
184 | for (size_t k = 0; k < values_per_col[j].size(); ++k) { |
| 71 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 68 times.
|
120 | c.value.push_back(values_per_col[j][k]); |
| 72 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 68 times.
|
120 | c.row.push_back(rows_per_col[j][k]); |
| 73 | } | ||
| 74 | 64 | c.col_index.push_back(c.value.size()); | |
| 75 | } | ||
| 76 | 24 | } | |
| 77 | |||
| 78 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | LuzanEDoubleSparseMatrixMultTBB::LuzanEDoubleSparseMatrixMultTBB(const InType &in) { |
| 79 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 80 | GetInput() = in; | ||
| 81 | // GetOutput() = 0; | ||
| 82 | 24 | } | |
| 83 | |||
| 84 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | bool LuzanEDoubleSparseMatrixMultTBB::ValidationImpl() { |
| 85 | const auto &a = std::get<0>(GetInput()); | ||
| 86 | const auto &b = std::get<1>(GetInput()); | ||
| 87 |
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 a.GetCols() == b.GetRows() && a.GetCols() != 0 && a.GetRows() != 0 && b.GetCols() != 0; |
| 88 | } | ||
| 89 | |||
| 90 | 24 | bool LuzanEDoubleSparseMatrixMultTBB::PreProcessingImpl() { | |
| 91 | 24 | return true; | |
| 92 | } | ||
| 93 | |||
| 94 | 24 | bool LuzanEDoubleSparseMatrixMultTBB::RunImpl() { | |
| 95 | const auto &a = std::get<0>(GetInput()); | ||
| 96 | const auto &b = std::get<1>(GetInput()); | ||
| 97 | |||
| 98 | 24 | GetOutput() = CalcProdTBB(a, b); | |
| 99 | 24 | return true; | |
| 100 | } | ||
| 101 | |||
| 102 | 24 | bool LuzanEDoubleSparseMatrixMultTBB::PostProcessingImpl() { | |
| 103 | 24 | return true; | |
| 104 | } | ||
| 105 | |||
| 106 | } // namespace luzan_e_double_sparse_matrix_mult | ||
| 107 |