X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/fe304706848f0a64477d4687b3ea97d5b9a0c35c..4e62e76d104a17f0c9aaf9135ac605e9c8c87141:/src/smpi/bindings/smpi_pmpi_coll.cpp diff --git a/src/smpi/bindings/smpi_pmpi_coll.cpp b/src/smpi/bindings/smpi_pmpi_coll.cpp index e000a88f9f..bf4952b2b9 100644 --- a/src/smpi/bindings/smpi_pmpi_coll.cpp +++ b/src/smpi/bindings/smpi_pmpi_coll.cpp @@ -13,6 +13,12 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); +#define CHECK_ARGS(test, errcode, ...) \ + if (test) { \ + XBT_WARN(__VA_ARGS__); \ + return (errcode); \ + } + /* PMPI User level calls */ int PMPI_Barrier(MPI_Comm comm) @@ -95,7 +101,7 @@ int PMPI_Igather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void { if (comm == MPI_COMM_NULL) return MPI_ERR_COMM; - if ((sendbuf == nullptr) || ((comm->rank() == root) && recvbuf == nullptr)) + if ((sendbuf == nullptr && sendcount > 0) || ((comm->rank() == root) && recvbuf == nullptr && recvcount > 0)) return MPI_ERR_BUFFER; if (((sendbuf != MPI_IN_PLACE && sendcount > 0) && (sendtype == MPI_DATATYPE_NULL)) || ((comm->rank() == root) && (recvtype == MPI_DATATYPE_NULL))) @@ -207,16 +213,17 @@ int PMPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, int PMPI_Iallgather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request) { - if (comm == MPI_COMM_NULL) - return MPI_ERR_COMM; - if ((sendbuf == nullptr && sendcount > 0) || (recvbuf == nullptr)) - return MPI_ERR_BUFFER; - if (((sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) || (recvtype == MPI_DATATYPE_NULL)) - return MPI_ERR_TYPE; - if (((sendbuf != MPI_IN_PLACE) && (sendcount < 0)) || (recvcount < 0)) - return MPI_ERR_COUNT; - if (request == nullptr) - return MPI_ERR_ARG; + CHECK_ARGS(comm == MPI_COMM_NULL, MPI_ERR_COMM, "Iallgather: the communicator cannot be MPI_COMM_NULL"); + CHECK_ARGS(recvbuf == nullptr && recvcount > 0, MPI_ERR_BUFFER, "Iallgather: param 4 recvbuf cannot be NULL"); + CHECK_ARGS(sendbuf == nullptr && sendcount > 0, MPI_ERR_BUFFER, + "Iallgather: param 1 sendbuf cannot be NULL when sendcound > 0"); + CHECK_ARGS((sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL), MPI_ERR_TYPE, + "Iallgather: param 3 sendtype cannot be MPI_DATATYPE_NULL when sendbuff is not MPI_IN_PLACE"); + CHECK_ARGS(recvtype == MPI_DATATYPE_NULL, MPI_ERR_TYPE, "Iallgather: param 6 recvtype cannot be MPI_DATATYPE_NULL"); + CHECK_ARGS(recvcount < 0, MPI_ERR_COUNT, "Iallgather: param 5 recvcount cannot be negative"); + CHECK_ARGS((sendbuf != MPI_IN_PLACE) && (sendcount < 0), MPI_ERR_COUNT, + "Iallgather: param 2 sendcount cannot be negative when sendbuf is not MPI_IN_PLACE"); + CHECK_ARGS(request == nullptr, MPI_ERR_ARG, "Iallgather: param 8 request cannot be NULL"); smpi_bench_end(); if (sendbuf == MPI_IN_PLACE) { @@ -252,7 +259,7 @@ int PMPI_Iallgatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, { if (comm == MPI_COMM_NULL) return MPI_ERR_COMM; - if ((sendbuf == nullptr && sendcount > 0) || (recvbuf == nullptr)) + if (sendbuf == nullptr && sendcount > 0) return MPI_ERR_BUFFER; if (((sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) || (recvtype == MPI_DATATYPE_NULL)) return MPI_ERR_TYPE; @@ -263,9 +270,11 @@ int PMPI_Iallgatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, if (request == nullptr) return MPI_ERR_ARG; - for (int i = 0; i < comm->size(); i++) { // copy data to avoid bad free + for (int i = 0; i < comm->size(); i++) { if (recvcounts[i] < 0) return MPI_ERR_COUNT; + else if (recvcounts[i] > 0 && recvbuf == nullptr) + return MPI_ERR_BUFFER; } smpi_bench_end(); @@ -353,29 +362,30 @@ int PMPI_Scatterv(const void *sendbuf, const int *sendcounts, const int *displs, int PMPI_Iscatterv(const void* sendbuf, const int* sendcounts, const int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request) { - if (comm == MPI_COMM_NULL) - return MPI_ERR_COMM; - if (sendcounts == nullptr || displs == nullptr) - return MPI_ERR_ARG; - if (((comm->rank() == root) && (sendtype == MPI_DATATYPE_NULL)) || - ((recvbuf != MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) - return MPI_ERR_TYPE; - if (request == nullptr) - return MPI_ERR_ARG; - if (recvbuf != MPI_IN_PLACE && recvcount < 0) - return MPI_ERR_COUNT; - if (root < 0 || root >= comm->size()) - return MPI_ERR_ROOT; + CHECK_ARGS(comm == MPI_COMM_NULL, MPI_ERR_COMM, "Iscatterv: the communicator cannot be MPI_COMM_NULL"); + CHECK_ARGS((comm->rank() == root) && (sendcounts == nullptr), MPI_ERR_ARG, + "Iscatterv: param 2 sendcounts cannot be NULL on the root rank"); + CHECK_ARGS((comm->rank() == root) && (displs == nullptr), MPI_ERR_ARG, + "Iscatterv: param 3 displs cannot be NULL on the root rank"); + CHECK_ARGS((comm->rank() == root) && (sendtype == MPI_DATATYPE_NULL), MPI_ERR_TYPE, + "Iscatterv: The sendtype cannot be NULL on the root rank"); + CHECK_ARGS((recvbuf != MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL), MPI_ERR_TYPE, + "Iscatterv: the recvtype cannot be NULL when not receiving in place"); + CHECK_ARGS(request == nullptr, MPI_ERR_ARG, "Iscatterv: param 10 request cannot be NULL"); + CHECK_ARGS(recvbuf != MPI_IN_PLACE && recvcount < 0, MPI_ERR_COUNT, + "Iscatterv: When not receiving in place, the recvcound cannot be negative"); + CHECK_ARGS(root < 0, MPI_ERR_ROOT, "Iscatterv: root cannot be negative"); + CHECK_ARGS(root >= comm->size(), MPI_ERR_ROOT, "Iscatterv: root (=%d) is larger than communicator size (=%d)", root, + comm->size()); if (comm->rank() == root) { if (recvbuf == MPI_IN_PLACE) { recvtype = sendtype; recvcount = sendcounts[comm->rank()]; } - for (int i = 0; i < comm->size(); i++) { - if (sendcounts[i] < 0) - return MPI_ERR_COUNT; - } + for (int i = 0; i < comm->size(); i++) + CHECK_ARGS(sendcounts[i] < 0, MPI_ERR_COUNT, "Iscatterv: sendcounts[%d]=%d but this cannot be negative", i, + sendcounts[i]); } smpi_bench_end(); @@ -732,7 +742,7 @@ int PMPI_Ialltoall(const void* sendbuf, int sendcount, MPI_Datatype sendtype, vo std::unique_ptr tmp_sendbuf; if (sendbuf == MPI_IN_PLACE) { tmp_sendbuf.reset(new unsigned char[recvcount * comm->size() * recvtype->size()]); - // memcpy(??,nullptr,0) is actually undefined behavor, even if harmless. + // memcpy(??,nullptr,0) is actually undefined behavior, even if harmless. if (recvbuf != nullptr) memcpy(tmp_sendbuf.get(), recvbuf, recvcount * comm->size() * recvtype->size()); real_sendbuf = tmp_sendbuf.get(); @@ -871,7 +881,7 @@ int PMPI_Ialltoallw(const void* sendbuf, const int* sendcounts, const int* sendd smpi_bench_end(); int rank = simgrid::s4u::this_actor::get_pid(); int size = comm->size(); - for (int i = 0; i < size; i++) { // copy data to avoid bad free + for (int i = 0; i < size; i++) { if (recvcounts[i] < 0 || (sendbuf != MPI_IN_PLACE && sendcounts[i] < 0)) return MPI_ERR_COUNT; }