Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove another bunch of const_casts.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 29 Apr 2019 09:14:19 +0000 (11:14 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 29 Apr 2019 14:08:52 +0000 (16:08 +0200)
src/smpi/colls/allreduce/allreduce-rab2.cpp
src/smpi/colls/gather/gather-ompi.cpp
src/smpi/colls/reduce/reduce-ompi.cpp
src/smpi/colls/smpi_mpich_selector.cpp
src/smpi/colls/smpi_nbc_impl.cpp
src/smpi/colls/smpi_openmpi_selector.cpp

index 0a45358..1381fa5 100644 (file)
@@ -17,7 +17,6 @@ int Coll_allreduce_rab2::allreduce(const void *sbuff, void *rbuff,
   MPI_Aint s_extent;
   int i, rank, nprocs;
   int nbytes, send_size, s_offset, r_offset;
   MPI_Aint s_extent;
   int i, rank, nprocs;
   int nbytes, send_size, s_offset, r_offset;
-  void *recv, *send, *tmp;
   /*
      #ifdef MPICH2_REDUCTION
      MPI_User_function * uop = MPIR_Op_table[op % 16 - 1];
   /*
      #ifdef MPICH2_REDUCTION
      MPI_User_function * uop = MPIR_Op_table[op % 16 - 1];
@@ -42,9 +41,9 @@ int Coll_allreduce_rab2::allreduce(const void *sbuff, void *rbuff,
       send_size = (count + nprocs) / nprocs;
     nbytes = send_size * s_extent;
 
       send_size = (count + nprocs) / nprocs;
     nbytes = send_size * s_extent;
 
-    send = (void *) smpi_get_tmp_sendbuffer(s_extent * send_size * nprocs);
-    recv = (void *) smpi_get_tmp_recvbuffer(s_extent * send_size * nprocs);
-    tmp = (void *) smpi_get_tmp_sendbuffer(nbytes);
+    void* send = smpi_get_tmp_sendbuffer(s_extent * send_size * nprocs);
+    void* recv = smpi_get_tmp_recvbuffer(s_extent * send_size * nprocs);
+    void* tmp  = smpi_get_tmp_sendbuffer(nbytes);
 
     memcpy(send, sbuff, s_extent * count);
 
 
     memcpy(send, sbuff, s_extent * count);
 
@@ -62,12 +61,12 @@ int Coll_allreduce_rab2::allreduce(const void *sbuff, void *rbuff,
     smpi_free_tmp_buffer(tmp);
     smpi_free_tmp_buffer(send);
   } else {
     smpi_free_tmp_buffer(tmp);
     smpi_free_tmp_buffer(send);
   } else {
-    send = const_cast<void*>(sbuff);
+    const void* send = sbuff;
     send_size = count / nprocs;
     nbytes = send_size * s_extent;
     r_offset = rank * nbytes;
 
     send_size = count / nprocs;
     nbytes = send_size * s_extent;
     r_offset = rank * nbytes;
 
-    recv = (void *) smpi_get_tmp_recvbuffer(s_extent * send_size * nprocs);
+    void* recv = smpi_get_tmp_recvbuffer(s_extent * send_size * nprocs);
 
     Colls::alltoall(send, send_size, dtype, recv, send_size, dtype, comm);
 
 
     Colls::alltoall(send, send_size, dtype, recv, send_size, dtype, comm);
 
index c81c7b8..1546bd3 100644 (file)
@@ -247,7 +247,7 @@ int Coll_gather_ompi_linear_sync::gather(const void *sbuf, int scount,
        first_segment_count = scount;
        COLL_TUNED_COMPUTED_SEGCOUNT((size_t)first_segment_size, typelng, first_segment_count);
 
        first_segment_count = scount;
        COLL_TUNED_COMPUTED_SEGCOUNT((size_t)first_segment_size, typelng, first_segment_count);
 
-       Request::recv(const_cast<void*>(sbuf), 0, MPI_BYTE, root, COLL_TAG_GATHER, comm, MPI_STATUS_IGNORE);
+       Request::recv(nullptr, 0, MPI_BYTE, root, COLL_TAG_GATHER, comm, MPI_STATUS_IGNORE);
 
        Request::send(sbuf, first_segment_count, sdtype, root, COLL_TAG_GATHER, comm);
 
 
        Request::send(sbuf, first_segment_count, sdtype, root, COLL_TAG_GATHER, comm);
 
index ad11934..98f6047 100644 (file)
@@ -482,7 +482,6 @@ int Coll_reduce_ompi_in_order_binary::reduce(const void *sendbuf, void *recvbuf,
     int ret;
     int rank, size, io_root;
     int segcount = count;
     int ret;
     int rank, size, io_root;
     int segcount = count;
-    void *use_this_sendbuf = NULL, *use_this_recvbuf = NULL;
     size_t typelng;
 
     rank = comm->rank();
     size_t typelng;
 
     rank = comm->rank();
@@ -504,30 +503,29 @@ int Coll_reduce_ompi_in_order_binary::reduce(const void *sendbuf, void *recvbuf,
        operations for non-commutative ops.
     */
     io_root = size - 1;
        operations for non-commutative ops.
     */
     io_root = size - 1;
-    use_this_sendbuf = const_cast<void*>(sendbuf);
-    use_this_recvbuf = recvbuf;
+    const void* use_this_sendbuf = sendbuf;
+    void* use_this_recvbuf       = recvbuf;
+    void* tmp_sendbuf            = nullptr;
+    void* tmp_recvbuf            = nullptr;
     if (io_root != root) {
         ptrdiff_t text, ext;
     if (io_root != root) {
         ptrdiff_t text, ext;
-        char *tmpbuf = NULL;
 
         ext=datatype->get_extent();
         text=datatype->get_extent();
 
         if ((root == rank) && (MPI_IN_PLACE == sendbuf)) {
 
         ext=datatype->get_extent();
         text=datatype->get_extent();
 
         if ((root == rank) && (MPI_IN_PLACE == sendbuf)) {
-            tmpbuf = (char *) smpi_get_tmp_sendbuffer(text + (count - 1) * ext);
-            if (NULL == tmpbuf) {
-                return MPI_ERR_INTERN;
-            }
-            Datatype::copy (
-                                                (char*)recvbuf, count, datatype,
-                                                (char*)tmpbuf, count, datatype);
-            use_this_sendbuf = tmpbuf;
+          tmp_sendbuf = smpi_get_tmp_sendbuffer(text + (count - 1) * ext);
+          if (NULL == tmp_sendbuf) {
+            return MPI_ERR_INTERN;
+          }
+          Datatype::copy(recvbuf, count, datatype, tmp_sendbuf, count, datatype);
+          use_this_sendbuf = tmp_sendbuf;
         } else if (io_root == rank) {
         } else if (io_root == rank) {
-            tmpbuf = (char *) smpi_get_tmp_recvbuffer(text + (count - 1) * ext);
-            if (NULL == tmpbuf) {
-                return MPI_ERR_INTERN;
-            }
-            use_this_recvbuf = tmpbuf;
+          tmp_recvbuf = smpi_get_tmp_recvbuffer(text + (count - 1) * ext);
+          if (NULL == tmp_recvbuf) {
+            return MPI_ERR_INTERN;
+          }
+          use_this_recvbuf = tmp_recvbuf;
         }
     }
 
         }
     }
 
@@ -546,7 +544,7 @@ int Coll_reduce_ompi_in_order_binary::reduce(const void *sendbuf, void *recvbuf,
                                     COLL_TAG_REDUCE, comm,
                                     MPI_STATUS_IGNORE);
             if (MPI_IN_PLACE == sendbuf) {
                                     COLL_TAG_REDUCE, comm,
                                     MPI_STATUS_IGNORE);
             if (MPI_IN_PLACE == sendbuf) {
-              smpi_free_tmp_buffer(use_this_sendbuf);
+              smpi_free_tmp_buffer(tmp_sendbuf);
             }
 
         } else if (io_root == rank) {
             }
 
         } else if (io_root == rank) {
@@ -554,7 +552,7 @@ int Coll_reduce_ompi_in_order_binary::reduce(const void *sendbuf, void *recvbuf,
             Request::send(use_this_recvbuf, count, datatype, root,
                                     COLL_TAG_REDUCE,
                                     comm);
             Request::send(use_this_recvbuf, count, datatype, root,
                                     COLL_TAG_REDUCE,
                                     comm);
-            smpi_free_tmp_buffer(use_this_recvbuf);
+            smpi_free_tmp_buffer(tmp_recvbuf);
         }
     }
 
         }
     }
 
