| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "egorova_l_a_broadcast/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <cstring> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "egorova_l_a_broadcast/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace egorova_l_a_broadcast { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | EgorovaLBroadcastMPI::EgorovaLBroadcastMPI(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | GetInput() = in; |
| 15 | 12 | } | |
| 16 | |||
| 17 | 12 | bool EgorovaLBroadcastMPI::ValidationImpl() { | |
| 18 | 12 | return true; | |
| 19 | } | ||
| 20 | 12 | bool EgorovaLBroadcastMPI::PreProcessingImpl() { | |
| 21 | 12 | return true; | |
| 22 | } | ||
| 23 | |||
| 24 | 12 | void EgorovaLBroadcastMPI::TreeBroadcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm) { | |
| 25 | 12 | int rank = 0; | |
| 26 | 12 | int size = 0; | |
| 27 | 12 | MPI_Comm_rank(comm, &rank); | |
| 28 | 12 | MPI_Comm_size(comm, &size); | |
| 29 | |||
| 30 | 12 | int v_rank = (rank - root + size) % size; | |
| 31 | |||
| 32 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
|
24 | for (int mask = 1; mask < size; mask <<= 1) { |
| 33 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (v_rank < mask) { |
| 34 | 6 | int v_dest = v_rank | mask; | |
| 35 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (v_dest < size) { |
| 36 | 6 | int dest = (v_dest + root) % size; | |
| 37 | 6 | MPI_Send(buffer, count, datatype, dest, 0, comm); | |
| 38 | } | ||
| 39 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | } else if (v_rank < (mask << 1)) { |
| 40 | 6 | int v_src = v_rank & ~mask; | |
| 41 | 6 | int src = (v_src + root) % size; | |
| 42 | 6 | MPI_Recv(buffer, count, datatype, src, 0, comm, MPI_STATUS_IGNORE); | |
| 43 | } | ||
| 44 | } | ||
| 45 | 12 | } | |
| 46 | |||
| 47 | 12 | bool EgorovaLBroadcastMPI::RunImpl() { | |
| 48 | 12 | int rank = 0; | |
| 49 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 50 | auto &in = GetInput(); | ||
| 51 | int count = 0; | ||
| 52 | MPI_Datatype type = MPI_DATATYPE_NULL; | ||
| 53 | |||
| 54 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
|
12 | if (in.type_indicator == 0) { |
| 55 | 4 | count = static_cast<int>(in.data_int.size()); | |
| 56 | type = MPI_INT; | ||
| 57 | 4 | GetOutput().resize(count * sizeof(int)); | |
| 58 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (rank == in.root) { |
| 59 | std::memcpy(GetOutput().data(), in.data_int.data(), GetOutput().size()); | ||
| 60 | } | ||
| 61 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | } else if (in.type_indicator == 1) { |
| 62 | 4 | count = static_cast<int>(in.data_float.size()); | |
| 63 | type = MPI_FLOAT; | ||
| 64 | 4 | GetOutput().resize(count * sizeof(float)); | |
| 65 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (rank == in.root) { |
| 66 | std::memcpy(GetOutput().data(), in.data_float.data(), GetOutput().size()); | ||
| 67 | } | ||
| 68 | } else { | ||
| 69 | 4 | count = static_cast<int>(in.data_double.size()); | |
| 70 | type = MPI_DOUBLE; | ||
| 71 | 4 | GetOutput().resize(count * sizeof(double)); | |
| 72 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (rank == in.root) { |
| 73 | std::memcpy(GetOutput().data(), in.data_double.data(), GetOutput().size()); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | 12 | TreeBroadcast(GetOutput().data(), count, type, in.root, MPI_COMM_WORLD); | |
| 78 | 12 | return true; | |
| 79 | } | ||
| 80 | |||
| 81 | 12 | bool EgorovaLBroadcastMPI::PostProcessingImpl() { | |
| 82 | 12 | return true; | |
| 83 | } | ||
| 84 | |||
| 85 | } // namespace egorova_l_a_broadcast | ||
| 86 |