Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / smpi / colls / smpi_nbc_impl.cpp
index 22301c0..6c0c050 100644 (file)
@@ -1,6 +1,6 @@
 /* Asynchronous parts of the basic collective algorithms, meant to be used both for the naive default implementation, but also for non blocking collectives */
 
-/* Copyright (c) 2009-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2009-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -11,8 +11,7 @@
 namespace simgrid{
 namespace smpi{
 
-
-int Colls::ibarrier(MPI_Comm comm, MPI_Request* request, int external)
+int colls::ibarrier(MPI_Comm comm, MPI_Request* request, int external)
 {
   int size = comm->size();
   int rank = comm->rank();
@@ -20,7 +19,7 @@ int Colls::ibarrier(MPI_Comm comm, MPI_Request* request, int external)
   (*request) = new Request( nullptr, 0, MPI_BYTE,
                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
   if (rank > 0) {
-    MPI_Request* requests = new MPI_Request[2];
+    auto* requests = new MPI_Request[2];
     requests[0] = Request::isend (nullptr, 0, MPI_BYTE, 0,
                              system_tag,
                              comm);
@@ -30,7 +29,7 @@ int Colls::ibarrier(MPI_Comm comm, MPI_Request* request, int external)
     (*request)->set_nbc_requests(requests, 2);
   }
   else {
-    MPI_Request* requests = new MPI_Request[(size - 1) * 2];
+    auto* requests = new MPI_Request[(size - 1) * 2];
     for (int i = 1; i < 2 * size - 1; i += 2) {
       requests[i - 1] = Request::irecv(nullptr, 0, MPI_BYTE, MPI_ANY_SOURCE, system_tag, comm);
       requests[i]     = Request::isend(nullptr, 0, MPI_BYTE, (i + 1) / 2, system_tag, comm);
@@ -40,7 +39,8 @@ int Colls::ibarrier(MPI_Comm comm, MPI_Request* request, int external)
   return MPI_SUCCESS;
 }
 
-int Colls::ibcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, MPI_Request* request, int external)
+int colls::ibcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, MPI_Request* request,
+                  int external)
 {
   int size = comm->size();
   int rank = comm->rank();
@@ -48,14 +48,14 @@ int Colls::ibcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Com
   (*request) = new Request( nullptr, 0, MPI_BYTE,
                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
   if (rank != root) {
-    MPI_Request* requests = new MPI_Request[1];
+    auto* requests = new MPI_Request[1];
     requests[0] = Request::irecv (buf, count, datatype, root,
                              system_tag,
                              comm);
     (*request)->set_nbc_requests(requests, 1);
   }
   else {
-    MPI_Request* requests = new MPI_Request[size - 1];
+    auto* requests = new MPI_Request[size - 1];
     int n = 0;
     for (int i = 0; i < size; i++) {
       if(i!=root){
@@ -71,8 +71,8 @@ int Colls::ibcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Com
   return MPI_SUCCESS;
 }
 
-int Colls::iallgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
-                        void *recvbuf,int recvcount, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request, int external)
+int colls::iallgather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
+                      MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request, int external)
 {
 
   const int system_tag = COLL_TAG_ALLGATHER-external;
@@ -89,7 +89,7 @@ int Colls::iallgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
   Datatype::copy(sendbuf, sendcount, sendtype, static_cast<char *>(recvbuf) + rank * recvcount * recvext, recvcount,
                      recvtype);
   // Send/Recv buffers to/from others;
-  MPI_Request* requests = new MPI_Request[2 * (size - 1)];
+  auto* requests = new MPI_Request[2 * (size - 1)];
   int index = 0;
   for (int other = 0; other < size; other++) {
     if(other != rank) {
@@ -105,8 +105,8 @@ int Colls::iallgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
   return MPI_SUCCESS;
 }
 
-int Colls::iscatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
-                      void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request, int external)
+int colls::iscatter(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
+                    MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request, int external)
 {
   const int system_tag = COLL_TAG_SCATTER-external;
   MPI_Aint lb = 0;
@@ -117,7 +117,7 @@ int Colls::iscatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
   (*request) = new Request( nullptr, 0, MPI_BYTE,
                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
   if(rank != root) {
-    MPI_Request* requests = new MPI_Request[1];
+    auto* requests = new MPI_Request[1];
     // Recv buffer from root
     requests[0] = Request::irecv(recvbuf, recvcount, recvtype, root, system_tag, comm);
     (*request)->set_nbc_requests(requests, 1);
@@ -129,7 +129,7 @@ int Colls::iscatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                            sendcount, sendtype, recvbuf, recvcount, recvtype);
     }
     // Send buffers to receivers
-    MPI_Request* requests = new MPI_Request[size - 1];
+    auto* requests = new MPI_Request[size - 1];
     int index = 0;
     for(int dst = 0; dst < size; dst++) {
       if(dst != root) {
@@ -145,8 +145,8 @@ int Colls::iscatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
   return MPI_SUCCESS;
 }
 
-int Colls::iallgatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,
-                         const int *recvcounts, const int *displs, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request, int external)
+int colls::iallgatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, const int* recvcounts,
+                       const int* displs, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request, int external)
 {
   const int system_tag = COLL_TAG_ALLGATHERV-external;
   MPI_Aint lb = 0;
@@ -161,7 +161,7 @@ int Colls::iallgatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype
   Datatype::copy(sendbuf, sendcount, sendtype,
                      static_cast<char *>(recvbuf) + displs[rank] * recvext,recvcounts[rank], recvtype);
   // Send buffers to others;
-  MPI_Request *requests = new MPI_Request[2 * (size - 1)];
+  auto* requests = new MPI_Request[2 * (size - 1)];
   int index = 0;
   for (int other = 0; other < size; other++) {
     if(other != rank) {
@@ -179,7 +179,9 @@ int Colls::iallgatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype
   return MPI_SUCCESS;
 }
 
-int Colls::ialltoall( const void *sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request, int external){
+int colls::ialltoall(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
+                     MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request, int external)
+{
   int system_tag   = COLL_TAG_ALLTOALL-external;
   MPI_Aint lb      = 0;
   MPI_Aint sendext = 0;
@@ -197,7 +199,7 @@ int Colls::ialltoall( const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                                static_cast<char *>(recvbuf) + rank * recvcount * recvext, recvcount, recvtype);
   if (err == MPI_SUCCESS && size > 1) {
     /* Initiate all send/recv to/from others. */
