| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "kulik_a_mat_mul_double_ccs/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <omp.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <limits> | ||
| 8 | #include <tuple> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "kulik_a_mat_mul_double_ccs/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace kulik_a_mat_mul_double_ccs { | ||
| 14 | |||
| 15 | namespace { | ||
| 16 | |||
| 17 | 24 | inline void MatMultPhase1(size_t j, const CCS &a, const CCS &b, std::vector<size_t> &was, | |
| 18 | std::vector<size_t> &col_nnz) { | ||
| 19 | size_t count = 0; | ||
| 20 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 24 times.
|
60 | for (size_t k = b.col_ind[j]; k < b.col_ind[j + 1]; ++k) { |
| 21 | 36 | const size_t b_row = b.row[k]; | |
| 22 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 36 times.
|
92 | for (size_t zc = a.col_ind[b_row]; zc < a.col_ind[b_row + 1]; ++zc) { |
| 23 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 8 times.
|
56 | const size_t a_row = a.row[zc]; |
| 24 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 8 times.
|
56 | if (was[a_row] != j) { |
| 25 | 48 | was[a_row] = j; | |
| 26 | 48 | ++count; | |
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | 24 | col_nnz[j] = count; | |
| 31 | 24 | } | |
| 32 | |||
| 33 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 10 times.
|
24 | inline void MatMultPhase2(size_t j, const CCS &a, const CCS &b, CCS &c, size_t stamp, std::vector<size_t> &was, |
| 34 | std::vector<double> &accum, std::vector<size_t> &rows) { | ||
| 35 | rows.clear(); | ||
| 36 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 24 times.
|
60 | for (size_t k = b.col_ind[j]; k < b.col_ind[j + 1]; ++k) { |
| 37 | 36 | const double b_val = b.value[k]; | |
| 38 | 36 | const size_t b_row = b.row[k]; | |
| 39 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 36 times.
|
92 | for (size_t zc = a.col_ind[b_row]; zc < a.col_ind[b_row + 1]; ++zc) { |
| 40 | 56 | const size_t a_row = a.row[zc]; | |
| 41 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 8 times.
|
56 | accum[a_row] += a.value[zc] * b_val; |
| 42 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 8 times.
|
56 | if (was[a_row] != stamp) { |
| 43 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 25 times.
|
48 | was[a_row] = stamp; |
| 44 | rows.push_back(a_row); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
| 48 | std::ranges::sort(rows); | ||
| 49 | 24 | size_t write = c.col_ind[j]; | |
| 50 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
|
72 | for (const size_t i : rows) { |
| 51 | 48 | c.row[write] = i; | |
| 52 | 48 | c.value[write] = accum[i]; | |
| 53 | 48 | accum[i] = 0.0; | |
| 54 | 48 | ++write; | |
| 55 | } | ||
| 56 | 24 | } | |
| 57 | |||
| 58 | } // namespace | ||
| 59 | |||
| 60 |
1/2✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | KulikAMatMulDoubleCcsOMP::KulikAMatMulDoubleCcsOMP(const InType &in) { |
| 61 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 62 | GetInput() = in; | ||
| 63 | 4 | } | |
| 64 | |||
| 65 | 4 | bool KulikAMatMulDoubleCcsOMP::ValidationImpl() { | |
| 66 | const auto &a = std::get<0>(GetInput()); | ||
| 67 | const auto &b = std::get<1>(GetInput()); | ||
| 68 | 4 | return (a.m == b.n); | |
| 69 | } | ||
| 70 | |||
| 71 | 4 | bool KulikAMatMulDoubleCcsOMP::PreProcessingImpl() { | |
| 72 | 4 | return true; | |
| 73 | } | ||
| 74 | |||
| 75 | 4 | bool KulikAMatMulDoubleCcsOMP::RunImpl() { | |
| 76 | const auto &a = std::get<0>(GetInput()); | ||
| 77 | const auto &b = std::get<1>(GetInput()); | ||
| 78 | OutType &c = GetOutput(); | ||
| 79 | 4 | c.n = a.n; | |
| 80 | 4 | c.m = b.m; | |
| 81 | 4 | c.col_ind.assign(c.m + 1, 0); | |
| 82 | |||
| 83 | 4 | std::vector<size_t> col_nnz(b.m, 0); | |
| 84 | |||
| 85 | 4 | #pragma omp parallel default(none) shared(a, b, col_nnz) | |
| 86 | { | ||
| 87 | std::vector<size_t> was(a.n, std::numeric_limits<size_t>::max()); | ||
| 88 | #pragma omp for schedule(static) | ||
| 89 | for (size_t j = 0; j < b.m; ++j) { | ||
| 90 | MatMultPhase1(j, a, b, was, col_nnz); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | size_t total_nz = 0; | ||
| 95 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 4 times.
|
28 | for (size_t j = 0; j < b.m; ++j) { |
| 96 | 24 | c.col_ind[j] = total_nz; | |
| 97 | 24 | total_nz += col_nnz[j]; | |
| 98 | } | ||
| 99 | 4 | c.col_ind[b.m] = total_nz; | |
| 100 | 4 | c.nz = total_nz; | |
| 101 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | c.value.resize(total_nz); |
| 102 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | c.row.resize(total_nz); |
| 103 | |||
| 104 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | #pragma omp parallel default(none) shared(a, b, c) |
| 105 | { | ||
| 106 | std::vector<size_t> was(a.n, std::numeric_limits<size_t>::max()); | ||
| 107 | std::vector<double> accum(a.n, 0.0); | ||
| 108 | std::vector<size_t> rows; | ||
| 109 | #pragma omp for schedule(static) | ||
| 110 | for (size_t j = 0; j < b.m; ++j) { | ||
| 111 | MatMultPhase2(j, a, b, c, b.m + j, was, accum, rows); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | 4 | return true; | |
| 116 | } | ||
| 117 | |||
| 118 | 4 | bool KulikAMatMulDoubleCcsOMP::PostProcessingImpl() { | |
| 119 | 4 | return true; | |
| 120 | } | ||
| 121 | |||
| 122 | } // namespace kulik_a_mat_mul_double_ccs | ||
| 123 |