Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change malloc/free to new/delete.
[simgrid.git] / src / smpi / colls / gather / gather-mvapich.cpp
index 79b7035..48946ed 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.hpp"
+#include <algorithm>
 
 #define MPIR_Gather_MV2_Direct Coll_gather_ompi_basic_linear::gather
 #define MPIR_Gather_MV2_two_level_Direct Coll_gather_ompi_basic_linear::gather
 #define MPIR_Gather_intra Coll_gather_mpich::gather
-typedef int (*MV2_Gather_function_ptr) (void *sendbuf,
+typedef int (*MV2_Gather_function_ptr) (const void *sendbuf,
     int sendcnt,
     MPI_Datatype sendtype,
     void *recvbuf,
@@ -79,7 +80,7 @@ namespace smpi{
  *                      intra node gather function
  * errflag           - (out) to record errors
  */
-static int MPIR_pt_pt_intra_gather( void *sendbuf, int sendcnt, MPI_Datatype sendtype,
+static int MPIR_pt_pt_intra_gather( const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
                             void *recvbuf, int recvcnt, MPI_Datatype recvtype,
                             int root, int rank,
                             void *tmp_buf, int nbytes,
@@ -126,7 +127,7 @@ static int MPIR_pt_pt_intra_gather( void *sendbuf, int sendcnt, MPI_Datatype sen
 
 
 
-int Coll_gather_mvapich2_two_level::gather(void *sendbuf,
+int Coll_gather_mvapich2_two_level::gather(const void *sendbuf,
                                             int sendcnt,
                                             MPI_Datatype sendtype,
                                             void *recvbuf,
@@ -223,12 +224,9 @@ int Coll_gather_mvapich2_two_level::gather(void *sendbuf,
         if (local_rank == 0) {
             /* Node leader, allocate tmp_buffer */
             if (rank == root) {
-                tmp_buf = smpi_get_tmp_recvbuffer(recvcnt * MAX(recvtype_extent,
-                            recvtype_true_extent) * local_size);
+              tmp_buf = smpi_get_tmp_recvbuffer(recvcnt * std::max(recvtype_extent, recvtype_true_extent) * local_size);
             } else {
-                tmp_buf = smpi_get_tmp_sendbuffer(sendcnt * MAX(sendtype_extent,
-                            sendtype_true_extent) *
-                        local_size);
+              tmp_buf = smpi_get_tmp_sendbuffer(sendcnt * std::max(sendtype_extent, sendtype_true_extent) * local_size);
             }
             if (tmp_buf == NULL) {
                 mpi_errno = MPI_ERR_OTHER;
@@ -291,10 +289,10 @@ int Coll_gather_mvapich2_two_level::gather(void *sendbuf,
            * is the same as leader_root */
           if (rank == root) {
             leader_gather_buf =
-                smpi_get_tmp_recvbuffer(recvcnt * MAX(recvtype_extent, recvtype_true_extent) * comm_size);
+                smpi_get_tmp_recvbuffer(recvcnt * std::max(recvtype_extent, recvtype_true_extent) * comm_size);
           } else {
             leader_gather_buf =
-                smpi_get_tmp_sendbuffer(sendcnt * MAX(sendtype_extent, sendtype_true_extent) * comm_size);
+                smpi_get_tmp_sendbuffer(sendcnt * std::max(sendtype_extent, sendtype_true_extent) * comm_size);
           }
           if (leader_gather_buf == NULL) {
             mpi_errno = MPI_ERR_OTHER;
@@ -305,12 +303,8 @@ int Coll_gather_mvapich2_two_level::gather(void *sendbuf,
         node_sizes = comm->get_non_uniform_map();
 
         if (leader_comm_rank == leader_root) {
-          displs   = static_cast<int*>(xbt_malloc(sizeof(int) * leader_comm_size));
-          recvcnts = static_cast<int*>(xbt_malloc(sizeof(int) * leader_comm_size));
-          if (not displs || not recvcnts) {
-            mpi_errno = MPI_ERR_OTHER;
-            return mpi_errno;
-          }
+          displs   = new int[leader_comm_size];
+          recvcnts = new int[leader_comm_size];
         }
 
         if (root == leader_of_root) {
@@ -344,8 +338,8 @@ int Coll_gather_mvapich2_two_level::gather(void *sendbuf,
                          leader_root, leader_comm);
         }
         if (leader_comm_rank == leader_root) {
-          xbt_free(displs);
-          xbt_free(recvcnts);
+          delete[] displs;
+          delete[] recvcnts;
         }
       }
     } else {