Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / smpi / colls / allgather / allgather-2dmesh.cpp
index 21be3ac..1189a1d 100644 (file)
@@ -1,10 +1,10 @@
-/* Copyright (c) 2013-2014. 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"
 
 /*****************************************************************************
 
@@ -53,7 +53,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
  * Function: is_2dmesh
 
- * Return: int
+ * Return: bool
 
  * Inputs:
      num: the number of processors in a communicator
@@ -62,14 +62,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
  * Descp: takes a number and tries to find a factoring of x, y mesh out of it
 
- * Auther: Ahmad Faraj
+ * Author: Ahmad Faraj
  ****************************************************************************/
 #ifndef TWOD
 #define TWOD
-static int is_2dmesh(int num, int *i, int *j)
+static bool is_2dmesh(int num, int* i, int* j)
 {
   int x, max = num / 2;
-  x = sqrt(num);
+  x = sqrt(double(num));
 
   while (x <= max) {
     if ((num % x) == 0) {
@@ -82,11 +82,11 @@ static int is_2dmesh(int num, int *i, int *j)
         *j = x;
       }
 
-      return 1;
+      return true;
     }
     x++;
   }
-  return 0;
+  return false;
 }
 #endif
 /*****************************************************************************
@@ -101,16 +101,20 @@ static int is_2dmesh(int num, int *i, int *j)
  * comm: communication
  * Descrp: Function realizes the allgather operation using the 2dmesh
  * algorithm. Allgather ommunication occurs first in the x dimension then in
- * the y dimension.  The communication in each dimension follows 
+ * the y dimension.  The communication in each dimension follows
  * "simple"
- * Auther: Ahmad Faraj
+ * Author: Ahmad Faraj
 ****************************************************************************/
+
+namespace simgrid{
+namespace smpi{
+
+
 int
-smpi_coll_tuned_allgather_2dmesh(void *send_buff, int send_count, MPI_Datatype
-                                 send_type, void *recv_buff, int recv_count,
-                                 MPI_Datatype recv_type, MPI_Comm comm)
+allgather__2dmesh(const void *send_buff, int send_count, MPI_Datatype
+                  send_type, void *recv_buff, int recv_count,
+                  MPI_Datatype recv_type, MPI_Comm comm)
 {
-  MPI_Request *req, *req_ptr;
   MPI_Aint extent;
 
   int i, src, dst, rank, num_procs;
@@ -125,8 +129,8 @@ smpi_coll_tuned_allgather_2dmesh(void *send_buff, int send_count, MPI_Datatype
 
   block_size = extent * send_count;
 
-  if (!is_2dmesh(num_procs, &X, &Y))
-    THROWF(arg_error,0, "allgather_2dmesh algorithm can't be used with this number of processes! ");
+  if (not is_2dmesh(num_procs, &X, &Y))
+    throw std::invalid_argument("allgather_2dmesh algorithm can't be used with this number of processes!");
 
   my_row_base = (rank / Y) * Y;
   my_col_base = rank % Y;
@@ -135,11 +139,10 @@ smpi_coll_tuned_allgather_2dmesh(void *send_buff, int send_count, MPI_Datatype
   if (Y > X)
     num_reqs = Y;
 
-  req = (MPI_Request *) xbt_malloc(num_reqs * sizeof(MPI_Request));
-
-  req_ptr = req;
+  auto* req            = new MPI_Request[num_reqs];
+  MPI_Request* req_ptr = req;
 
-  // do local allgather/local copy 
+  // do local allgather/local copy
   recv_offset = rank * block_size;
   Datatype::copy(send_buff, send_count, send_type, (char *)recv_buff + recv_offset,
                  recv_count, recv_type);
@@ -188,7 +191,10 @@ smpi_coll_tuned_allgather_2dmesh(void *send_buff, int send_count, MPI_Datatype
 
   Request::waitall(X - 1, req, MPI_STATUSES_IGNORE);
 
-  free(req);
+  delete[] req;
 
   return MPI_SUCCESS;
 }
+
+}
+}