| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "romanova_v_min_by_matrix_rows_processes/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "romanova_v_min_by_matrix_rows_processes/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace romanova_v_min_by_matrix_rows_processes { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | RomanovaVMinByMatrixRowsMPI::RomanovaVMinByMatrixRowsMPI(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | GetInput() = in; |
| 16 |
1/4✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
12 | GetOutput() = OutType(in.size()); |
| 17 | 12 | } | |
| 18 | |||
| 19 | 12 | bool RomanovaVMinByMatrixRowsMPI::ValidationImpl() { | |
| 20 | 12 | bool status = false; | |
| 21 | 12 | int rank = 0; | |
| 22 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 23 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank == 0) { |
| 24 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | status = !GetInput().empty() && !GetInput()[0].empty(); |
| 25 | } | ||
| 26 | 12 | MPI_Bcast(&status, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD); | |
| 27 | 12 | return status; | |
| 28 | } | ||
| 29 | |||
| 30 | 12 | bool RomanovaVMinByMatrixRowsMPI::PreProcessingImpl() { | |
| 31 | 12 | in_data_ = GetInput(); | |
| 32 | 12 | return true; | |
| 33 | } | ||
| 34 | |||
| 35 | 12 | bool RomanovaVMinByMatrixRowsMPI::RunImpl() { | |
| 36 | 12 | int n = 0; | |
| 37 | 12 | int rank = 0; | |
| 38 | 12 | int delta = 0; | |
| 39 | 12 | int extra = 0; | |
| 40 | |||
| 41 | 12 | MPI_Comm_size(MPI_COMM_WORLD, &n); | |
| 42 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 43 | |||
| 44 | 12 | std::vector<int> recv_counts(n); | |
| 45 |
1/4✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
12 | std::vector<int> send_counts(n); |
| 46 | |||
| 47 |
1/4✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
12 | std::vector<int> displs_scatt(n); |
| 48 |
1/4✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
12 | std::vector<int> displs_gath(n); |
| 49 | |||
| 50 | 12 | OutType flat_data; | |
| 51 | |||
| 52 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank == 0) { |
| 53 | 6 | n_ = in_data_.size(); | |
| 54 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | m_ = ((!in_data_.empty()) ? in_data_[0].size() : 0); |
| 55 | |||
| 56 | 6 | delta = static_cast<int>(n_ / n); | |
| 57 | 6 | extra = static_cast<int>(n_ % n); | |
| 58 | |||
| 59 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | recv_counts = std::vector<int>(n, delta); |
| 60 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | recv_counts[n - 1] += extra; |
| 61 | |||
| 62 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | send_counts = std::vector<int>(n, static_cast<int>(delta * m_)); |
| 63 | 6 | send_counts[n - 1] += static_cast<int>(extra * m_); | |
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | for (int i = 1; i < n; i++) { |
| 66 | 6 | displs_gath[i] = displs_gath[i - 1] + delta; | |
| 67 | 6 | displs_scatt[i] = displs_scatt[i - 1] + static_cast<int>(delta * m_); | |
| 68 | } | ||
| 69 | |||
| 70 |
2/2✓ Branch 0 taken 361 times.
✓ Branch 1 taken 6 times.
|
367 | for (const auto &vec : in_data_) { |
| 71 | 361 | flat_data.insert(flat_data.end(), vec.begin(), vec.end()); | |
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | MPI_Bcast(&n_, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 76 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | MPI_Bcast(&m_, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 77 | |||
| 78 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | MPI_Bcast(&delta, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 79 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | MPI_Bcast(&extra, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 80 | |||
| 81 |
5/8✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
12 | OutType local_data((delta + (rank == n - 1 ? extra : 0)) * m_); |
| 82 | |||
| 83 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
|
18 | MPI_Scatterv(rank == 0 ? flat_data.data() : nullptr, send_counts.data(), displs_scatt.data(), MPI_INT, |
| 84 | local_data.data(), static_cast<int>(local_data.size()), MPI_INT, 0, MPI_COMM_WORLD); | ||
| 85 | |||
| 86 |
3/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
12 | OutType temp(delta + (rank == n - 1 ? extra : 0)); |
| 87 | |||
| 88 |
2/2✓ Branch 0 taken 361 times.
✓ Branch 1 taken 12 times.
|
373 | for (size_t i = 0; i < temp.size(); i++) { |
| 89 | 361 | temp[i] = local_data[i * m_]; | |
| 90 |
2/2✓ Branch 0 taken 32240 times.
✓ Branch 1 taken 361 times.
|
32601 | for (size_t j = 1; j < m_; j++) { |
| 91 |
2/2✓ Branch 0 taken 9918 times.
✓ Branch 1 taken 22322 times.
|
42158 | temp[i] = std::min(temp[i], local_data[(i * m_) + j]); |
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 |
2/6✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
24 | res_ = OutType(n_); |
| 96 | |||
| 97 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | MPI_Gatherv(temp.data(), static_cast<int>(temp.size()), MPI_INT, res_.data(), recv_counts.data(), displs_gath.data(), |
| 98 | MPI_INT, 0, MPI_COMM_WORLD); | ||
| 99 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | MPI_Bcast(res_.data(), static_cast<int>(n_), MPI_INT, 0, MPI_COMM_WORLD); |
| 100 | |||
| 101 | 12 | return true; | |
| 102 | } | ||
| 103 | |||
| 104 | 12 | bool RomanovaVMinByMatrixRowsMPI::PostProcessingImpl() { | |
| 105 | 12 | GetOutput() = res_; | |
| 106 | 12 | return true; | |
| 107 | } | ||
| 108 | |||
| 109 | } // namespace romanova_v_min_by_matrix_rows_processes | ||
| 110 |