Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change malloc/free to new/delete.
[simgrid.git] / src / smpi / colls / allreduce / allreduce-mvapich-rs.cpp
index cc9e89b..1a74de8 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2017. The SimGrid Team.
+/* Copyright (c) 2013-2019. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  *
  */
 
-#include "../colls_private.h"
+#include "../colls_private.hpp"
+#include <algorithm>
+
 namespace simgrid{
 namespace smpi{
-int Coll_allreduce_mvapich2_rs::allreduce(void *sendbuf,
+int Coll_allreduce_mvapich2_rs::allreduce(const void *sendbuf,
                             void *recvbuf,
                             int count,
                             MPI_Datatype datatype,
@@ -33,8 +35,7 @@ int Coll_allreduce_mvapich2_rs::allreduce(void *sendbuf,
     int mpi_errno = MPI_SUCCESS;
     int newrank = 0;
     int mask, pof2, i, send_idx, recv_idx, last_idx, send_cnt;
-    int dst, is_commutative, rem, newdst,
-        recv_cnt, *cnts, *disps;
+    int dst, is_commutative, rem, newdst, recv_cnt;
     MPI_Aint true_lb, true_extent, extent;
     void *tmp_buf, *tmp_buf_free;
 
@@ -53,7 +54,7 @@ int Coll_allreduce_mvapich2_rs::allreduce(void *sendbuf,
     datatype->extent(&true_lb, &true_extent);
     extent = datatype->get_extent();
 
-    tmp_buf_free= smpi_get_tmp_recvbuffer(count * (MAX(extent, true_extent)));
+    tmp_buf_free = smpi_get_tmp_recvbuffer(count * std::max(extent, true_extent));
 
     /* adjust for potential negative lower bound in datatype */
     tmp_buf = (void *) ((char *) tmp_buf_free - true_lb);
@@ -150,8 +151,8 @@ int Coll_allreduce_mvapich2_rs::allreduce(void *sendbuf,
             /* for the reduce-scatter, calculate the count that
                each process receives and the displacement within
                the buffer */
-            cnts = (int *)xbt_malloc(pof2 * sizeof (int));
-            disps = (int *)xbt_malloc(pof2 * sizeof (int));
+            int* cnts  = new int[pof2];
+            int* disps = new int[pof2];
 
             for (i = 0; i < (pof2 - 1); i++) {
                 cnts[i] = count / pof2;
@@ -265,8 +266,8 @@ int Coll_allreduce_mvapich2_rs::allreduce(void *sendbuf,
 
                 mask >>= 1;
             }
-            xbt_free(disps);
-            xbt_free(cnts);
+            delete[] disps;
+            delete[] cnts;
         }
     }