| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "zenin_a_topology_star/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <cstddef> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "zenin_a_topology_star/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace zenin_a_topology_star { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
|
30 | ZeninATopologyStarMPI::ZeninATopologyStarMPI(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | 30 | GetOutput() = OutType{}; | |
| 16 | 30 | } | |
| 17 | |||
| 18 | 30 | bool ZeninATopologyStarMPI::ValidationImpl() { | |
| 19 | 30 | int world_size = 0; | |
| 20 | 30 | MPI_Comm_size(MPI_COMM_WORLD, &world_size); | |
| 21 | |||
| 22 | const auto &in = GetInput(); | ||
| 23 | 30 | const int src = static_cast<int>(std::get<0>(in)); | |
| 24 | 30 | const int dst = static_cast<int>(std::get<1>(in)); | |
| 25 |
3/6✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 30 times.
|
30 | return src >= 0 && dst >= 0 && src < world_size && dst < world_size; |
| 26 | } | ||
| 27 | |||
| 28 | 30 | bool ZeninATopologyStarMPI::PreProcessingImpl() { | |
| 29 | 30 | return true; | |
| 30 | } | ||
| 31 | |||
| 32 | 30 | bool ZeninATopologyStarMPI::RunImpl() { | |
| 33 | 30 | int world_rank = 0; | |
| 34 | 30 | int world_size = 0; | |
| 35 | 30 | MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); | |
| 36 | 30 | MPI_Comm_size(MPI_COMM_WORLD, &world_size); | |
| 37 | |||
| 38 | const auto &in = GetInput(); | ||
| 39 | 30 | const size_t src = std::get<0>(in); | |
| 40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | const size_t dst = std::get<1>(in); |
| 41 | const auto &data = std::get<2>(in); | ||
| 42 | |||
| 43 | auto &out = GetOutput(); | ||
| 44 | out.clear(); | ||
| 45 | |||
| 46 | const int center = 0; | ||
| 47 | const int tag = 0; | ||
| 48 | |||
| 49 | 30 | const int src_rank = static_cast<int>(src); | |
| 50 | 30 | const int dst_rank = static_cast<int>(dst); | |
| 51 | const int center_rank = center; | ||
| 52 | |||
| 53 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 22 times.
|
30 | if (src_rank == dst_rank) { |
| 54 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | if (world_rank == src_rank) { |
| 55 | 4 | out = data; | |
| 56 | } | ||
| 57 | 8 | return true; | |
| 58 | } | ||
| 59 | |||
| 60 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | if (src_rank == center_rank || dst_rank == center_rank) { |
| 61 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 11 times.
|
22 | if (world_rank == src_rank) { |
| 62 | 11 | MPI_Send(data.data(), static_cast<int>(data.size()), MPI_DOUBLE, dst_rank, tag, MPI_COMM_WORLD); | |
| 63 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | } else if (world_rank == dst_rank) { |
| 64 | 11 | out.resize(data.size()); | |
| 65 | 11 | MPI_Recv(out.data(), static_cast<int>(out.size()), MPI_DOUBLE, src_rank, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
| 66 | } | ||
| 67 | 22 | return true; | |
| 68 | } | ||
| 69 | |||
| 70 | ✗ | if (world_rank == src_rank) { | |
| 71 | ✗ | MPI_Send(data.data(), static_cast<int>(data.size()), MPI_DOUBLE, center_rank, tag, MPI_COMM_WORLD); | |
| 72 | ✗ | } else if (world_rank == center_rank) { | |
| 73 | ✗ | std::vector<double> buf(data.size()); | |
| 74 | ✗ | MPI_Recv(buf.data(), static_cast<int>(buf.size()), MPI_DOUBLE, src_rank, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
| 75 | |||
| 76 | ✗ | MPI_Send(buf.data(), static_cast<int>(buf.size()), MPI_DOUBLE, dst_rank, tag, MPI_COMM_WORLD); | |
| 77 | ✗ | } else if (world_rank == dst_rank) { | |
| 78 | ✗ | out.resize(data.size()); | |
| 79 | ✗ | MPI_Recv(out.data(), static_cast<int>(out.size()), MPI_DOUBLE, center_rank, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
| 80 | } | ||
| 81 | |||
| 82 | return true; | ||
| 83 | } | ||
| 84 | |||
| 85 | 30 | bool ZeninATopologyStarMPI::PostProcessingImpl() { | |
| 86 | 30 | return true; | |
| 87 | } | ||
| 88 | |||
| 89 | } // namespace zenin_a_topology_star | ||
| 90 |