-    MPI_Request* requests = new MPI_Request[2 * (size - 1)];
+    auto* requests = new MPI_Request[2 * (size - 1)];
     /* Post all receives first -- a simple optimization */
     int count = 0;
     for (int i = (rank + 1) % size; i != rank; i = (i + 1) % size) {
@@ -222,8 +224,10 @@ int Colls::ialltoall( const void *sendbuf, int sendcount, MPI_Datatype sendtype,
   return MPI_SUCCESS;
 }
 
-int Colls::ialltoallv(const void *sendbuf, const int *sendcounts, const int *senddisps, MPI_Datatype sendtype,
-                              void *recvbuf, const int *recvcounts, const int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request *request, int external){
+int colls::ialltoallv(const void* sendbuf, const int* sendcounts, const int* senddisps, MPI_Datatype sendtype,
+                      void* recvbuf, const int* recvcounts, const int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm,
+                      MPI_Request* request, int external)
+{
   const int system_tag = COLL_TAG_ALLTOALLV-external;
   MPI_Aint lb = 0;
   MPI_Aint sendext = 0;
@@ -241,7 +245,7 @@ int Colls::ialltoallv(const void *sendbuf, const int *sendcounts, const int *sen
                                static_cast<char *>(recvbuf) + recvdisps[rank] * recvext, recvcounts[rank], recvtype);
   if (err == MPI_SUCCESS && size > 1) {
     /* Initiate all send/recv to/from others. */
-    MPI_Request* requests = new MPI_Request[2 * (size - 1)];
+    auto* requests = new MPI_Request[2 * (size - 1)];
     int count = 0;
     /* Create all receives that will be posted first */
     for (int i = 0; i < size; ++i) {
@@ -270,8 +274,10 @@ int Colls::ialltoallv(const void *sendbuf, const int *sendcounts, const int *sen
   return err;
 }
 
-int Colls::ialltoallw(const void *sendbuf, const int *sendcounts, const int *senddisps, const MPI_Datatype* sendtypes,
-                              void *recvbuf, const int *recvcounts, const int *recvdisps, const MPI_Datatype* recvtypes, MPI_Comm comm, MPI_Request *request, int external){
+int colls::ialltoallw(const void* sendbuf, const int* sendcounts, const int* senddisps, const MPI_Datatype* sendtypes,
+                      void* recvbuf, const int* recvcounts, const int* recvdisps, const MPI_Datatype* recvtypes,
+                      MPI_Comm comm, MPI_Request* request, int external)
+{
   const int system_tag = COLL_TAG_ALLTOALLW-external;
 
   /* Initialize. */
@@ -284,7 +290,7 @@ int Colls::ialltoallw(const void *sendbuf, const int *sendcounts, const int *sen
                                static_cast<char *>(recvbuf) + recvdisps[rank], recvcounts[rank], recvtypes[rank]): MPI_SUCCESS;
   if (err == MPI_SUCCESS && size > 1) {
     /* Initiate all send/recv to/from others. */
-    MPI_Request* requests = new MPI_Request[2 * (size - 1)];
+    auto* requests = new MPI_Request[2 * (size - 1)];
     int count = 0;
     /* Create all receives that will be posted first */
     for (int i = 0; i < size; ++i) {
@@ -313,8 +319,8 @@ int Colls::ialltoallw(const void *sendbuf, const int *sendcounts, const int *sen
   return err;
 }
 
-int Colls::igather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
-                     void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request *request, int external)
+int colls::igather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
+                   MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request, int external)
 {
   const int system_tag = COLL_TAG_GATHER-external;
   MPI_Aint lb = 0;
@@ -326,7 +332,7 @@ int Colls::igather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
   if(rank != root) {
     // Send buffer to root
-    MPI_Request* requests = new MPI_Request[1];
+    auto* requests = new MPI_Request[1];
     requests[0]=Request::isend(sendbuf, sendcount, sendtype, root, system_tag, comm);
     (*request)->set_nbc_requests(requests, 1);
   } else {
@@ -335,7 +341,7 @@ int Colls::igather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
     Datatype::copy(sendbuf, sendcount, sendtype, static_cast<char*>(recvbuf) + root * recvcount * recvext,
                        recvcount, recvtype);
     // Receive buffers from senders
-    MPI_Request* requests = new MPI_Request[size - 1];
+    auto* requests = new MPI_Request[size - 1];
     int index = 0;
     for (int src = 0; src < size; src++) {
       if(src != root) {
@@ -351,8 +357,9 @@ int Colls::igather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
   return MPI_SUCCESS;
 }
 
-int Colls::igatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int *recvcounts, const int *displs,
-                      MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request *request, int external)
+int colls::igatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, const int* recvcounts,
+                    const int* displs, MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request,
+                    int external)
 {
   int system_tag = COLL_TAG_GATHERV-external;
   MPI_Aint lb = 0;
@@ -364,7 +371,7 @@ int Colls::igatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, v
                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
   if (rank != root) {
     // Send buffer to root
-    MPI_Request* requests = new MPI_Request[1];
+    auto* requests = new MPI_Request[1];
     requests[0]=Request::isend(sendbuf, sendcount, sendtype, root, system_tag, comm);
     (*request)->set_nbc_requests(requests, 1);
   } else {
@@ -373,7 +380,7 @@ int Colls::igatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, v
     Datatype::copy(sendbuf, sendcount, sendtype, static_cast<char*>(recvbuf) + displs[root] * recvext,
                        recvcounts[root], recvtype);
     // Receive buffers from senders
-    MPI_Request* requests = new MPI_Request[size - 1];
+    auto* requests = new MPI_Request[size - 1];
     int index = 0;
     for (int src = 0; src < size; src++) {
       if(src != root) {
@@ -388,8 +395,9 @@ int Colls::igatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, v
   }
   return MPI_SUCCESS;
 }
-int Colls::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, int external)
+int colls::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,
+                     int external)
 {
   int system_tag = COLL_TAG_SCATTERV-external;
   MPI_Aint lb = 0;
@@ -401,7 +409,7 @@ int Colls::iscatterv(const void *sendbuf, const int *sendcounts, const int *disp
                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
   if(rank != root) {
     // Recv buffer from root
-    MPI_Request* requests = new MPI_Request[1];
+    auto* requests = new MPI_Request[1];
     requests[0]=Request::irecv(recvbuf, recvcount, recvtype, root, system_tag, comm);
     (*request)->set_nbc_requests(requests, 1);
   } else {
@@ -412,7 +420,7 @@ int Colls::iscatterv(const void *sendbuf, const int *sendcounts, const int *disp
                        sendtype, recvbuf, recvcount, recvtype);
     }
     // Send buffers to receivers
-    MPI_Request *requests = new MPI_Request[size - 1];
+    auto* requests = new MPI_Request[size - 1];
     int index = 0;
     for (int dst = 0; dst < size; dst++) {
       if (dst != root) {
@@ -428,8 +436,8 @@ int Colls::iscatterv(const void *sendbuf, const int *sendcounts, const int *disp
   return MPI_SUCCESS;
 }
 
-int Colls::ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,
-                     MPI_Comm comm, MPI_Request* request, int external)
+int colls::ireduce(const void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,
+                   MPI_Comm comm, MPI_Request* request, int external)
 {
   const int system_tag = COLL_TAG_REDUCE-external;
   MPI_Aint lb = 0;
@@ -460,7 +468,7 @@ int Colls::ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d
 
   if(rank != root) {
     // Send buffer to root
-    MPI_Request* requests = new MPI_Request[1];
+    auto* requests        = new MPI_Request[1];
     requests[0]           = Request::isend(real_sendbuf, count, datatype, root, system_tag, comm);
     (*request)->set_nbc_requests(requests, 1);
   } else {
@@ -469,7 +477,7 @@ int Colls::ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d
     if (real_sendbuf != nullptr && recvbuf != nullptr)
       Datatype::copy(real_sendbuf, count, datatype, recvbuf, count, datatype);
     // Receive buffers from senders
-    MPI_Request *requests = new MPI_Request[size - 1];
+    auto* requests = new MPI_Request[size - 1];
     int index = 0;
     for (int src = 0; src < size; src++) {
       if (src != root) {
@@ -488,8 +496,8 @@ int Colls::ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d
   return MPI_SUCCESS;
 }
 
-int Colls::iallreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
-                      MPI_Op op, MPI_Comm comm, MPI_Request* request, int external)
+int colls::iallreduce(const void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
+                      MPI_Request* request, int external)
 {
 
   const int system_tag = COLL_TAG_ALLREDUCE-external;
@@ -505,7 +513,7 @@ int Colls::iallreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatyp
   // Local copy from self
   Datatype::copy(sendbuf, count, datatype, recvbuf, count, datatype);
   // Send/Recv buffers to/from others;
-  MPI_Request* requests = new MPI_Request[2 * (size - 1)];
+  auto* requests = new MPI_Request[2 * (size - 1)];
   int index = 0;
   for (int other = 0; other < size; other++) {
     if(other != rank) {
@@ -521,7 +529,8 @@ int Colls::iallreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatyp
   return MPI_SUCCESS;
 }
 
-int Colls::iscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request* request, int external)
+int colls::iscan(const void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
+                 MPI_Request* request, int external)
 {
   int system_tag = -888-external;
   MPI_Aint lb      = 0;
@@ -537,7 +546,7 @@ int Colls::iscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dat
   Datatype::copy(sendbuf, count, datatype, recvbuf, count, datatype);
 
   // Send/Recv buffers to/from others
-  MPI_Request *requests = new MPI_Request[size - 1];
+  auto* requests = new MPI_Request[size - 1];
   int index = 0;
   for (int other = 0; other < rank; other++) {
     requests[index] = Request::irecv_init(smpi_get_tmp_sendbuffer(count * dataext), count, datatype, other, system_tag, comm);
@@ -553,7 +562,8 @@ int Colls::iscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dat
   return MPI_SUCCESS;
 }
 
-int Colls::iexscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request* request, int external)
+int colls::iexscan(const void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
+                   MPI_Request* request, int external)
 {
   int system_tag = -888-external;
   MPI_Aint lb         = 0;
@@ -567,7 +577,7 @@ int Colls::iexscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d
     memset(recvbuf, 0, count*dataext);
 
   // Send/Recv buffers to/from others
-  MPI_Request *requests = new MPI_Request[size - 1];
+  auto* requests = new MPI_Request[size - 1];
   int index = 0;
   for (int other = 0; other < rank; other++) {
     requests[index] = Request::irecv_init(smpi_get_tmp_sendbuffer(count * dataext), count, datatype, other, system_tag, comm);
@@ -583,9 +593,10 @@ int Colls::iexscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d
   return MPI_SUCCESS;
 }
 
-int Colls::ireduce_scatter(const void *sendbuf, void *recvbuf, const int *recvcounts, MPI_Datatype datatype, MPI_Op op,
-                             MPI_Comm comm, MPI_Request* request, int external){
-//Version where each process performs the reduce for its own part. Alltoall pattern for comms.
+int colls::ireduce_scatter(const void* sendbuf, void* recvbuf, const int* recvcounts, MPI_Datatype datatype, MPI_Op op,
+                           MPI_Comm comm, MPI_Request* request, int external)
+{
+  // Version where each process performs the reduce for its own part. Alltoall pattern for comms.
   const int system_tag = COLL_TAG_REDUCE_SCATTER-external;
   MPI_Aint lb = 0;
   MPI_Aint dataext = 0;
@@ -598,7 +609,7 @@ int Colls::ireduce_scatter(const void *sendbuf, void *recvbuf, const int *recvco
   datatype->extent(&lb, &dataext);
 
   // Send/Recv buffers to/from others;
-  MPI_Request* requests = new MPI_Request[2 * (size - 1)];
+  auto* requests = new MPI_Request[2 * (size - 1)];
   int index = 0;
   int recvdisp=0;
   for (int other = 0; other < size; other++) {