index 5e0dd82..11de914 100644 (file)
@@ -710,18 +710,14 @@ int Coll_scatter_mpich::scatter(const void *sbuf, int scount,
                                             int root, MPI_Comm  comm
                                             )
 {
                                             int root, MPI_Comm  comm
                                             )
 {
+  std::unique_ptr<unsigned char[]> tmp_buf;
   if(comm->rank()!=root){
   if(comm->rank()!=root){
-      sbuf=xbt_malloc(rcount*rdtype->get_extent());
-      scount=rcount;
-      sdtype=rdtype;
+    tmp_buf.reset(new unsigned char[rcount * rdtype->get_extent()]);
+    sbuf   = tmp_buf.get();
+    scount = rcount;
+    sdtype = rdtype;
   }
   }
-  int ret= Coll_scatter_ompi_binomial::scatter (sbuf, scount, sdtype,
-                                                       rbuf, rcount, rdtype,
-                                                       root, comm);
-  if(comm->rank()!=root){
-      xbt_free(const_cast<void*>(sbuf));
-  }
-  return ret;
+  return Coll_scatter_ompi_binomial::scatter(sbuf, scount, sdtype, rbuf, rcount, rdtype, root, comm);
 }
 }
 }
 }
 }
 }
index 4193b13..eed0380 100644 (file)
@@ -433,7 +433,7 @@ int Colls::ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d
   MPI_Aint lb = 0;
   MPI_Aint dataext = 0;
 
   MPI_Aint lb = 0;
   MPI_Aint dataext = 0;
 
