| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ashihmin_d_mult_matr_crs/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/tbb.h> | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | #include <map> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "ashihmin_d_mult_matr_crs/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace ashihmin_d_mult_matr_crs { | ||
| 12 | |||
| 13 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | AshihminDMultMatrCrsTBB::AshihminDMultMatrCrsTBB(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 24 | } | |
| 17 | |||
| 18 | 24 | bool AshihminDMultMatrCrsTBB::ValidationImpl() { | |
| 19 | 24 | return GetInput().first.cols == GetInput().second.rows; | |
| 20 | } | ||
| 21 | |||
| 22 | 24 | bool AshihminDMultMatrCrsTBB::PreProcessingImpl() { | |
| 23 | auto &matrix_c = GetOutput(); | ||
| 24 | 24 | matrix_c.rows = GetInput().first.rows; | |
| 25 | 24 | matrix_c.cols = GetInput().second.cols; | |
| 26 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
|
24 | matrix_c.row_ptr.assign(matrix_c.rows + 1, 0); |
| 27 | matrix_c.values.clear(); | ||
| 28 | matrix_c.col_index.clear(); | ||
| 29 | 24 | return true; | |
| 30 | } | ||
| 31 | |||
| 32 | 24 | bool AshihminDMultMatrCrsTBB::RunImpl() { | |
| 33 | 24 | const auto &matrix_a = GetInput().first; | |
| 34 | 24 | const auto &matrix_b = GetInput().second; | |
| 35 | auto &matrix_c = GetOutput(); | ||
| 36 | 24 | int rows_a = matrix_a.rows; | |
| 37 | |||
| 38 | 24 | std::vector<std::vector<int>> local_cols(rows_a); | |
| 39 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | std::vector<std::vector<double>> local_vals(rows_a); |
| 40 | |||
| 41 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
72 | tbb::parallel_for(0, rows_a, [&](int i) { |
| 42 | std::map<int, double> row_accumulator; | ||
| 43 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 48 times.
|
100 | for (int j = matrix_a.row_ptr[i]; j < matrix_a.row_ptr[i + 1]; ++j) { |
| 44 | 52 | int col_a = matrix_a.col_index[j]; | |
| 45 | 52 | double val_a = matrix_a.values[j]; | |
| 46 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 52 times.
|
132 | for (int k = matrix_b.row_ptr[col_a]; k < matrix_b.row_ptr[col_a + 1]; ++k) { |
| 47 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | row_accumulator[matrix_b.col_index[k]] += val_a * matrix_b.values[k]; |
| 48 | } | ||
| 49 | } | ||
| 50 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 48 times.
|
108 | for (const auto &[col, val] : row_accumulator) { |
| 51 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
60 | if (std::abs(val) > 1e-15) { |
| 52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60 | local_cols[i].push_back(col); |
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60 | local_vals[i].push_back(val); |
| 54 | } | ||
| 55 | } | ||
| 56 | 48 | }); | |
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
|
72 | for (int i = 0; i < rows_a; ++i) { |
| 59 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | matrix_c.col_index.insert(matrix_c.col_index.end(), local_cols[i].begin(), local_cols[i].end()); |
| 60 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | matrix_c.values.insert(matrix_c.values.end(), local_vals[i].begin(), local_vals[i].end()); |
| 61 | 48 | matrix_c.row_ptr[i + 1] = static_cast<int>(matrix_c.values.size()); | |
| 62 | } | ||
| 63 | 24 | return true; | |
| 64 | 24 | } | |
| 65 | |||
| 66 | 24 | bool AshihminDMultMatrCrsTBB::PostProcessingImpl() { | |
| 67 | 24 | return true; | |
| 68 | } | ||
| 69 | |||
| 70 | } // namespace ashihmin_d_mult_matr_crs | ||
| 71 |