Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / smpi / colls / allgather / allgather-mvapich-smp.cpp
index 993efea..18725e3 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2019. The SimGrid Team.
+/* Copyright (c) 2013-2023. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  *      See COPYRIGHT in top-level directory.
  */
 #include "../colls_private.hpp"
-namespace simgrid{
-namespace smpi{
+namespace simgrid::smpi {
 
-int Coll_allgather_mvapich2_smp::allgather(const void *sendbuf,int sendcnt, MPI_Datatype sendtype,
+int allgather__mvapich2_smp(const void *sendbuf,int sendcnt, MPI_Datatype sendtype,
                             void *recvbuf, int recvcnt,MPI_Datatype recvtype,
                             MPI_Comm  comm)
 {
@@ -54,10 +53,12 @@ int Coll_allgather_mvapich2_smp::allgather(const void *sendbuf,int sendcnt, MPI_
   }
 
   if (not comm->is_uniform() || not comm->is_blocked())
-    THROWF(arg_error,0, "allgather MVAPICH2 smp algorithm can't be used with irregular deployment. Please insure that processes deployed on the same node are contiguous and that each node has the same number of processes");
+    throw std::invalid_argument("allgather MVAPICH2 smp algorithm can't be used with irregular deployment. Please "
+                                "insure that processes deployed on the same node are contiguous and that each node has "
+                                "the same number of processes");
 
-    if (recvcnt == 0) {
-        return MPI_SUCCESS;
+  if (recvcnt == 0) {
+    return MPI_SUCCESS;
     }
 
     rank = comm->rank();
@@ -82,61 +83,51 @@ int Coll_allgather_mvapich2_smp::allgather(const void *sendbuf,int sendcnt, MPI_
     /*If there is just one node, after gather itself,
      * root has all the data and it can do bcast*/
     if(local_rank == 0) {
-        mpi_errno = Colls::gather(sendbuf, sendcnt,sendtype,
-                                    (void*)((char*)recvbuf + (rank * recvcnt * recvtype_extent)),
-                                     recvcnt, recvtype,
-                                     0, shmem_comm);
+      mpi_errno =
+          colls::gather(sendbuf, sendcnt, sendtype, (void*)((char*)recvbuf + (rank * recvcnt * recvtype_extent)),
+                        recvcnt, recvtype, 0, shmem_comm);
     } else {
         /*Since in allgather all the processes could have
          * its own data in place*/
         if(sendbuf == MPI_IN_PLACE) {
-            mpi_errno = Colls::gather((void*)((char*)recvbuf + (rank * recvcnt * recvtype_extent)),
-                                         recvcnt , recvtype,
-                                         recvbuf, recvcnt, recvtype,
-                                         0, shmem_comm);
+          mpi_errno = colls::gather((void*)((char*)recvbuf + (rank * recvcnt * recvtype_extent)), recvcnt, recvtype,
+                                    recvbuf, recvcnt, recvtype, 0, shmem_comm);
         } else {
-            mpi_errno = Colls::gather(sendbuf, sendcnt,sendtype,
-                                         recvbuf, recvcnt, recvtype,
-                                         0, shmem_comm);
+          mpi_errno = colls::gather(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, recvtype, 0, shmem_comm);
         }
     }
     /* Exchange the data between the node leaders*/
     if (local_rank == 0 && (leader_comm_size > 1)) {
         /*When data in each socket is different*/
-        if (comm->is_uniform() != 1) {
+        if (not comm->is_uniform()) {
 
-            int *node_sizes = NULL;
-            int i = 0;
+          int* node_sizes = nullptr;
+          int i           = 0;
 
-            node_sizes = comm->get_non_uniform_map();
+          node_sizes = comm->get_non_uniform_map();
 
-            int* displs   = new int[leader_comm_size];
-            int* recvcnts = new int[leader_comm_size];
-            recvcnts[0] = node_sizes[0] * recvcnt;
-            displs[0] = 0;
+          int* displs   = new int[leader_comm_size];
+          int* recvcnts = new int[leader_comm_size];
+          recvcnts[0]   = node_sizes[0] * recvcnt;
+          displs[0]     = 0;
 
-            for (i = 1; i < leader_comm_size; i++) {
-                displs[i] = displs[i - 1] + node_sizes[i - 1] * recvcnt;
-                recvcnts[i] = node_sizes[i] * recvcnt;
-            }
+          for (i = 1; i < leader_comm_size; i++) {
+            displs[i]   = displs[i - 1] + node_sizes[i - 1] * recvcnt;
+            recvcnts[i] = node_sizes[i] * recvcnt;
+          }
 
+          void* sendtmpbuf = ((char*)recvbuf) + recvtype->get_extent() * displs[leader_comm->rank()];
 
-            void* sendbuf=((char*)recvbuf)+recvtype->get_extent()*displs[leader_comm->rank()];
-
-            mpi_errno = Colls::allgatherv(sendbuf,
-                                       (recvcnt*local_size),
-                                       recvtype,
-                                       recvbuf, recvcnts,
-                                       displs, recvtype,
-                                       leader_comm);
-            delete[] displs;
-            delete[] recvcnts;
+          mpi_errno = colls::allgatherv(sendtmpbuf, (recvcnt * local_size), recvtype, recvbuf, recvcnts, displs,
+                                        recvtype, leader_comm);
+          delete[] displs;
+          delete[] recvcnts;
         } else {
         void* sendtmpbuf=((char*)recvbuf)+recvtype->get_extent()*(recvcnt*local_size)*leader_comm->rank();
 
 
 
-            mpi_errno = Coll_allgather_mpich::allgather(sendtmpbuf,
+            mpi_errno = allgather__mpich(sendtmpbuf,
                                                (recvcnt*local_size),
                                                recvtype,
                                                recvbuf, (recvcnt*local_size), recvtype,
@@ -146,9 +137,8 @@ int Coll_allgather_mvapich2_smp::allgather(const void *sendbuf,int sendcnt, MPI_
     }
 
     /*Bcast the entire data from node leaders to all other cores*/
-    mpi_errno = Colls::bcast (recvbuf, recvcnt * size, recvtype, 0, shmem_comm);
+    mpi_errno = colls::bcast(recvbuf, recvcnt * size, recvtype, 0, shmem_comm);
     return mpi_errno;
 }
 
-}
-}
+} // namespace simgrid::smpi