Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Constify third parameter of smpi::Op::apply, and save a few const_casts.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 29 Apr 2019 12:12:06 +0000 (14:12 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 29 Apr 2019 14:08:52 +0000 (16:08 +0200)
src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp
src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp
src/smpi/include/smpi_op.hpp
src/smpi/mpi/smpi_op.cpp

index a3a1c79..1b590b7 100644 (file)
@@ -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)
             if (is_commutative || (src < rank)) {
                 if (sendbuf != MPI_IN_PLACE) {
                   if (op != MPI_OP_NULL)
-                    op->apply(tmp_recvbuf, recvbuf, &((const_cast<int*>(recvcounts))[rank]), datatype);
+                    op->apply(tmp_recvbuf, recvbuf, &recvcounts[rank], datatype);
                 }
                 else {
                   if (op != MPI_OP_NULL)
                 }
                 else {
                   if (op != MPI_OP_NULL)
-                    op->apply(tmp_recvbuf, ((char*)recvbuf + disps[rank] * extent), &((const_cast<int*>(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
                   /* 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)
             else {
                 if (sendbuf != MPI_IN_PLACE) {
                   if (op != MPI_OP_NULL)
-                    op->apply(recvbuf, tmp_recvbuf, &((const_cast<int*>(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);
                   /* 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)
                 }
                 else {
                   if (op != MPI_OP_NULL)
-                    op->apply(((char*)recvbuf + disps[rank] * extent), tmp_recvbuf, &((const_cast<int*>(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);
                   /* copy result back into recvbuf */
                   mpi_errno = Datatype::copy(tmp_recvbuf, recvcounts[rank], datatype,
                                              ((char*)recvbuf + disps[rank] * extent), recvcounts[rank], datatype);
index 3a7eb37..bcd2dce 100644 (file)
@@ -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;
            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<int*>(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,
 
         /* 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;
     /* 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<int*>(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);
 
     /* Copy result from tmprecv to rbuf */
     ret = Datatype::copy(tmprecv, rcounts[rank], dtype, (char*)rbuf, rcounts[rank], dtype);
index f483eac..bae3055 100644 (file)
@@ -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; }
   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);
   static Op* f2c(int id);
   void ref();
   static void unref(MPI_Op* op);
index 962978c..228c3b9 100644 (file)
@@ -219,7 +219,7 @@ CREATE_MPI_OP(MPI_NO_OP, no_func);
 namespace simgrid{
 namespace smpi{
 
 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
 {
   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_)
 
   if (not smpi_process()->replaying() && *len > 0) {
     if (not is_fortran_op_)
-      this->func_(const_cast<void*>(invec), inoutvec, len, &datatype);
+      this->func_(const_cast<void*>(invec), inoutvec, const_cast<int*>(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. */
     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<void*>(invec), inoutvec, len, reinterpret_cast<MPI_Datatype*>(&tmp) );
+      this->func_(const_cast<void*>(invec), inoutvec, const_cast<int*>(len), reinterpret_cast<MPI_Datatype*>(&tmp));
     }
   }
 }
     }
   }
 }