From eef4b77f222102ba1ee0e5cc119e218bdfe9d3b5 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 29 Apr 2019 14:12:06 +0200 Subject: [PATCH] Constify third parameter of smpi::Op::apply, and save a few const_casts. --- src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp | 8 ++++---- src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp | 6 ++++-- src/smpi/include/smpi_op.hpp | 2 +- src/smpi/mpi/smpi_op.cpp | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp b/src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp index a3a1c795c6..1b590b7802 100644 --- a/src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp +++ b/src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp @@ -93,11 +93,11 @@ int Coll_reduce_scatter_mpich_pair::reduce_scatter(const void *sendbuf, void *re if (is_commutative || (src < rank)) { if (sendbuf != MPI_IN_PLACE) { if (op != MPI_OP_NULL) - op->apply(tmp_recvbuf, recvbuf, &((const_cast(recvcounts))[rank]), datatype); + op->apply(tmp_recvbuf, recvbuf, &recvcounts[rank], datatype); } else { if (op != MPI_OP_NULL) - op->apply(tmp_recvbuf, ((char*)recvbuf + disps[rank] * extent), &((const_cast(recvcounts))[rank]), datatype); + op->apply(tmp_recvbuf, ((char*)recvbuf + disps[rank] * extent), &recvcounts[rank], datatype); /* we can't store the result at the beginning of recvbuf right here because there is useful data there that other process/processes need. at the @@ -108,7 +108,7 @@ int Coll_reduce_scatter_mpich_pair::reduce_scatter(const void *sendbuf, void *re else { if (sendbuf != MPI_IN_PLACE) { if (op != MPI_OP_NULL) - op->apply(recvbuf, tmp_recvbuf, &((const_cast(recvcounts))[rank]), datatype); + op->apply(recvbuf, tmp_recvbuf, &recvcounts[rank], datatype); /* copy result back into recvbuf */ mpi_errno = Datatype::copy(tmp_recvbuf, recvcounts[rank], datatype, recvbuf, recvcounts[rank], datatype); @@ -117,7 +117,7 @@ int Coll_reduce_scatter_mpich_pair::reduce_scatter(const void *sendbuf, void *re } else { if (op != MPI_OP_NULL) - op->apply(((char*)recvbuf + disps[rank] * extent), tmp_recvbuf, &((const_cast(recvcounts))[rank]), datatype); + op->apply(((char*)recvbuf + disps[rank] * extent), tmp_recvbuf, &recvcounts[rank], datatype); /* copy result back into recvbuf */ mpi_errno = Datatype::copy(tmp_recvbuf, recvcounts[rank], datatype, ((char*)recvbuf + disps[rank] * extent), recvcounts[rank], datatype); diff --git a/src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp b/src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp index 3a7eb3715b..bcd2dce83d 100644 --- a/src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp +++ b/src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp @@ -483,7 +483,8 @@ Coll_reduce_scatter_ompi_ring::reduce_scatter(const void *sbuf, void *rbuf, cons rbuf[prevblock] = inbuf[inbi ^ 0x1] (op) rbuf[prevblock] */ tmprecv = accumbuf + (ptrdiff_t)displs[prevblock] * extent; - if(op!=MPI_OP_NULL) op->apply( inbuf[inbi ^ 0x1], tmprecv, &((const_cast(rcounts))[prevblock]), dtype); + if (op != MPI_OP_NULL) + op->apply(inbuf[inbi ^ 0x1], tmprecv, &rcounts[prevblock], dtype); /* send previous block to send_to */ Request::send(tmprecv, rcounts[prevblock], dtype, send_to, @@ -497,7 +498,8 @@ Coll_reduce_scatter_ompi_ring::reduce_scatter(const void *sbuf, void *rbuf, cons /* Apply operation on the last block (my block) rbuf[rank] = inbuf[inbi] (op) rbuf[rank] */ tmprecv = accumbuf + (ptrdiff_t)displs[rank] * extent; - if(op!=MPI_OP_NULL) op->apply( inbuf[inbi], tmprecv, &((const_cast(rcounts))[rank]), dtype); + if (op != MPI_OP_NULL) + op->apply(inbuf[inbi], tmprecv, &rcounts[rank], dtype); /* Copy result from tmprecv to rbuf */ ret = Datatype::copy(tmprecv, rcounts[rank], dtype, (char*)rbuf, rcounts[rank], dtype); diff --git a/src/smpi/include/smpi_op.hpp b/src/smpi/include/smpi_op.hpp index f483eac897..bae3055430 100644 --- a/src/smpi/include/smpi_op.hpp +++ b/src/smpi/include/smpi_op.hpp @@ -25,7 +25,7 @@ public: bool is_fortran_op() { return is_fortran_op_; } // tell that we were created from fortran, so we need to translate the type to fortran when called void set_fortran_op() { is_fortran_op_ = true; } - void apply(const void* invec, void* inoutvec, int* len, MPI_Datatype datatype); + void apply(const void* invec, void* inoutvec, const int* len, MPI_Datatype datatype); static Op* f2c(int id); void ref(); static void unref(MPI_Op* op); diff --git a/src/smpi/mpi/smpi_op.cpp b/src/smpi/mpi/smpi_op.cpp index 962978cd24..228c3b93ce 100644 --- a/src/smpi/mpi/smpi_op.cpp +++ b/src/smpi/mpi/smpi_op.cpp @@ -219,7 +219,7 @@ CREATE_MPI_OP(MPI_NO_OP, no_func); namespace simgrid{ namespace smpi{ -void Op::apply(const void *invec, void *inoutvec, int *len, MPI_Datatype datatype) +void Op::apply(const void* invec, void* inoutvec, const int* len, MPI_Datatype datatype) { if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP) { // we need to switch as the called function may silently touch global variables @@ -229,13 +229,13 @@ void Op::apply(const void *invec, void *inoutvec, int *len, MPI_Datatype datatyp if (not smpi_process()->replaying() && *len > 0) { if (not is_fortran_op_) - this->func_(const_cast(invec), inoutvec, len, &datatype); + this->func_(const_cast(invec), inoutvec, const_cast(len), &datatype); else{ XBT_DEBUG("Applying operation of length %d from %p and from/to %p", *len, invec, inoutvec); int tmp = datatype->c2f(); /* Unfortunately, the C and Fortran version of the MPI standard do not agree on the type here, thus the reinterpret_cast. */ - this->func_(const_cast(invec), inoutvec, len, reinterpret_cast(&tmp) ); + this->func_(const_cast(invec), inoutvec, const_cast(len), reinterpret_cast(&tmp)); } } } -- 2.20.1