| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "../include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <complex> | ||
| 5 | #include <thread> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "../../common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace shvetsova_k_mult_matrix_complex_col { | ||
| 12 | |||
| 13 | struct SparseColumn { | ||
| 14 | std::vector<int> rows; | ||
| 15 | std::vector<std::complex<double>> vals; | ||
| 16 | }; | ||
| 17 | |||
| 18 | namespace { | ||
| 19 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | void ComputeColumnTask(int col_idx, const MatrixCCS &matrix_a, const MatrixCCS &matrix_b, |
| 20 | std::vector<std::complex<double>> &column_c_local, SparseColumn &out_col) { | ||
| 21 | std::ranges::fill(column_c_local, std::complex<double>{0.0, 0.0}); | ||
| 22 | |||
| 23 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 72 times.
|
152 | for (int j = matrix_b.col_ptr[col_idx]; j < matrix_b.col_ptr[col_idx + 1]; j++) { |
| 24 | 80 | int tmp_ind = matrix_b.row_ind[j]; | |
| 25 | 80 | std::complex<double> tmp_val = matrix_b.values[j]; | |
| 26 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 80 times.
|
160 | for (int ind = matrix_a.col_ptr[tmp_ind]; ind < matrix_a.col_ptr[tmp_ind + 1]; ind++) { |
| 27 | 80 | int row = matrix_a.row_ind[ind]; | |
| 28 | 80 | std::complex<double> val_a = matrix_a.values[ind]; | |
| 29 | 80 | column_c_local[row] += tmp_val * val_a; | |
| 30 | } | ||
| 31 | } | ||
| 32 |
1/2✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
|
208 | for (int index = 0; std::cmp_less(index, column_c_local.size()); ++index) { |
| 33 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 72 times.
|
136 | if (column_c_local[index].real() != 0.0 || column_c_local[index].imag() != 0.0) { |
| 34 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | out_col.rows.push_back(index); |
| 35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | out_col.vals.push_back(column_c_local[index]); |
| 36 | } | ||
| 37 | } | ||
| 38 | 72 | } | |
| 39 | } // namespace | ||
| 40 | |||
| 41 |
1/2✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
40 | ShvetsovaKMultMatrixComplexSTL::ShvetsovaKMultMatrixComplexSTL(const InType &in) { |
| 42 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 43 | GetInput() = in; | ||
| 44 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetOutput() = MatrixCCS(0, 0, std::vector<int>{0}, std::vector<int>{}, std::vector<std::complex<double>>{}); |
| 45 | 40 | } | |
| 46 | |||
| 47 | 40 | bool ShvetsovaKMultMatrixComplexSTL::ValidationImpl() { | |
| 48 | 40 | return true; | |
| 49 | } | ||
| 50 | |||
| 51 | 40 | bool ShvetsovaKMultMatrixComplexSTL::PreProcessingImpl() { | |
| 52 | const auto &matrix_a = std::get<0>(GetInput()); | ||
| 53 | const auto &matrix_b = std::get<1>(GetInput()); | ||
| 54 | |||
| 55 | auto &matrix_c = GetOutput(); | ||
| 56 | 40 | matrix_c.rows = matrix_a.rows; | |
| 57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | matrix_c.cols = matrix_b.cols; |
| 58 | matrix_c.row_ind.clear(); | ||
| 59 | matrix_c.values.clear(); | ||
| 60 | matrix_c.col_ptr.clear(); | ||
| 61 | 40 | matrix_c.col_ptr.push_back(0); | |
| 62 | 40 | return true; | |
| 63 | } | ||
| 64 | |||
| 65 | 40 | bool ShvetsovaKMultMatrixComplexSTL::RunImpl() { | |
| 66 | const MatrixCCS &matrix_a = std::get<0>(GetInput()); | ||
| 67 | const MatrixCCS &matrix_b = std::get<1>(GetInput()); | ||
| 68 | |||
| 69 | auto &matrix_c = GetOutput(); | ||
| 70 | |||
| 71 | 40 | std::vector<SparseColumn> columns_c(matrix_b.cols); | |
| 72 | |||
| 73 | 40 | int num_threads = static_cast<int>(std::thread::hardware_concurrency()); | |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (num_threads <= 0) { |
| 75 | num_threads = 4; | ||
| 76 | } | ||
| 77 | |||
| 78 | 40 | std::vector<std::thread> threads; | |
| 79 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | threads.reserve(num_threads); |
| 80 | |||
| 81 | 40 | int cols_per_thread = matrix_b.cols / num_threads; | |
| 82 | 40 | int remainder = matrix_b.cols % num_threads; | |
| 83 | |||
| 84 | int current_start = 0; | ||
| 85 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 40 times.
|
200 | for (int thread_idx = 0; thread_idx < num_threads; ++thread_idx) { |
| 86 | int start_col = current_start; | ||
| 87 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 72 times.
|
160 | int end_col = start_col + cols_per_thread + (thread_idx < remainder ? 1 : 0); |
| 88 | current_start = end_col; | ||
| 89 | |||
| 90 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 88 times.
|
160 | if (start_col < end_col) { |
| 91 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | threads.emplace_back([&, start_col, end_col]() { |
| 92 | 72 | std::vector<std::complex<double>> column_c_local(matrix_a.rows, {0.0, 0.0}); | |
| 93 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
|
144 | for (int i = start_col; i < end_col; ++i) { |
| 94 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | ComputeColumnTask(i, matrix_a, matrix_b, column_c_local, columns_c[i]); |
| 95 | } | ||
| 96 | 72 | }); | |
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 40 times.
|
112 | for (auto &th : threads) { |
| 101 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | if (th.joinable()) { |
| 102 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | th.join(); |
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 40 times.
|
112 | for (int i = 0; i < matrix_b.cols; i++) { |
| 107 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | matrix_c.row_ind.insert(matrix_c.row_ind.end(), columns_c[i].rows.begin(), columns_c[i].rows.end()); |
| 108 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | matrix_c.values.insert(matrix_c.values.end(), columns_c[i].vals.begin(), columns_c[i].vals.end()); |
| 109 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | matrix_c.col_ptr.push_back(static_cast<int>(matrix_c.row_ind.size())); |
| 110 | } | ||
| 111 | |||
| 112 | 40 | return true; | |
| 113 | 40 | } | |
| 114 | |||
| 115 | 40 | bool ShvetsovaKMultMatrixComplexSTL::PostProcessingImpl() { | |
| 116 | 40 | return true; | |
| 117 | } | ||
| 118 | |||
| 119 | } // namespace shvetsova_k_mult_matrix_complex_col | ||
| 120 |