Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / smpi / colls / alltoallv / alltoallv-bruck.cpp
index 41b4abd..f6bc827 100644 (file)
@@ -1,10 +1,10 @@
-/* Copyright (c) 2013-2017. The SimGrid Team.
+/* Copyright (c) 2013-2022. 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. */
 
-#include "../colls_private.h"
+#include "../colls_private.hpp"
 
 /**
  * Alltoall Bruck
  **/
 namespace simgrid{
 namespace smpi{
-int Coll_alltoallv_bruck::alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
-                                   MPI_Datatype sendtype, void *recvbuf,
-                                   int *recvcounts, int *recvdisps, MPI_Datatype recvtype,
-                                   MPI_Comm comm)
+int alltoallv__bruck(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)
 {
   int system_tag = COLL_TAG_ALLTOALLV;
   int i, rank, size, err, count;
   MPI_Aint lb;
   MPI_Aint sendext = 0;
   MPI_Aint recvext = 0;
-  MPI_Request *requests;
 
   // FIXME: check implementation
   rank = comm->rank();
@@ -43,52 +42,47 @@ int Coll_alltoallv_bruck::alltoallv(void *sendbuf, int *sendcounts, int *senddis
   if (err == MPI_SUCCESS && size > 1) {
     /* Initiate all send/recv to/from others. */
 
-      int bblock = 4;//MPIR_PARAM_ALLTOALL_THROTTLE
-      //if (bblock == 0) bblock = comm_size;
+    int bblock = 4; // MPIR_PARAM_ALLTOALL_THROTTLE
+    // if (bblock == 0) bblock = comm_size;
 
+    // MPI_Request* requests = new MPI_Request[2 * (bblock - 1)];
+    int ii, ss, dst;
+    /* post only bblock isends/irecvs at a time as suggested by Tony Ladd */
+    for (ii = 0; ii < size; ii += bblock) {
+      auto* requests = new MPI_Request[2 * bblock];
 
-     // requests = xbt_new(MPI_Request, 2 * (bblock - 1));
-      int ii, ss, dst;
-      /* post only bblock isends/irecvs at a time as suggested by Tony Ladd */
-      for (ii=0; ii<size; ii+=bblock) {
-          requests = xbt_new(MPI_Request, 2 * (bblock ));
+      ss    = size - ii < bblock ? size - ii : bblock;
+      count = 0;
 
-          ss = size-ii < bblock ? size-ii : bblock;
-          count = 0;
-
-          /* do the communication -- post ss sends and receives: */
-          for ( i=0; i<ss; i++ ) {
-            dst = (rank+i+ii) % size;
-              if (dst == rank) {
-                XBT_DEBUG("<%d> skip request creation [src = %d, recvcount = %d]",
-                       rank, i, recvcounts[dst]);
-                continue;
-              }
-
-              requests[count]=Request::irecv((char *)recvbuf + recvdisps[dst] * recvext, recvcounts[dst],
-                                  recvtype, dst, system_tag, comm );
-              count++;
-            }
-            /* Now create all sends  */
-          for ( i=0; i<ss; i++ ) {
-              dst = (rank-i-ii+size) % size;
-              if (dst == rank) {
-                XBT_DEBUG("<%d> skip request creation [dst = %d, sendcount = %d]",
-                       rank, i, sendcounts[dst]);
-                continue;
-              }
-              requests[count]=Request::isend((char *)sendbuf + senddisps[dst] * sendext, sendcounts[dst],
-                                  sendtype, dst, system_tag, comm);
-              count++;
-            }
-            /* Wait for them all. */
-            //Colls::startall(count, requests);
-            XBT_DEBUG("<%d> wait for %d requests", rank, count);
-            Request::waitall(count, requests, MPI_STATUSES_IGNORE);
-            xbt_free(requests);
-
-          }
+      /* do the communication -- post ss sends and receives: */
+      for (i = 0; i < ss; i++) {
+        dst = (rank + i + ii) % size;
+        if (dst == rank) {
+          XBT_DEBUG("<%d> skip request creation [src = %d, recvcount = %d]", rank, i, recvcounts[dst]);
+          continue;
+        }
 
+        requests[count] =
+            Request::irecv((char*)recvbuf + recvdisps[dst] * recvext, recvcounts[dst], recvtype, dst, system_tag, comm);
+        count++;
+      }
+      /* Now create all sends  */
+      for (i = 0; i < ss; i++) {
+        dst = (rank - i - ii + size) % size;
+        if (dst == rank) {
+          XBT_DEBUG("<%d> skip request creation [dst = %d, sendcount = %d]", rank, i, sendcounts[dst]);
+          continue;
+        }
+        requests[count] =
+            Request::isend((char*)sendbuf + senddisps[dst] * sendext, sendcounts[dst], sendtype, dst, system_tag, comm);
+        count++;
+      }
+      /* Wait for them all. */
+      // colls::startall(count, requests);
+      XBT_DEBUG("<%d> wait for %d requests", rank, count);
+      Request::waitall(count, requests, MPI_STATUSES_IGNORE);
+      delete[] requests;
+    }
   }
   return MPI_SUCCESS;
 }