| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "goriacheva_k_mult_sparse_complex_matrix_ccs/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <ranges> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "goriacheva_k_mult_sparse_complex_matrix_ccs/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace goriacheva_k_mult_sparse_complex_matrix_ccs { | ||
| 10 | |||
| 11 |
1/2✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
|
56 | GoriachevaKMultSparseComplexMatrixCcsOMP::GoriachevaKMultSparseComplexMatrixCcsOMP(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 | GetInput() = in; | ||
| 14 | 56 | } | |
| 15 | |||
| 16 | 56 | bool GoriachevaKMultSparseComplexMatrixCcsOMP::ValidationImpl() { | |
| 17 | auto &[a, b] = GetInput(); | ||
| 18 | |||
| 19 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | if (a.cols != b.rows) { |
| 20 | return false; | ||
| 21 | } | ||
| 22 | |||
| 23 |
2/4✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
|
56 | if (a.col_ptr.empty() || b.col_ptr.empty()) { |
| 24 | ✗ | return false; | |
| 25 | } | ||
| 26 | |||
| 27 | return true; | ||
| 28 | } | ||
| 29 | |||
| 30 | 56 | bool GoriachevaKMultSparseComplexMatrixCcsOMP::PreProcessingImpl() { | |
| 31 | 56 | GetOutput() = {}; | |
| 32 | 56 | return true; | |
| 33 | } | ||
| 34 | |||
| 35 | namespace { | ||
| 36 | 164 | void ProcessColumn(int j, const SparseMatrixCCS &a, const SparseMatrixCCS &b, std::vector<Complex> &values, | |
| 37 | std::vector<int> &rows) { | ||
| 38 | 164 | std::vector<Complex> accumulator(a.rows); | |
| 39 |
1/4✓ Branch 1 taken 164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
164 | std::vector<int> marker(a.rows, -1); |
| 40 | 164 | std::vector<int> used_rows; | |
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 164 times.
|
276 | for (int bi = b.col_ptr[j]; bi < b.col_ptr[j + 1]; bi++) { |
| 43 | 112 | int k = b.row_ind[bi]; | |
| 44 | 112 | Complex b_val = b.values[bi]; | |
| 45 | |||
| 46 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 112 times.
|
220 | for (int ai = a.col_ptr[k]; ai < a.col_ptr[k + 1]; ai++) { |
| 47 |
1/2✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
|
108 | int i = a.row_ind[ai]; |
| 48 | |||
| 49 |
1/2✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
|
108 | if (marker[i] != j) { |
| 50 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
|
108 | marker[i] = j; |
| 51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
|
108 | accumulator[i] = Complex(0.0, 0.0); |
| 52 | used_rows.push_back(i); | ||
| 53 | } | ||
| 54 | |||
| 55 | accumulator[i] += a.values[ai] * b_val; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | std::ranges::sort(used_rows); | ||
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 164 times.
|
272 | for (int r : used_rows) { |
| 62 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 96 times.
|
108 | if (accumulator[r] != Complex(0.0, 0.0)) { |
| 63 | rows.push_back(r); | ||
| 64 | values.push_back(accumulator[r]); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | 164 | } | |
| 68 | } // namespace | ||
| 69 | |||
| 70 | 56 | bool GoriachevaKMultSparseComplexMatrixCcsOMP::RunImpl() { | |
| 71 | auto &a = std::get<0>(GetInput()); | ||
| 72 | auto &b = std::get<1>(GetInput()); | ||
| 73 | auto &c = GetOutput(); | ||
| 74 | |||
| 75 | 56 | c.rows = a.rows; | |
| 76 | 56 | c.cols = b.cols; | |
| 77 | 56 | c.col_ptr.resize(c.cols + 1); | |
| 78 | |||
| 79 | 56 | std::vector<std::vector<Complex>> local_values(c.cols); | |
| 80 |
1/2✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
|
56 | std::vector<std::vector<int>> local_rows(c.cols); |
| 81 | |||
| 82 | 56 | #pragma omp parallel for default(none) shared(a, b, local_values, local_rows) | |
| 83 | for (int j = 0; j < b.cols; j++) { | ||
| 84 | ProcessColumn(j, a, b, local_values[j], local_rows[j]); | ||
| 85 | } | ||
| 86 | |||
| 87 | int nnz = 0; | ||
| 88 |
2/2✓ Branch 0 taken 164 times.
✓ Branch 1 taken 56 times.
|
220 | for (int j = 0; j < c.cols; j++) { |
| 89 | 164 | c.col_ptr[j] = nnz; | |
| 90 | 164 | nnz += static_cast<int>(local_values[j].size()); | |
| 91 | } | ||
| 92 |
1/2✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
|
56 | c.col_ptr[c.cols] = nnz; |
| 93 | |||
| 94 |
1/2✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
|
56 | c.values.reserve(nnz); |
| 95 |
1/2✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
|
56 | c.row_ind.reserve(nnz); |
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 164 times.
✓ Branch 1 taken 56 times.
|
220 | for (int j = 0; j < c.cols; j++) { |
| 98 |
2/4✓ Branch 1 taken 164 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 164 times.
✗ Branch 5 not taken.
|
164 | c.values.insert(c.values.end(), local_values[j].begin(), local_values[j].end()); |
| 99 | 164 | c.row_ind.insert(c.row_ind.end(), local_rows[j].begin(), local_rows[j].end()); | |
| 100 | } | ||
| 101 | |||
| 102 | 56 | return true; | |
| 103 | 56 | } | |
| 104 | |||
| 105 | 56 | bool GoriachevaKMultSparseComplexMatrixCcsOMP::PostProcessingImpl() { | |
| 106 | 56 | return true; | |
| 107 | } | ||
| 108 | |||
| 109 | } // namespace goriacheva_k_mult_sparse_complex_matrix_ccs | ||
| 110 |