Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / smpi / colls / allgather / allgather-SMP-NTS.cpp
index 0ea5ff7..8a08fe8 100644 (file)
@@ -1,15 +1,18 @@
-/* Copyright (c) 2013-2014. 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
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "../colls_private.h"
+#include "../colls_private.hpp"
+#include "xbt/string.hpp"
 
-int smpi_coll_tuned_allgather_SMP_NTS(void *sbuf, int scount,
-                                      MPI_Datatype stype, void *rbuf,
-                                      int rcount, MPI_Datatype rtype,
-                                      MPI_Comm comm)
+namespace simgrid::smpi {
+
+int allgather__SMP_NTS(const void *sbuf, int scount,
+                       MPI_Datatype stype, void *rbuf,
+                       int rcount, MPI_Datatype rtype,
+                       MPI_Comm comm)
 {
   int src, dst, comm_size, rank;
   comm_size = comm->size();
@@ -37,13 +40,14 @@ int smpi_coll_tuned_allgather_SMP_NTS(void *sbuf, int scount,
   int num_core_in_current_smp = num_core;
 
   if(comm_size%num_core)
-    THROWF(arg_error,0, "allgather SMP NTS algorithm can't be used with non multiple of NUM_CORE=%d number of processes ! ", num_core);
+    throw std::invalid_argument(xbt::string_printf(
+        "allgather SMP NTS algorithm can't be used with non multiple of NUM_CORE=%d number of processes!", num_core));
 
   /* for too small number of processes, use default implementation */
   if (comm_size <= num_core) {
-    XBT_WARN("MPI_allgather_SMP_NTS use default MPI_allgather.");        
-    smpi_mpi_allgather(sbuf, scount, stype, rbuf, rcount, rtype, comm);
-    return MPI_SUCCESS;    
+    XBT_INFO("MPI_allgather_SMP_NTS: comm_size <= num_core, use default MPI_allgather.");
+    allgather__default(sbuf, scount, stype, rbuf, rcount, rtype, comm);
+    return MPI_SUCCESS;
   }
 
   // the last SMP node may have fewer number of running processes than all others
@@ -74,14 +78,14 @@ int smpi_coll_tuned_allgather_SMP_NTS(void *sbuf, int scount,
 
   }
 
-  // INTER-SMP-ALLGATHER 
+  // INTER-SMP-ALLGATHER
   // Every root of each SMP node post INTER-Sendrecv, then do INTRA-Bcast for each receiving message
   // Use logical ring algorithm
 
   // root of each SMP
   if (intra_rank == 0) {
-    MPI_Request *rrequest_array = xbt_new(MPI_Request, inter_comm_size - 1);
-    MPI_Request *srequest_array = xbt_new(MPI_Request, inter_comm_size - 1);
+    auto* rrequest_array = new MPI_Request[inter_comm_size - 1];
+    auto* srequest_array = new MPI_Request[inter_comm_size - 1];
 
     src = ((inter_rank - 1 + inter_comm_size) % inter_comm_size) * num_core;
     dst = ((inter_rank + 1) % inter_comm_size) * num_core;
@@ -129,8 +133,8 @@ int smpi_coll_tuned_allgather_SMP_NTS(void *sbuf, int scount,
     }
 
     Request::waitall(inter_comm_size - 1, srequest_array, MPI_STATUSES_IGNORE);
-    xbt_free(rrequest_array);
-    xbt_free(srequest_array);
+    delete[] rrequest_array;
+    delete[] srequest_array;
   }
   // last rank of each SMP
   else if (intra_rank == (num_core_in_current_smp - 1)) {
@@ -157,3 +161,5 @@ int smpi_coll_tuned_allgather_SMP_NTS(void *sbuf, int scount,
 
   return MPI_SUCCESS;
 }
+
+} // namespace simgrid::smpi