Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix issues with attr and cloning
authoraugustin degomme <adegomme@gmail.com>
Sun, 7 Jun 2020 01:57:30 +0000 (03:57 +0200)
committeraugustin degomme <adegomme@gmail.com>
Sun, 7 Jun 2020 01:57:30 +0000 (03:57 +0200)
src/smpi/bindings/smpi_pmpi_type.cpp
src/smpi/include/smpi_datatype.hpp
src/smpi/include/smpi_datatype_derived.hpp
src/smpi/mpi/smpi_datatype.cpp
src/smpi/mpi/smpi_datatype_derived.cpp

index 74cd22d..056316c 100644 (file)
@@ -77,7 +77,7 @@ int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
   int retval = MPI_SUCCESS;
   CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype)
-  *newtype = datatype->clone();
+  retval = datatype->clone(newtype);
   //error when duplicating, free the new datatype
   if(retval!=MPI_SUCCESS){
     simgrid::smpi::Datatype::unref(*newtype);
index 5e387ba..48316ee 100644 (file)
@@ -130,6 +130,7 @@ public:
   void ref();
   static void unref(MPI_Datatype datatype);
   void commit();
+  int copy_attrs(Datatype* datatype);
   bool is_valid();
   bool is_basic();
   static const char* encode(const Datatype* dt) { return dt->id.c_str(); }
@@ -142,7 +143,7 @@ public:
   void set_name(const char* name);
   static int copy(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
                   MPI_Datatype recvtype);
-  virtual MPI_Datatype clone();
+  virtual int clone(MPI_Datatype* type);
   virtual void serialize(const void* noncontiguous, void* contiguous, int count);
   virtual void unserialize(const void* contiguous, void* noncontiguous, int count, MPI_Op op);
   static int keyval_create(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
index 845bd50..707b47c 100644 (file)
@@ -21,7 +21,7 @@ public:
   Type_Contiguous(const Type_Contiguous&) = delete;
   Type_Contiguous& operator=(const Type_Contiguous&) = delete;
   ~Type_Contiguous();
-  Type_Contiguous* clone() override;
+  int clone(MPI_Datatype* type) override;
   void serialize(const void* noncontiguous, void* contiguous, int count) override;
   void unserialize(const void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op) override;
 };
@@ -39,7 +39,7 @@ public:
   Type_Hvector(const Type_Hvector&) = delete;
   Type_Hvector& operator=(const Type_Hvector&) = delete;
   ~Type_Hvector();
-  Type_Hvector* clone() override;
+  int clone(MPI_Datatype* type) override;
   void serialize(const void* noncontiguous, void* contiguous, int count) override;
   void unserialize(const void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op) override;
 };
@@ -48,7 +48,7 @@ class Type_Vector : public Type_Hvector {
 public:
   Type_Vector(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, int blocklen, int stride,
               MPI_Datatype old_type);
-  Type_Vector* clone() override;
+  int clone(MPI_Datatype* type) override;
 };
 
 class Type_Hindexed: public Datatype{
@@ -65,7 +65,7 @@ public:
                 MPI_Datatype old_type, MPI_Aint factor);
   Type_Hindexed(const Type_Hindexed&) = delete;
   Type_Hindexed& operator=(const Type_Hindexed&) = delete;
-  Type_Hindexed* clone() override;
+  int clone(MPI_Datatype* type) override;
   ~Type_Hindexed();
   void serialize(const void* noncontiguous, void* contiguous, int count) override;
   void unserialize(const void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op) override;
@@ -75,7 +75,7 @@ class Type_Indexed : public Type_Hindexed {
 public:
   Type_Indexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, const int* block_lengths, const int* block_indices,
                MPI_Datatype old_type);
-  Type_Indexed* clone() override;
+  int clone(MPI_Datatype* type) override;
 };
 
 class Type_Struct: public Datatype{
@@ -89,7 +89,7 @@ public:
               const MPI_Aint* block_indices, const MPI_Datatype* old_types);
   Type_Struct(const Type_Struct&) = delete;
   Type_Struct& operator=(const Type_Struct&) = delete;
-  Type_Struct* clone() override;
+  int clone(MPI_Datatype* type) override;
   ~Type_Struct();
   void serialize(const void* noncontiguous, void* contiguous, int count) override;
   void unserialize(const void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op) override;
