Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
keep track of which datatype was duplicated, to be able to match with it later
authorAugustin Degomme <adegomme@gmail.com>
Wed, 26 May 2021 14:47:22 +0000 (16:47 +0200)
committerAugustin Degomme <adegomme@gmail.com>
Wed, 26 May 2021 14:50:12 +0000 (16:50 +0200)
src/smpi/include/smpi_datatype.hpp
src/smpi/mpi/smpi_datatype.cpp

index 8b7f947..7bd716a 100644 (file)
@@ -109,6 +109,7 @@ class Datatype : public F2C, public Keyval{
   int flags_;
   int refcount_ = 1;
   std::unique_ptr<Datatype_contents> contents_ = nullptr;
+  MPI_Datatype duplicated_datatype_ = MPI_DATATYPE_NULL;
 
 protected:
   template <typename... Args> void set_contents(Args&&... args)
@@ -133,6 +134,7 @@ public:
   MPI_Aint ub() const { return ub_; }
   int flags() const { return flags_; }
   int refcount() const { return refcount_; }
+  MPI_Datatype duplicated_datatype() const { return duplicated_datatype_; }
 
   void ref();
   static void unref(MPI_Datatype datatype);
index 561499f..22a28a3 100644 (file)
@@ -136,9 +136,10 @@ Datatype::Datatype(const char* name, int ident, int size, MPI_Aint lb, MPI_Aint
 }
 
 Datatype::Datatype(Datatype* datatype, int* ret)
-    : size_(datatype->size_), lb_(datatype->lb_), ub_(datatype->ub_), flags_(datatype->flags_)
+    : size_(datatype->size_), lb_(datatype->lb_), ub_(datatype->ub_), flags_(datatype->flags_), duplicated_datatype_(datatype)
 {
   this->add_f();
+  datatype->ref();
   *ret = this->copy_attrs(datatype);
 }
 
@@ -150,6 +151,8 @@ Datatype::~Datatype()
     return;
   //prevent further usage
   flags_ &= ~ DT_FLAG_COMMITED;
+  if(duplicated_datatype_ != MPI_DATATYPE_NULL)
+    unref(duplicated_datatype_);
   F2C::free_f(this->f2c_id());
   //if still used, mark for deletion
   if(refcount_!=0){