| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "tsyplakov_k_mul_double_crs_matrix/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <omp.h> | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | #include <unordered_map> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "tsyplakov_k_mul_double_crs_matrix/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace tsyplakov_k_mul_double_crs_matrix { | ||
| 13 | |||
| 14 |
1/2✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 | TsyplakovKTestTaskOMP::TsyplakovKTestTaskOMP(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 | GetInput() = in; | ||
| 17 | 16 | } | |
| 18 | |||
| 19 | 16 | bool TsyplakovKTestTaskOMP::ValidationImpl() { | |
| 20 | const auto &input = GetInput(); | ||
| 21 | 16 | return input.a.cols == input.b.rows; | |
| 22 | } | ||
| 23 | |||
| 24 | 16 | bool TsyplakovKTestTaskOMP::PreProcessingImpl() { | |
| 25 | 16 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 | 16 | bool TsyplakovKTestTaskOMP::RunImpl() { | |
| 29 | const auto &input = GetInput(); | ||
| 30 | 16 | const auto &a = input.a; | |
| 31 | 16 | const auto &b = input.b; | |
| 32 | |||
| 33 | 16 | const int rows = a.rows; | |
| 34 | |||
| 35 | 16 | std::vector<std::vector<double>> row_values(rows); | |
| 36 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | std::vector<std::vector<int>> row_cols(rows); |
| 37 | |||
| 38 | 16 | #pragma omp parallel for schedule(dynamic) default(none) shared(a, b, row_values, row_cols, rows) | |
| 39 | for (int i = 0; i < rows; ++i) { | ||
| 40 | std::unordered_map<int, double> acc; | ||
| 41 | |||
| 42 | for (int j = a.row_ptr[i]; j < a.row_ptr[i + 1]; ++j) { | ||
| 43 | int k = a.col_index[j]; | ||
| 44 | double val_a = a.values[j]; | ||
| 45 | |||
| 46 | for (int zz = b.row_ptr[k]; zz < b.row_ptr[k + 1]; ++zz) { | ||
| 47 | int j1 = b.col_index[zz]; | ||
| 48 | acc[j1] += val_a * b.values[zz]; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | row_values[i].reserve(acc.size()); | ||
| 53 | row_cols[i].reserve(acc.size()); | ||
| 54 | |||
| 55 | for (const auto &[col, val] : acc) { | ||
| 56 | if (std::fabs(val) > 1e-12) { | ||
| 57 | row_cols[i].push_back(col); | ||
| 58 | row_values[i].push_back(val); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | SparseMatrixCRS c(a.rows, b.cols); |
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 16 times.
|
52 | for (int i = 0; i < c.rows; ++i) { |
| 66 | 36 | c.row_ptr[i + 1] = c.row_ptr[i] + static_cast<int>(row_values[i].size()); | |
| 67 | } | ||
| 68 | |||
| 69 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | const int nnz = c.row_ptr[c.rows]; |
| 70 | |||
| 71 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | c.values.reserve(nnz); |
| 72 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | c.col_index.reserve(nnz); |
| 73 | |||
| 74 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 16 times.
|
52 | for (int i = 0; i < c.rows; ++i) { |
| 75 |
2/4✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
|
36 | c.values.insert(c.values.end(), row_values[i].begin(), row_values[i].end()); |
| 76 | 36 | c.col_index.insert(c.col_index.end(), row_cols[i].begin(), row_cols[i].end()); | |
| 77 | } | ||
| 78 | |||
| 79 | 16 | GetOutput() = std::move(c); | |
| 80 | |||
| 81 | 16 | return true; | |
| 82 | 16 | } | |
| 83 | |||
| 84 | 16 | bool TsyplakovKTestTaskOMP::PostProcessingImpl() { | |
| 85 | 16 | return true; | |
| 86 | } | ||
| 87 | |||
| 88 | } // namespace tsyplakov_k_mul_double_crs_matrix | ||
| 89 |