| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "pikhotskiy_r_scatter/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <cstddef> | ||
| 6 | #include <cstring> | ||
| 7 | |||
| 8 | #include "pikhotskiy_r_scatter/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace pikhotskiy_r_scatter { | ||
| 11 | |||
| 12 | 8 | PikhotskiyRScatterMPI::PikhotskiyRScatterMPI(const InType &in) { | |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | GetOutput() = nullptr; | ||
| 16 | 8 | } | |
| 17 | |||
| 18 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | bool PikhotskiyRScatterMPI::ValidationImpl() { |
| 19 | InType input = GetInput(); | ||
| 20 | MPI_Datatype sendtype = std::get<2>(input); | ||
| 21 | MPI_Datatype recvtype = std::get<5>(input); | ||
| 22 | |||
| 23 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (sendtype != recvtype) { |
| 24 | return false; | ||
| 25 | } | ||
| 26 | |||
| 27 | int sendcount = std::get<1>(input); | ||
| 28 | int recvcount = std::get<4>(input); | ||
| 29 | |||
| 30 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (sendcount < 0 || recvcount < 0) { |
| 31 | return false; | ||
| 32 | } | ||
| 33 | |||
| 34 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (sendcount != recvcount) { |
| 35 | return false; | ||
| 36 | } | ||
| 37 | |||
| 38 | void *recvbuf = std::get<3>(input); | ||
| 39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (recvcount > 0 && recvbuf == nullptr) { |
| 40 | return false; | ||
| 41 | } | ||
| 42 | |||
| 43 | int root = std::get<6>(input); | ||
| 44 | MPI_Comm comm = std::get<7>(input); | ||
| 45 | |||
| 46 | 8 | int rank = 0; | |
| 47 | 8 | MPI_Comm_rank(comm, &rank); | |
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | if (rank == root) { |
| 50 | const void *sendbuf = std::get<0>(input); | ||
| 51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (sendcount > 0 && sendbuf == nullptr) { |
| 52 | return false; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | return true; | ||
| 57 | } | ||
| 58 | |||
| 59 | 8 | bool PikhotskiyRScatterMPI::PreProcessingImpl() { | |
| 60 | 8 | return true; | |
| 61 | } | ||
| 62 | |||
| 63 | 2 | int PikhotskiyRScatterMPI::CustomScatterInt(const void *sendbuf, int sendcount, void *recvbuf, int recvcount, int root, | |
| 64 | MPI_Comm comm) { | ||
| 65 | 2 | int rank = 0; | |
| 66 | 2 | int size = 0; | |
| 67 | 2 | MPI_Comm_rank(comm, &rank); | |
| 68 | 2 | MPI_Comm_size(comm, &size); | |
| 69 | |||
| 70 | int *recv_data = static_cast<int *>(recvbuf); | ||
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (rank == root) { |
| 73 | const int *send_data = static_cast<const int *>(sendbuf); | ||
| 74 | |||
| 75 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (recv_data != nullptr && sendcount > 0) { |
| 76 | 1 | std::memcpy(recv_data, send_data + (static_cast<ptrdiff_t>(rank) * sendcount), | |
| 77 | 1 | static_cast<size_t>(sendcount) * sizeof(int)); | |
| 78 | } | ||
| 79 | |||
| 80 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (sendcount > 0) { |
| 81 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (int i = 0; i < size; ++i) { |
| 82 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (i != root) { |
| 83 | 1 | MPI_Send(send_data + (static_cast<ptrdiff_t>(i) * sendcount), sendcount, MPI_INT, i, 0, comm); | |
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | } else if (recvcount > 0) { |
| 88 | 1 | MPI_Recv(recv_data, recvcount, MPI_INT, root, 0, comm, MPI_STATUS_IGNORE); | |
| 89 | } | ||
| 90 | |||
| 91 | 2 | return MPI_SUCCESS; | |
| 92 | } | ||
| 93 | |||
| 94 | 2 | int PikhotskiyRScatterMPI::CustomScatterFloat(const void *sendbuf, int sendcount, void *recvbuf, int recvcount, | |
| 95 | int root, MPI_Comm comm) { | ||
| 96 | 2 | int rank = 0; | |
| 97 | 2 | int size = 0; | |
| 98 | 2 | MPI_Comm_rank(comm, &rank); | |
| 99 | 2 | MPI_Comm_size(comm, &size); | |
| 100 | |||
| 101 | auto *recv_data = static_cast<float *>(recvbuf); | ||
| 102 | |||
| 103 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (rank == root) { |
| 104 | const auto *send_data = static_cast<const float *>(sendbuf); | ||
| 105 | |||
| 106 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (recv_data != nullptr && sendcount > 0) { |
| 107 | 1 | std::memcpy(recv_data, send_data + (static_cast<ptrdiff_t>(rank) * sendcount), | |
| 108 | 1 | static_cast<size_t>(sendcount) * sizeof(float)); | |
| 109 | } | ||
| 110 | |||
| 111 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (sendcount > 0) { |
| 112 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (int i = 0; i < size; ++i) { |
| 113 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (i != root) { |
| 114 | 1 | MPI_Send(send_data + (static_cast<ptrdiff_t>(i) * sendcount), sendcount, MPI_FLOAT, i, 0, comm); | |
| 115 | } | ||
| 116 | } | ||
| 117 | } | ||
| 118 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | } else if (recvcount > 0) { |
| 119 | 1 | MPI_Recv(recv_data, recvcount, MPI_FLOAT, root, 0, comm, MPI_STATUS_IGNORE); | |
| 120 | } | ||
| 121 | |||
| 122 | 2 | return MPI_SUCCESS; | |
| 123 | } | ||
| 124 | |||
| 125 | 2 | int PikhotskiyRScatterMPI::CustomScatterDouble(const void *sendbuf, int sendcount, void *recvbuf, int recvcount, | |
| 126 | int root, MPI_Comm comm) { | ||
| 127 | 2 | int rank = 0; | |
| 128 | 2 | int size = 0; | |
| 129 | 2 | MPI_Comm_rank(comm, &rank); | |
| 130 | 2 | MPI_Comm_size(comm, &size); | |
| 131 | |||
| 132 | auto *recv_data = static_cast<double *>(recvbuf); | ||
| 133 | |||
| 134 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (rank == root) { |
| 135 | const auto *send_data = static_cast<const double *>(sendbuf); | ||
| 136 | |||
| 137 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (recv_data != nullptr && sendcount > 0) { |
| 138 | 1 | std::memcpy(recv_data, send_data + (static_cast<ptrdiff_t>(rank) * sendcount), | |
| 139 | 1 | static_cast<size_t>(sendcount) * sizeof(double)); | |
| 140 | } | ||
| 141 | |||
| 142 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (sendcount > 0) { |
| 143 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (int i = 0; i < size; ++i) { |
| 144 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (i != root) { |
| 145 | 1 | MPI_Send(send_data + (static_cast<ptrdiff_t>(i) * sendcount), sendcount, MPI_DOUBLE, i, 0, comm); | |
| 146 | } | ||
| 147 | } | ||
| 148 | } | ||
| 149 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | } else if (recvcount > 0) { |
| 150 | 1 | MPI_Recv(recv_data, recvcount, MPI_DOUBLE, root, 0, comm, MPI_STATUS_IGNORE); | |
| 151 | } | ||
| 152 | |||
| 153 | 2 | return MPI_SUCCESS; | |
| 154 | } | ||
| 155 | |||
| 156 | 8 | int PikhotskiyRScatterMPI::CustomScatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, | |
| 157 | int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { | ||
| 158 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
|
8 | if (sendcount == 0 && recvcount == 0) { |
| 159 | return MPI_SUCCESS; | ||
| 160 | } | ||
| 161 | |||
| 162 | 6 | int sendtype_size = 0; | |
| 163 | 6 | MPI_Type_size(sendtype, &sendtype_size); | |
| 164 | |||
| 165 | 6 | int recvtype_size = 0; | |
| 166 | 6 | MPI_Type_size(recvtype, &recvtype_size); | |
| 167 | |||
| 168 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (sendcount * sendtype_size < recvcount * recvtype_size) { |
| 169 | return MPI_ERR_ARG; | ||
| 170 | } | ||
| 171 | |||
| 172 | 6 | int rank = 0; | |
| 173 | 6 | MPI_Comm_rank(comm, &rank); | |
| 174 | |||
| 175 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
6 | if (rank == root && sendbuf == nullptr && sendcount > 0) { |
| 176 | return MPI_ERR_BUFFER; | ||
| 177 | } | ||
| 178 | |||
| 179 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (recvbuf == nullptr && recvcount > 0) { |
| 180 | return MPI_ERR_BUFFER; | ||
| 181 | } | ||
| 182 | |||
| 183 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | if (sendtype == MPI_INT) { |
| 184 | 2 | return CustomScatterInt(sendbuf, sendcount, recvbuf, recvcount, root, comm); | |
| 185 | } | ||
| 186 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (sendtype == MPI_FLOAT) { |
| 187 | 2 | return CustomScatterFloat(sendbuf, sendcount, recvbuf, recvcount, root, comm); | |
| 188 | } | ||
| 189 | 2 | return CustomScatterDouble(sendbuf, sendcount, recvbuf, recvcount, root, comm); | |
| 190 | } | ||
| 191 | |||
| 192 | 8 | bool PikhotskiyRScatterMPI::RunImpl() { | |
| 193 | auto &input = GetInput(); | ||
| 194 | |||
| 195 | 8 | const void *sendbuf = std::get<0>(input); | |
| 196 | 8 | int sendcount = std::get<1>(input); | |
| 197 | 8 | MPI_Datatype sendtype = std::get<2>(input); | |
| 198 | 8 | void *recvbuf = std::get<3>(input); | |
| 199 | 8 | int recvcount = std::get<4>(input); | |
| 200 | 8 | MPI_Datatype recvtype = std::get<5>(input); | |
| 201 | 8 | int root = std::get<6>(input); | |
| 202 | 8 | MPI_Comm comm = std::get<7>(input); | |
| 203 | |||
| 204 | 8 | MPI_Barrier(comm); | |
| 205 | |||
| 206 | 8 | int result = CustomScatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm); | |
| 207 | |||
| 208 | 8 | MPI_Barrier(comm); | |
| 209 | |||
| 210 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (result != MPI_SUCCESS) { |
| 211 | return false; | ||
| 212 | } | ||
| 213 | |||
| 214 | 8 | GetOutput() = recvbuf; | |
| 215 | 8 | return true; | |
| 216 | } | ||
| 217 | |||
| 218 | 8 | bool PikhotskiyRScatterMPI::PostProcessingImpl() { | |
| 219 | 8 | return true; | |
| 220 | } | ||
| 221 | |||
| 222 | } // namespace pikhotskiy_r_scatter | ||
| 223 |