| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "viderman_a_sparse_matrix_mult_crs_complex/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <functional> | ||
| 6 | #include <iterator> | ||
| 7 | #include <thread> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "util/include/util.hpp" | ||
| 11 | #include "viderman_a_sparse_matrix_mult_crs_complex/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace viderman_a_sparse_matrix_mult_crs_complex { | ||
| 14 | |||
| 15 |
1/2✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | VidermanASparseMatrixMultCRSComplexSTL::VidermanASparseMatrixMultCRSComplexSTL(const InType &in) { |
| 16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 17 | GetInput() = in; | ||
| 18 | 48 | GetOutput() = CRSMatrix(); | |
| 19 | 48 | } | |
| 20 | |||
| 21 | 68 | void VidermanASparseMatrixMultCRSComplexSTL::ProcessRows(int start_row, int end_row, | |
| 22 | std::vector<std::vector<Complex>> &local_values, | ||
| 23 | std::vector<std::vector<int>> &local_cols) const { | ||
| 24 | 68 | const int cols_b = b_->cols; | |
| 25 | 68 | std::vector<Complex> accumulator(cols_b, Complex(0.0, 0.0)); | |
| 26 |
1/4✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
68 | std::vector<int> marker(cols_b, -1); |
| 27 | |||
| 28 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 68 times.
|
148 | for (int i = start_row; i < end_row; ++i) { |
| 29 | 80 | std::vector<int> current_row_indices; | |
| 30 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 80 times.
|
136 | for (int j = a_->row_ptr[i]; j < a_->row_ptr[i + 1]; ++j) { |
| 31 | 56 | int col_a = a_->col_indices[j]; | |
| 32 | 56 | Complex val_a = a_->values[j]; | |
| 33 | |||
| 34 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 56 times.
|
112 | for (int k = b_->row_ptr[col_a]; k < b_->row_ptr[col_a + 1]; ++k) { |
| 35 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | int col_b = b_->col_indices[k]; |
| 36 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | accumulator[col_b] += val_a * b_->values[k]; |
| 37 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | if (marker[col_b] != i) { |
| 38 | current_row_indices.push_back(col_b); | ||
| 39 | 56 | marker[col_b] = i; | |
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | std::ranges::sort(current_row_indices); | ||
| 45 | |||
| 46 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 80 times.
|
136 | for (int idx : current_row_indices) { |
| 47 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | if (std::abs(accumulator[idx]) > kEpsilon) { |
| 48 | local_values[i].push_back(accumulator[idx]); | ||
| 49 | local_cols[i].push_back(idx); | ||
| 50 | } | ||
| 51 | 56 | accumulator[idx] = Complex(0.0, 0.0); | |
| 52 | } | ||
| 53 | } | ||
| 54 | 68 | } | |
| 55 | |||
| 56 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | bool VidermanASparseMatrixMultCRSComplexSTL::ValidationImpl() { |
| 57 | const auto &input = GetInput(); | ||
| 58 | const auto &a = std::get<0>(input); | ||
| 59 | const auto &b = std::get<1>(input); | ||
| 60 |
4/6✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 40 times.
|
48 | return a.IsValid() && b.IsValid() && (a.cols == b.rows); |
| 61 | } | ||
| 62 | |||
| 63 | 40 | bool VidermanASparseMatrixMultCRSComplexSTL::PreProcessingImpl() { | |
| 64 | const auto &input = GetInput(); | ||
| 65 | 40 | a_ = &std::get<0>(input); | |
| 66 | 40 | b_ = &std::get<1>(input); | |
| 67 | 40 | return true; | |
| 68 | } | ||
| 69 | |||
| 70 | 40 | bool VidermanASparseMatrixMultCRSComplexSTL::RunImpl() { | |
| 71 | 40 | const int rows_a = a_->rows; | |
| 72 | 40 | const int cols_b = b_->cols; | |
| 73 | 40 | const int num_threads = ppc::util::GetNumThreads(); | |
| 74 | |||
| 75 | 40 | std::vector<std::jthread> threads; | |
| 76 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | std::vector<std::vector<Complex>> local_values(rows_a); |
| 77 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | std::vector<std::vector<int>> local_cols(rows_a); |
| 78 | |||
| 79 | 40 | int chunk = rows_a / num_threads; | |
| 80 | 40 | int remainder = rows_a % num_threads; | |
| 81 | 40 | int current_start = 0; | |
| 82 | |||
| 83 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 40 times.
|
140 | for (int i = 0; i < num_threads; ++i) { |
| 84 |
2/2✓ Branch 0 taken 62 times.
✓ Branch 1 taken 38 times.
|
100 | int current_end = current_start + chunk + (i < remainder ? 1 : 0); |
| 85 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 32 times.
|
100 | if (current_start < current_end) { |
| 86 | 136 | threads.emplace_back(&VidermanASparseMatrixMultCRSComplexSTL::ProcessRows, this, current_start, current_end, | |
| 87 |
1/2✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
|
68 | std::ref(local_values), std::ref(local_cols)); |
| 88 | } | ||
| 89 | 100 | current_start = current_end; | |
| 90 | } | ||
| 91 | |||
| 92 | threads.clear(); | ||
| 93 | |||
| 94 | CRSMatrix &c = GetOutput(); | ||
| 95 | 40 | c.rows = rows_a; | |
| 96 | 40 | c.cols = cols_b; | |
| 97 |
2/4✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 40 times.
|
40 | c.row_ptr.assign(rows_a + 1, 0); |
| 98 | |||
| 99 | c.values.clear(); | ||
| 100 | c.col_indices.clear(); | ||
| 101 | |||
| 102 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 40 times.
|
120 | for (int i = 0; i < rows_a; ++i) { |
| 103 | 80 | c.row_ptr[i + 1] = c.row_ptr[i] + static_cast<int>(local_values[i].size()); | |
| 104 | 80 | std::move(local_values[i].begin(), local_values[i].end(), std::back_inserter(c.values)); | |
| 105 | 80 | std::move(local_cols[i].begin(), local_cols[i].end(), std::back_inserter(c.col_indices)); | |
| 106 | } | ||
| 107 | |||
| 108 | 40 | return true; | |
| 109 | 40 | } | |
| 110 | |||
| 111 | 40 | bool VidermanASparseMatrixMultCRSComplexSTL::PostProcessingImpl() { | |
| 112 | 40 | return GetOutput().IsValid(); | |
| 113 | } | ||
| 114 | |||
| 115 | } // namespace viderman_a_sparse_matrix_mult_crs_complex | ||
| 116 |