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);
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(); }
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,
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;
};
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;
};
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{
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;
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{
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;
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;
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 ||
}
}
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()
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)
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,
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,
}
}
-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()
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,
}
}
-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,