| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "../../omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <complex> | ||
| 4 | #include <utility> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "omp.h" | ||
| 8 | #include "shvetsova_k_mult_matrix_complex_col/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace shvetsova_k_mult_matrix_complex_col { | ||
| 11 | |||
| 12 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | ShvetsovaKMultMatrixComplexOMP::ShvetsovaKMultMatrixComplexOMP(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | GetOutput() = MatrixCCS(0, 0, std::vector<int>{0}, std::vector<int>{}, std::vector<std::complex<double>>{}); |
| 16 | 20 | } | |
| 17 | |||
| 18 | 20 | bool ShvetsovaKMultMatrixComplexOMP::ValidationImpl() { | |
| 19 | 20 | return true; | |
| 20 | } | ||
| 21 | |||
| 22 | 20 | bool ShvetsovaKMultMatrixComplexOMP::PreProcessingImpl() { | |
| 23 | const auto &matrix_a = std::get<0>(GetInput()); | ||
| 24 | const auto &matrix_b = std::get<1>(GetInput()); | ||
| 25 | |||
| 26 | auto &matrix_c = GetOutput(); | ||
| 27 | 20 | matrix_c.rows = matrix_a.rows; | |
| 28 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | matrix_c.cols = matrix_b.cols; |
| 29 | matrix_c.row_ind.clear(); | ||
| 30 | matrix_c.values.clear(); | ||
| 31 | matrix_c.col_ptr.clear(); | ||
| 32 | 20 | matrix_c.col_ptr.push_back(0); | |
| 33 | 20 | return true; | |
| 34 | } | ||
| 35 | |||
| 36 | 20 | bool ShvetsovaKMultMatrixComplexOMP::RunImpl() { | |
| 37 | const MatrixCCS &matrix_a = std::get<0>(GetInput()); | ||
| 38 | const MatrixCCS &matrix_b = std::get<1>(GetInput()); | ||
| 39 | struct SparseColumn { | ||
| 40 | std::vector<int> rows; | ||
| 41 | std::vector<std::complex<double>> vals; | ||
| 42 | }; | ||
| 43 | |||
| 44 | 20 | std::vector<SparseColumn> columns_c(matrix_b.cols); | |
| 45 | auto &matrix_c = GetOutput(); | ||
| 46 | |||
| 47 | 20 | #pragma omp parallel default(none) shared(matrix_a, matrix_b, columns_c) | |
| 48 | { | ||
| 49 | std::vector<std::complex<double>> column_c(matrix_a.rows, {0.0, 0.0}); | ||
| 50 | #pragma omp for | ||
| 51 | for (int i = 0; i < matrix_b.cols; i++) { | ||
| 52 | for (auto &val : column_c) { | ||
| 53 | val = {0.0, 0.0}; | ||
| 54 | } | ||
| 55 | for (int j = matrix_b.col_ptr[i]; j < matrix_b.col_ptr[i + 1]; j++) { | ||
| 56 | int tmp_ind = matrix_b.row_ind[j]; | ||
| 57 | std::complex tmp_val = matrix_b.values[j]; | ||
| 58 | for (int ind = matrix_a.col_ptr[tmp_ind]; ind < matrix_a.col_ptr[tmp_ind + 1]; ind++) { | ||
| 59 | int row = matrix_a.row_ind[ind]; | ||
| 60 | std::complex val_a = matrix_a.values[ind]; | ||
| 61 | column_c[row] += tmp_val * val_a; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | for (int index = 0; std::cmp_less(index, column_c.size()); ++index) { | ||
| 66 | if (column_c[index].real() != 0.0 || column_c[index].imag() != 0.0) { | ||
| 67 | columns_c[i].rows.push_back(index); | ||
| 68 | columns_c[i].vals.push_back(column_c[index]); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 20 times.
|
56 | for (int i = 0; i < matrix_b.cols; i++) { |
| 75 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
36 | matrix_c.row_ind.insert(matrix_c.row_ind.end(), columns_c[i].rows.begin(), columns_c[i].rows.end()); |
| 76 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
36 | matrix_c.values.insert(matrix_c.values.end(), columns_c[i].vals.begin(), columns_c[i].vals.end()); |
| 77 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
36 | matrix_c.col_ptr.push_back(static_cast<int>(matrix_c.row_ind.size())); |
| 78 | } | ||
| 79 | |||
| 80 | 20 | return true; | |
| 81 | 20 | } | |
| 82 | |||
| 83 | 20 | bool ShvetsovaKMultMatrixComplexOMP::PostProcessingImpl() { | |
| 84 | 20 | return true; | |
| 85 | } | ||
| 86 | |||
| 87 | } // namespace shvetsova_k_mult_matrix_complex_col | ||
| 88 |