index df3e3d0..5422b5d 100644 (file)
@@ -130,8 +130,30 @@ Datatype::Datatype(char* name, int ident, int size, MPI_Aint lb, MPI_Aint ub, in
 Datatype::Datatype(Datatype* datatype, int* ret)
     : size_(datatype->size_), lb_(datatype->lb_), ub_(datatype->ub_), flags_(datatype->flags_)
 {
+  *ret = this->copy_attrs(datatype);
+}
+
+Datatype::~Datatype()
+{
+  xbt_assert(refcount_ >= 0);
+
+  if(flags_ & DT_FLAG_PREDEFINED)
+    return;
+
+  //if still used, mark for deletion
+  if(refcount_!=0){
+      flags_ |=DT_FLAG_DESTROYED;
+      return;
+  }
+
+  cleanup_attr<Datatype>();
+  delete contents_;
+  xbt_free(name_);
+}
+
+int Datatype::copy_attrs(Datatype* datatype){
   flags_ &= ~DT_FLAG_PREDEFINED;
-  *ret = MPI_SUCCESS;
+  int ret = MPI_SUCCESS;
     
   if (not datatype->attributes()->empty()) {
     int flag=0;
@@ -141,13 +163,13 @@ Datatype::Datatype(Datatype* datatype, int* ret)
       if (elem != nullptr){
         if( elem->copy_fn.type_copy_fn != MPI_NULL_COPY_FN && 
             elem->copy_fn.type_copy_fn != MPI_TYPE_DUP_FN)
-          *ret = elem->copy_fn.type_copy_fn(datatype, it.first, elem->extra_state, it.second, &value_out, &flag);
+          ret = elem->copy_fn.type_copy_fn(datatype, it.first, elem->extra_state, it.second, &value_out, &flag);
         else if ( elem->copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN &&
                   (*(int*)*elem->copy_fn.type_copy_fn_fort) != 1){
           value_out=(int*)xbt_malloc(sizeof(int));
-          elem->copy_fn.type_copy_fn_fort(datatype, it.first, elem->extra_state, it.second, value_out, &flag,ret);
+          elem->copy_fn.type_copy_fn_fort(datatype, it.first, elem->extra_state, it.second, value_out, &flag, &ret);
         }
-        if (*ret != MPI_SUCCESS) {
+        if (ret != MPI_SUCCESS) {
           break;
         }
         if(elem->copy_fn.type_copy_fn == MPI_TYPE_DUP_FN || 
@@ -162,29 +184,13 @@ Datatype::Datatype(Datatype* datatype, int* ret)
     }
   }
   contents_ = new Datatype_contents(MPI_COMBINER_DUP, 0, nullptr, 0, nullptr, 1, &datatype);
+  return ret;
 }
 
-Datatype::~Datatype()
-{
-  xbt_assert(refcount_ >= 0);
-
-  if(flags_ & DT_FLAG_PREDEFINED)
-    return;
-
-  //if still used, mark for deletion
-  if(refcount_!=0){
-      flags_ |=DT_FLAG_DESTROYED;
-      return;
-  }
-
-  cleanup_attr<Datatype>();
-  delete contents_;
-  xbt_free(name_);
-}
-
-MPI_Datatype Datatype::clone(){
-  int ret = MPI_SUCCESS;
-  return new Datatype(this, &ret);
+int Datatype::clone(MPI_Datatype* type){
+  int ret;
+  *type = new Datatype(this, &ret);
+  return ret;
 }
 
 void Datatype::ref()
index bf6392b..55deb44 100644 (file)
@@ -53,9 +53,11 @@ Type_Contiguous::~Type_Contiguous()
   Datatype::unref(old_type_);
 }
 
-Type_Contiguous* Type_Contiguous::clone()
+int Type_Contiguous::clone(MPI_Datatype* type)
 {
-  return new Type_Contiguous(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->old_type_);
+  *type = new Type_Contiguous(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->old_type_);
+  (*type)->copy_attrs(this);
+  return MPI_SUCCESS;
 }
 
 void Type_Contiguous::serialize(const void* noncontiguous_buf, void* contiguous_buf, int count)
@@ -83,9 +85,11 @@ Type_Hvector::~Type_Hvector(){
   Datatype::unref(old_type_);
 }
 
-Type_Hvector* Type_Hvector::clone()
+int Type_Hvector::clone(MPI_Datatype* type)
 {
-  return new Type_Hvector(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_length_, this->block_stride_, this->old_type_);
+  *type = new Type_Hvector(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_length_, this->block_stride_, this->old_type_);
+  (*type)->copy_attrs(this);
+  return MPI_SUCCESS;
 }
 
 void Type_Hvector::serialize(const void* noncontiguous_buf, void *contiguous_buf,
@@ -135,9 +139,11 @@ Type_Vector::Type_Vector(int size, MPI_Aint lb, MPI_Aint ub, int flags, int coun
   contents_ = new Datatype_contents(MPI_COMBINER_VECTOR, 3, ints, 0, nullptr, 1, &old_type);
 }
 
-Type_Vector* Type_Vector::clone()
+int Type_Vector::clone(MPI_Datatype* type)
 {
-  return new Type_Vector(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_length_, this->block_stride_, this->old_type_);
+  *type = new Type_Vector(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_length_, this->block_stride_, this->old_type_);
+  (*type)->copy_attrs(this);
+  return MPI_SUCCESS;
 }
 
 Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths,
@@ -176,9 +182,11 @@ Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int
   }
 }
 
-Type_Hindexed* Type_Hindexed::clone()
+int Type_Hindexed::clone(MPI_Datatype* type)
 {
-  return new Type_Hindexed(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_lengths_, this->block_indices_, this->old_type_);
+  *type = new Type_Hindexed(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_lengths_, this->block_indices_, this->old_type_);
+  (*type)->copy_attrs(this);
+  return MPI_SUCCESS;
 }
 
 Type_Hindexed::~Type_Hindexed()
@@ -250,9 +258,11 @@ Type_Indexed::Type_Indexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int co
   delete[] ints;
 }
 
-Type_Indexed* Type_Indexed::clone()
-{
-  return new Type_Indexed(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_lengths_, (int*)(this->block_indices_), this->old_type_);
+int Type_Indexed::clone(MPI_Datatype* type)
+{ 
+  *type = new Type_Indexed(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_lengths_, (int*)(this->block_indices_), this->old_type_);
+  (*type)->copy_attrs(this);
+  return MPI_SUCCESS;
 }
 
 Type_Struct::Type_Struct(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths,
@@ -288,9 +298,11 @@ Type_Struct::~Type_Struct(){
   }
 }
 
-Type_Struct* Type_Struct::clone()
+int Type_Struct::clone(MPI_Datatype* type)
 {
-  return new Type_Struct(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_lengths_, this->block_indices_, this->old_types_);
+  *type = new Type_Struct(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_lengths_, this->block_indices_, this->old_types_);
+  (*type)->copy_attrs(this);
+  return MPI_SUCCESS;
 }
 
 void Type_Struct::serialize(const void* noncontiguous_buf, void *contiguous_buf,