Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / smpi / colls / reduce / reduce-mvapich-knomial.cpp
index 2ab0774..05da851 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2017. The SimGrid Team.
+/* Copyright (c) 2013-2021. 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;
 
@@ -55,7 +57,7 @@ static int MPIR_Reduce_knomial_trace(int root, int reduce_knomial_factor,
     int mask=0x1, k, comm_size, src, rank, relative_rank, lroot=0;
     int orig_mask=0x1;
     int recv_iter=0, send_iter=0;
-    int *knomial_reduce_src_array=NULL;
+    int* knomial_reduce_src_array = nullptr;
     comm_size =  comm->size();
     rank = comm->rank();
 
@@ -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;
@@ -114,10 +116,10 @@ static int MPIR_Reduce_knomial_trace(int root, int reduce_knomial_factor,
     return 0;
 }
 
-namespace simgrid{
-namespace smpi{
-int Coll_reduce_mvapich2_knomial::reduce (
-        void *sendbuf,
+namespace simgrid {
+namespace smpi {
+int reduce__mvapich2_knomial(
+        const void *sendbuf,
         void *recvbuf,
         int count,
         MPI_Datatype datatype,
@@ -126,17 +128,14 @@ int Coll_reduce_mvapich2_knomial::reduce (
         MPI_Comm comm)
 {
     int mpi_errno = MPI_SUCCESS;
-    int rank, is_commutative;
+    int rank;
     int src, k;
     MPI_Request send_request;
     int index=0;
     MPI_Aint true_lb, true_extent, extent;
     MPI_Status status;
     int recv_iter=0, dst=-1, expected_send_count, expected_recv_count;
-    int *src_array=NULL;
-    void **tmp_buf=NULL;
-    MPI_Request *requests=NULL;
-
+    int* src_array = nullptr;
 
     if (count == 0) return MPI_SUCCESS;
 
@@ -147,10 +146,10 @@ int Coll_reduce_mvapich2_knomial::reduce (
     datatype->extent(&true_lb, &true_extent);
     extent = datatype->get_extent();
 
-    is_commutative =  (op==MPI_OP_NULL || op->is_commutative());
+    bool 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);
     }
 
@@ -174,11 +173,11 @@ int Coll_reduce_mvapich2_knomial::reduce (
            &dst, &expected_send_count, &expected_recv_count, &src_array);
 
     if(expected_recv_count > 0 ) {
-        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] = (void *)((char*)tmp_buf[k] - true_lb);
+      auto** tmp_buf = new unsigned char*[expected_recv_count];
+      auto* requests = new MPI_Request[expected_recv_count];
+      for (k = 0; k < expected_recv_count; k++) {
+        tmp_buf[k] = smpi_get_tmp_sendbuffer(count * std::max(extent, true_extent));
+        tmp_buf[k] = tmp_buf[k] - true_lb;
         }
 
         while(recv_iter  < expected_recv_count) {
@@ -204,12 +203,12 @@ int Coll_reduce_mvapich2_knomial::reduce (
         for(k=0; k < expected_recv_count; k++ ) {
             smpi_free_tmp_buffer(tmp_buf[k]);
         }
-        xbt_free(tmp_buf);
-        xbt_free(requests);
+        delete[] tmp_buf;
+        delete[] requests;
     }
 
-    if(src_array != NULL) {
-        xbt_free(src_array);
+    if (src_array != nullptr) {
+      delete[] src_array;
     }
 
     if(rank != root) {
@@ -218,7 +217,7 @@ int Coll_reduce_mvapich2_knomial::reduce (
 
         Request::waitall(1, &send_request, &status);
 
-        smpi_free_tmp_buffer((void *)((char*)recvbuf + true_lb));
+        smpi_free_tmp_buffer(static_cast<unsigned char*>(recvbuf) + true_lb);
     }
 
     /* --END ERROR HANDLING-- */