-  void* sendtmpbuf = const_cast<void *>(sendbuf);
+  const void* real_sendbuf = sendbuf;
 
   int rank = comm->rank();
   int size = comm->size();
 
   int rank = comm->rank();
   int size = comm->size();
@@ -441,9 +441,11 @@ int Colls::ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d
   if (size <= 0)
     return MPI_ERR_COMM;
 
   if (size <= 0)
     return MPI_ERR_COMM;
 
+  void* tmp_sendbuf = nullptr;
   if( sendbuf == MPI_IN_PLACE ) {
   if( sendbuf == MPI_IN_PLACE ) {
-    sendtmpbuf = static_cast<void *>(smpi_get_tmp_sendbuffer(count*datatype->get_extent()));
-    Datatype::copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
+    tmp_sendbuf = smpi_get_tmp_sendbuffer(count * datatype->get_extent());
+    Datatype::copy(recvbuf, count, datatype, tmp_sendbuf, count, datatype);
+    real_sendbuf = tmp_sendbuf;
   }
 
   if(rank == root){
   }
 
   if(rank == root){
@@ -457,13 +459,13 @@ int Colls::ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d
   if(rank != root) {
     // Send buffer to root
     MPI_Request* requests = new MPI_Request[1];
   if(rank != root) {
     // Send buffer to root
     MPI_Request* requests = new MPI_Request[1];
-    requests[0]=Request::isend(sendtmpbuf, count, datatype, root, system_tag, comm);
+    requests[0]           = Request::isend(real_sendbuf, count, datatype, root, system_tag, comm);
     (*request)->set_nbc_requests(requests, 1);
   } else {
     datatype->extent(&lb, &dataext);
     // Local copy from root
     (*request)->set_nbc_requests(requests, 1);
   } else {
     datatype->extent(&lb, &dataext);
     // Local copy from root
-    if (sendtmpbuf != nullptr && recvbuf != nullptr)
-      Datatype::copy(sendtmpbuf, count, datatype, recvbuf, count, datatype);
+    if (real_sendbuf != nullptr && recvbuf != nullptr)
+      Datatype::copy(real_sendbuf, count, datatype, recvbuf, count, datatype);
     // Receive buffers from senders
     MPI_Request *requests = new MPI_Request[size - 1];
     int index = 0;
     // Receive buffers from senders
     MPI_Request *requests = new MPI_Request[size - 1];
     int index = 0;
@@ -479,7 +481,7 @@ int Colls::ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d
     (*request)->set_nbc_requests(requests, size - 1);
   }    
   if( sendbuf == MPI_IN_PLACE ) {
     (*request)->set_nbc_requests(requests, size - 1);
   }    
   if( sendbuf == MPI_IN_PLACE ) {
-    smpi_free_tmp_buffer(sendtmpbuf);
+    smpi_free_tmp_buffer(tmp_sendbuf);
   }
   return MPI_SUCCESS;
 }
   }
   return MPI_SUCCESS;
 }
index 3d8134d..3461709 100644 (file)
@@ -595,18 +595,14 @@ int Coll_scatter_ompi::scatter(const void *sbuf, int scount,
 
     if ((communicator_size > small_comm_size) &&
         (block_size < small_block_size)) {
 
     if ((communicator_size > small_comm_size) &&
         (block_size < small_block_size)) {
-        if(rank!=root){
-            sbuf=xbt_malloc(rcount*rdtype->get_extent());
-            scount=rcount;
-            sdtype=rdtype;
-        }
-        int ret=Coll_scatter_ompi_binomial::scatter (sbuf, scount, sdtype,
-            rbuf, rcount, rdtype,
-            root, comm);
-        if(rank!=root){
-            xbt_free(const_cast<void*>(sbuf));
-        }
-        return ret;
+      std::unique_ptr<unsigned char[]> tmp_buf;
+      if (rank != root) {
+        tmp_buf.reset(new unsigned char[rcount * rdtype->get_extent()]);
+        sbuf   = tmp_buf.get();
+        scount = rcount;
+        sdtype = rdtype;
+      }
+      return Coll_scatter_ompi_binomial::scatter(sbuf, scount, sdtype, rbuf, rcount, rdtype, root, comm);
     }
     return Coll_scatter_ompi_basic_linear::scatter (sbuf, scount, sdtype,
                                                        rbuf, rcount, rdtype,
     }
     return Coll_scatter_ompi_basic_linear::scatter (sbuf, scount, sdtype,
                                                        rbuf, rcount, rdtype,