Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a refcount for MPI_Op
authorAugustin Degomme <adegomme@users.noreply.github.com>
Mon, 1 Apr 2019 19:08:05 +0000 (21:08 +0200)
committerAugustin Degomme <adegomme@users.noreply.github.com>
Mon, 1 Apr 2019 22:46:45 +0000 (00:46 +0200)
src/smpi/bindings/smpi_pmpi_op.cpp
src/smpi/include/smpi_op.hpp
src/smpi/include/smpi_request.hpp
src/smpi/mpi/smpi_op.cpp
src/smpi/mpi/smpi_request.cpp

index 6b3bd32..505914e 100644 (file)
@@ -27,7 +27,7 @@ int PMPI_Op_free(MPI_Op * op)
   } else if (*op == MPI_OP_NULL) {
     return MPI_ERR_OP;
   } else {
-    delete (*op);
+    simgrid::smpi::Op::unref(op);
     *op = MPI_OP_NULL;
     return MPI_SUCCESS;
   }
index 5354177..c0eb212 100644 (file)
@@ -16,6 +16,7 @@ class Op : public F2C{
   MPI_User_function* func_;
   bool is_commutative_;
   bool is_fortran_op_ = false;
+  int refcount_ = 1;
 
 public:
   Op(MPI_User_function* function, bool commutative) : func_(function), is_commutative_(commutative) {}
@@ -25,6 +26,8 @@ public:
   void set_fortran_op() { is_fortran_op_ = true; }
   void apply(void* invec, void* inoutvec, int* len, MPI_Datatype datatype);
   static Op* f2c(int id);
+  void ref();
+  static void unref(MPI_Op* op);
 };
 
 }
index fa9e7dd..a4fa0d5 100644 (file)
@@ -54,7 +54,7 @@ class Request : public F2C {
 
 public:
   Request() = default;
-  Request(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags);
+  Request(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags, MPI_Op op = MPI_REPLACE);
   MPI_Comm comm() { return comm_; }
   size_t size() { return size_; }
   size_t real_size() { return real_size_; }
index e81b93f..bb52d0e 100644 (file)
@@ -242,5 +242,17 @@ Op* Op::f2c(int id){
   return static_cast<Op*>(F2C::f2c(id));
 }
 
+void Op::ref(){
+  refcount_++;
+}
+
+void Op::unref(MPI_Op* op){
+  if((*op)!=MPI_OP_NULL){
+    (*op)->refcount_--;
+    if((*op)->refcount_==0)
+      delete(*op);
+  }
+}
+
 }
 }
index 30c21a4..0762073 100644 (file)
@@ -36,8 +36,8 @@ extern void (*smpi_comm_copy_data_callback)(simgrid::kernel::activity::CommImpl*
 namespace simgrid{
 namespace smpi{
 
-Request::Request(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags)
-    : buf_(buf), old_type_(datatype), src_(src), dst_(dst), tag_(tag), comm_(comm), flags_(flags)
+Request::Request(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags, MPI_Op op)
+    : buf_(buf), old_type_(datatype), src_(src), dst_(dst), tag_(tag), comm_(comm), flags_(flags), op_(op)
 {
   void *old_buf = nullptr;
 // FIXME Handle the case of a partial shared malloc.
@@ -58,6 +58,8 @@ Request::Request(void* buf, int count, MPI_Datatype datatype, int src, int dst,
   size_ = datatype->size() * count;
   datatype->ref();
   comm_->ref();
+  if(op != MPI_REPLACE && op != MPI_OP_NULL)
+    op_->ref();
   action_          = nullptr;
   detached_        = 0;
   detached_sender_ = nullptr;
@@ -69,7 +71,6 @@ Request::Request(void* buf, int count, MPI_Datatype datatype, int src, int dst,
     refcount_ = 1;
   else
     refcount_ = 0;
-  op_   = MPI_REPLACE;
   cancelled_ = 0;
   generalized_funcs=nullptr;
   nbc_requests_=nullptr;
@@ -95,6 +96,9 @@ void Request::unref(MPI_Request* request)
         Comm::unref((*request)->comm_);
         Datatype::unref((*request)->old_type_);
       }
+      if ((*request)->op_!=MPI_REPLACE && (*request)->op_!=MPI_OP_NULL)
+        Op::unref(&(*request)->op_);
+
       (*request)->print_request("Destroying");
       delete *request;
       *request = MPI_REQUEST_NULL;
@@ -201,8 +205,7 @@ MPI_Request Request::rma_send_init(void *buf, int count, MPI_Datatype datatype,
     request      = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, comm->group()->actor(src)->get_pid(),
                           comm->group()->actor(dst)->get_pid(), tag, comm,
                           MPI_REQ_RMA | MPI_REQ_NON_PERSISTENT | MPI_REQ_ISEND | MPI_REQ_SEND | MPI_REQ_PREPARED |
-                              MPI_REQ_ACCUMULATE);
-    request->op_ = op;
+                              MPI_REQ_ACCUMULATE, op);
   }
   return request;
 }
@@ -226,8 +229,7 @@ MPI_Request Request::rma_recv_init(void *buf, int count, MPI_Datatype datatype,
   }else{
     request      = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, comm->group()->actor(src)->get_pid(),
                           comm->group()->actor(dst)->get_pid(), tag, comm,
-                          MPI_REQ_RMA | MPI_REQ_NON_PERSISTENT | MPI_REQ_RECV | MPI_REQ_PREPARED | MPI_REQ_ACCUMULATE);
-    request->op_ = op;
+                          MPI_REQ_RMA | MPI_REQ_NON_PERSISTENT | MPI_REQ_RECV | MPI_REQ_PREPARED | MPI_REQ_ACCUMULATE, op);
   }
   return request;
 }