| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ermakov_a_ring/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <cstddef> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "ermakov_a_ring/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace ermakov_a_ring { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
26 | ErmakovATestTaskMPI::ErmakovATestTaskMPI(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | 26 | } | |
| 16 | |||
| 17 | 26 | bool ErmakovATestTaskMPI::ValidationImpl() { | |
| 18 | 26 | int size = 0; | |
| 19 | 26 | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 20 | 26 | return size > 0; | |
| 21 | } | ||
| 22 | |||
| 23 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | bool ErmakovATestTaskMPI::PreProcessingImpl() { |
| 24 | GetOutput().clear(); | ||
| 25 | 26 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 | 26 | bool ErmakovATestTaskMPI::RunImpl() { | |
| 29 | 26 | int rank = 0; | |
| 30 | 26 | int size = 0; | |
| 31 | 26 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 32 | 26 | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 33 | |||
| 34 | const auto &input = GetInput(); | ||
| 35 | 26 | std::vector<int> payload = input.data; | |
| 36 | 26 | const int src = ((input.source % size) + size) % size; | |
| 37 | 26 | const int dst = ((input.dest % size) + size) % size; | |
| 38 | |||
| 39 | 26 | const int cw_dist = (dst - src + size) % size; | |
| 40 | 26 | const int cc_dist = (src - dst + size) % size; | |
| 41 | |||
| 42 | bool clockwise = (cw_dist <= cc_dist); | ||
| 43 | int steps = cc_dist; | ||
| 44 | 26 | int next = (rank - 1 + size) % size; | |
| 45 | 26 | int prev = (rank + 1) % size; | |
| 46 | 26 | int dist_from_src = (src - rank + size) % size; | |
| 47 | |||
| 48 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (clockwise) { |
| 49 | steps = cw_dist; | ||
| 50 | next = (rank + 1) % size; | ||
| 51 | prev = (rank - 1 + size) % size; | ||
| 52 | 26 | dist_from_src = (rank - src + size) % size; | |
| 53 | } | ||
| 54 | |||
| 55 | 26 | std::vector<int> path; | |
| 56 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | if (rank == src) { |
| 57 | path.push_back(src); | ||
| 58 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5 times.
|
13 | if (src != dst) { |
| 59 | 8 | const int path_sz = static_cast<int>(path.size()); | |
| 60 | 8 | const int data_sz = static_cast<int>(payload.size()); | |
| 61 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | MPI_Send(payload.data(), data_sz, MPI_INT, next, 100, MPI_COMM_WORLD); |
| 62 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | MPI_Send(&path_sz, 1, MPI_INT, next, 0, MPI_COMM_WORLD); |
| 63 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | MPI_Send(path.data(), path_sz, MPI_INT, next, 1, MPI_COMM_WORLD); |
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | 26 | bool is_in_path = (dist_from_src > 0 && dist_from_src <= steps); | |
| 68 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 18 times.
|
26 | if (is_in_path) { |
| 69 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | int path_sz = 0; |
| 70 | 8 | const int data_sz = static_cast<int>(payload.size()); | |
| 71 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | MPI_Recv(payload.data(), data_sz, MPI_INT, prev, 100, MPI_COMM_WORLD, MPI_STATUS_IGNORE); |
| 72 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | MPI_Recv(&path_sz, 1, MPI_INT, prev, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); |
| 73 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | path.resize(static_cast<size_t>(path_sz)); |
| 74 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | MPI_Recv(path.data(), path_sz, MPI_INT, prev, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); |
| 75 | path.push_back(rank); | ||
| 76 | |||
| 77 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (rank != dst) { |
| 78 | ✗ | const int next_path_sz = static_cast<int>(path.size()); | |
| 79 | ✗ | MPI_Send(payload.data(), data_sz, MPI_INT, next, 100, MPI_COMM_WORLD); | |
| 80 | ✗ | MPI_Send(&next_path_sz, 1, MPI_INT, next, 0, MPI_COMM_WORLD); | |
| 81 | ✗ | MPI_Send(path.data(), next_path_sz, MPI_INT, next, 1, MPI_COMM_WORLD); | |
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | 26 | int final_path_sz = static_cast<int>(path.size()); | |
| 86 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
26 | MPI_Bcast(&final_path_sz, 1, MPI_INT, dst, MPI_COMM_WORLD); |
| 87 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 13 times.
|
26 | if (rank != dst) { |
| 88 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
13 | path.resize(static_cast<size_t>(final_path_sz)); |
| 89 | } | ||
| 90 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
26 | MPI_Bcast(path.data(), final_path_sz, MPI_INT, dst, MPI_COMM_WORLD); |
| 91 | |||
| 92 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
26 | GetOutput() = path; |
| 93 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
26 | MPI_Barrier(MPI_COMM_WORLD); |
| 94 | 26 | return true; | |
| 95 | } | ||
| 96 | |||
| 97 | 26 | bool ErmakovATestTaskMPI::PostProcessingImpl() { | |
| 98 | 26 | return true; | |
| 99 | } | ||
| 100 | |||
| 101 | } // namespace ermakov_a_ring | ||
| 102 |