Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix mismatched alloc/free.
[simgrid.git] / src / smpi / colls / reduce / reduce-mvapich-knomial.cpp
index 2ab0774..13454c2 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
@@ -38,7 +38,9 @@
  *
  */
 
-#include "../colls_private.h"
+#include "../colls_private.hpp"
+#include <algorithm>
+
 extern int mv2_reduce_intra_knomial_factor;
 extern int mv2_reduce_inter_knomial_factor;
 
@@ -90,7 +92,7 @@ static int MPIR_Reduce_knomial_trace(int root, int reduce_knomial_factor,
 
     /* Finally, fill up the src array */
     if(recv_iter > 0) {
-        knomial_reduce_src_array = static_cast<int*>(smpi_get_tmp_sendbuffer(sizeof(int)*recv_iter));
+      knomial_reduce_src_array = new int[recv_iter];
     }
 
     mask = orig_mask;
@@ -150,7 +152,7 @@ int Coll_reduce_mvapich2_knomial::reduce (
     is_commutative =  (op==MPI_OP_NULL || op->is_commutative());
 
     if (rank != root) {
-        recvbuf=(void *)smpi_get_tmp_recvbuffer(count*(MAX(extent,true_extent)));
+        recvbuf = (void*)smpi_get_tmp_recvbuffer(count * std::max(extent, true_extent));
         recvbuf = (void *)((char*)recvbuf - true_lb);
     }
 
@@ -177,7 +179,7 @@ int Coll_reduce_mvapich2_knomial::reduce (
         tmp_buf  = static_cast<void**>(xbt_malloc(sizeof(void *)*expected_recv_count));
         requests = static_cast<MPI_Request*>(xbt_malloc(sizeof(MPI_Request)*expected_recv_count));
         for(k=0; k < expected_recv_count; k++ ) {
-            tmp_buf[k] = smpi_get_tmp_sendbuffer(count*(MAX(extent,true_extent)));
+            tmp_buf[k] = smpi_get_tmp_sendbuffer(count * std::max(extent, true_extent));
             tmp_buf[k] = (void *)((char*)tmp_buf[k] - true_lb);
         }
 
@@ -209,7 +211,7 @@ int Coll_reduce_mvapich2_knomial::reduce (
     }
 
     if(src_array != NULL) {
-        xbt_free(src_array);
+      delete[] src_array;
     }
 
     if(rank != root) {