Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / smpi / colls / alltoall / alltoall-bruck.cpp
index 9c0e30cd2ae6117303e246401b6e1935a01df69c..21248d09f0b34764ff9d69c924aaece9a6506edb 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
 
  * Descrp: Function realizes the alltoall operation using the bruck algorithm.
 
- * Auther: MPICH / modified by Ahmad Faraj
+ * Author: MPICH / modified by Ahmad Faraj
 
  ****************************************************************************/
+
+#include "../colls_private.hpp"
+
+namespace simgrid::smpi {
+
 int
-smpi_coll_tuned_alltoall_bruck(void *send_buff, int send_count,
-                               MPI_Datatype send_type, void *recv_buff,
-                               int recv_count, MPI_Datatype recv_type,
-                               MPI_Comm comm)
+alltoall__bruck(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_Status status;
   MPI_Aint extent;
   MPI_Datatype new_type;
 
-  int *blocks_length, *disps;
-  int i, src, dst, rank, num_procs, count, remainder, block, position;
+  int i, src, dst, rank, num_procs, count, block, position;
   int pack_size, tag = COLL_TAG_ALLTOALL, pof2 = 1;
 
-
-  char *tmp_buff;
   char *send_ptr = (char *) send_buff;
   char *recv_ptr = (char *) recv_buff;
 
@@ -48,9 +50,9 @@ smpi_coll_tuned_alltoall_bruck(void *send_buff, int send_count,
 
   extent = recv_type->get_extent();
 
-  tmp_buff = (char *) smpi_get_tmp_sendbuffer(num_procs * recv_count * extent);
-  disps = (int *) xbt_malloc(sizeof(int) * num_procs);
-  blocks_length = (int *) xbt_malloc(sizeof(int) * num_procs);
+  unsigned char* tmp_buff = smpi_get_tmp_sendbuffer(num_procs * recv_count * extent);
+  int* disps         = new int[num_procs];
+  int* blocks_length = new int[num_procs];
 
   Request::sendrecv(send_ptr + rank * send_count * extent,
                (num_procs - rank) * send_count, send_type, rank, tag,
@@ -79,7 +81,7 @@ smpi_coll_tuned_alltoall_bruck(void *send_buff, int send_count,
       }
 
     MPI_Type_indexed(count, blocks_length, disps, recv_type, &new_type);
-    smpi_datatype_commit(&new_type);
+    new_type->commit();
 
     position = 0;
     MPI_Pack(recv_buff, 1, new_type, tmp_buff, pack_size, &position, comm);
@@ -91,8 +93,8 @@ smpi_coll_tuned_alltoall_bruck(void *send_buff, int send_count,
     pof2 *= 2;
   }
 
-  free(disps);
-  free(blocks_length);
+  delete[] disps;
+  delete[] blocks_length;
 
   Request::sendrecv(recv_ptr + (rank + 1) * recv_count * extent,
                (num_procs - rank - 1) * recv_count, send_type,
@@ -113,3 +115,5 @@ smpi_coll_tuned_alltoall_bruck(void *send_buff, int send_count,
   smpi_free_tmp_buffer(tmp_buff);
   return MPI_SUCCESS;
 }
+
+} // namespace simgrid::smpi