Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Spell check.
[simgrid.git] / src / smpi / bindings / smpi_pmpi_coll.cpp
index 0147374..bf4952b 100644 (file)
@@ -16,7 +16,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
 #define CHECK_ARGS(test, errcode, ...)                                                                                 \
   if (test) {                                                                                                          \
     XBT_WARN(__VA_ARGS__);                                                                                             \
-    return errcode;                                                                                                    \
+    return (errcode);                                                                                                  \
   }
 
 /* PMPI User level calls */
@@ -101,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)))
@@ -214,7 +214,7 @@ int PMPI_Iallgather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, v
                     MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request)
 {
   CHECK_ARGS(comm == MPI_COMM_NULL, MPI_ERR_COMM, "Iallgather: the communicator cannot be MPI_COMM_NULL");
-  CHECK_ARGS(recvbuf == nullptr, MPI_ERR_BUFFER, "Iallgather: param 4 recvbuf cannot be 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,
@@ -259,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;
@@ -270,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();
@@ -740,7 +742,7 @@ int PMPI_Ialltoall(const void* sendbuf, int sendcount, MPI_Datatype sendtype, vo
   std::unique_ptr<unsigned char[]> 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();
@@ -879,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;
   }