| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "sakharov_a_transmission_from_one_to_all/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "sakharov_a_transmission_from_one_to_all/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace sakharov_a_transmission_from_one_to_all { | ||
| 10 | |||
| 11 | 64 | int MyBcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm) { | |
| 12 | 64 | int rank = 0; | |
| 13 | 64 | int size = 0; | |
| 14 | 64 | MPI_Comm_rank(comm, &rank); | |
| 15 | 64 | MPI_Comm_size(comm, &size); | |
| 16 | |||
| 17 | 64 | int v_rank = (rank - root + size) % size; | |
| 18 | |||
| 19 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 32 times.
|
64 | if (v_rank != 0) { |
| 20 | 32 | int v_parent = (v_rank - 1) / 2; | |
| 21 | 32 | int real_parent = (v_parent + root) % size; | |
| 22 | 32 | MPI_Recv(buffer, count, datatype, real_parent, 0, comm, MPI_STATUS_IGNORE); | |
| 23 | } | ||
| 24 | |||
| 25 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 64 times.
|
192 | for (int child_offset = 1; child_offset <= 2; ++child_offset) { |
| 26 | 128 | int v_child = (2 * v_rank) + child_offset; | |
| 27 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 96 times.
|
128 | if (v_child < size) { |
| 28 | 32 | int real_child = (v_child + root) % size; | |
| 29 | 32 | MPI_Send(buffer, count, datatype, real_child, 0, comm); | |
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | 64 | return MPI_SUCCESS; | |
| 34 | } | ||
| 35 | |||
| 36 | namespace { | ||
| 37 | |||
| 38 | 16 | void BroadcastInts(int root, int rank, const InType &input, std::vector<int> &data_out) { | |
| 39 | 16 | std::vector<int> data; | |
| 40 | 16 | int count = 0; | |
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 | if (rank == root) { |
| 43 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | data = std::get<1>(input); |
| 44 | 8 | count = static_cast<int>(data.size()); | |
| 45 | } | ||
| 46 | |||
| 47 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | MyBcast(&count, 1, MPI_INT, root, MPI_COMM_WORLD); |
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 | if (rank != root) { |
| 50 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | data.resize(count); |
| 51 | } | ||
| 52 | |||
| 53 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | MyBcast(data.data(), count, MPI_INT, root, MPI_COMM_WORLD); |
| 54 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | data_out = data; |
| 55 | 16 | } | |
| 56 | |||
| 57 | 16 | void BroadcastFloats(int root, int rank) { | |
| 58 | 16 | std::vector<float> float_data(100); | |
| 59 | constexpr int kFloatCount = 100; | ||
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 | if (rank == root) { |
| 62 |
2/2✓ Branch 0 taken 800 times.
✓ Branch 1 taken 8 times.
|
808 | for (int i = 0; i < kFloatCount; ++i) { |
| 63 | 800 | float_data[i] = static_cast<float>(i) + 0.5F; | |
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | MyBcast(float_data.data(), kFloatCount, MPI_FLOAT, root, MPI_COMM_WORLD); |
| 68 | 16 | } | |
| 69 | |||
| 70 | 16 | void BroadcastDoubles(int root, int rank) { | |
| 71 | 16 | std::vector<double> double_data(100); | |
| 72 | constexpr int kDoubleCount = 100; | ||
| 73 | |||
| 74 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 | if (rank == root) { |
| 75 |
2/2✓ Branch 0 taken 800 times.
✓ Branch 1 taken 8 times.
|
808 | for (int i = 0; i < kDoubleCount; ++i) { |
| 76 | 800 | double_data[i] = static_cast<double>(i) + 0.123; | |
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | MyBcast(double_data.data(), kDoubleCount, MPI_DOUBLE, root, MPI_COMM_WORLD); |
| 81 | 16 | } | |
| 82 | |||
| 83 | } // namespace | ||
| 84 | |||
| 85 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | SakharovATransmissionFromOneToAllMPI::SakharovATransmissionFromOneToAllMPI(const InType &in) { |
| 86 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 87 | GetInput() = in; | ||
| 88 | 16 | } | |
| 89 | |||
| 90 | 16 | bool SakharovATransmissionFromOneToAllMPI::ValidationImpl() { | |
| 91 | 16 | int root = std::get<0>(GetInput()); | |
| 92 | 16 | int world_size = 0; | |
| 93 | 16 | MPI_Comm_size(MPI_COMM_WORLD, &world_size); | |
| 94 |
2/4✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
|
16 | return root >= 0 && root < world_size; |
| 95 | } | ||
| 96 | |||
| 97 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | bool SakharovATransmissionFromOneToAllMPI::PreProcessingImpl() { |
| 98 | GetOutput().clear(); | ||
| 99 | 16 | return true; | |
| 100 | } | ||
| 101 | |||
| 102 | 16 | bool SakharovATransmissionFromOneToAllMPI::RunImpl() { | |
| 103 | 16 | const int root = std::get<0>(GetInput()); | |
| 104 | 16 | int rank = 0; | |
| 105 | 16 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 106 | |||
| 107 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | std::vector<int> data; |
| 108 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | BroadcastInts(root, rank, GetInput(), data); |
| 109 | |||
| 110 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | BroadcastFloats(root, rank); |
| 111 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | BroadcastDoubles(root, rank); |
| 112 | |||
| 113 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | GetOutput() = data; |
| 114 | 16 | return true; | |
| 115 | } | ||
| 116 | |||
| 117 | 16 | bool SakharovATransmissionFromOneToAllMPI::PostProcessingImpl() { | |
| 118 | 16 | return true; | |
| 119 | } | ||
| 120 | |||
| 121 | } // namespace sakharov_a_transmission_from_one_to_all | ||
| 122 |