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 = new simgrid::smpi::Datatype(datatype, &retval);
+ *newtype = datatype->clone();
//error when duplicating, free the new datatype
if(retval!=MPI_SUCCESS){
simgrid::smpi::Datatype::unref(*newtype);
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 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();
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;
};
class Type_Hvector: public Datatype{
+public:
int block_count_;
int block_length_;
MPI_Aint block_stride_;
Type_Hvector(const Type_Hvector&) = delete;
Type_Hvector& operator=(const Type_Hvector&) = delete;
~Type_Hvector();
+ Type_Hvector* clone();
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();
};
class Type_Hindexed: public Datatype{
+public:
int block_count_;
int* block_lengths_;
MPI_Aint* block_indices_;
MPI_Datatype old_type, MPI_Aint factor);
Type_Hindexed(const Type_Hindexed&) = delete;
Type_Hindexed& operator=(const Type_Hindexed&) = delete;
+ Type_Hindexed* clone();
~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();
};
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();
~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;
xbt_free(name_);
}
+MPI_Datatype Datatype::clone(){
+ int ret = MPI_SUCCESS;
+ return new Datatype(this, &ret);
+}
+
void Datatype::ref()
{
refcount_++;
Datatype::unref(old_type_);
}
+Type_Contiguous* Type_Contiguous::clone()
+{
+ return new Type_Contiguous(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->old_type_);
+}
+
void Type_Contiguous::serialize(const void* noncontiguous_buf, void* contiguous_buf, int count)
{
char* contiguous_buf_char = static_cast<char*>(contiguous_buf);
Datatype::unref(old_type_);
}
+Type_Hvector* Type_Hvector::clone()
+{
+ return new Type_Hvector(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_length_, this->block_stride_, this->old_type_);
+}
+
void Type_Hvector::serialize(const void* noncontiguous_buf, void *contiguous_buf,
int count){
char* contiguous_buf_char = static_cast<char*>(contiguous_buf);
contents_ = new Datatype_contents(MPI_COMBINER_VECTOR, 3, ints, 0, nullptr, 1, &old_type);
}
+Type_Vector* Type_Vector::clone()
+{
+ 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_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths,
const MPI_Aint* block_indices, MPI_Datatype old_type)
: Datatype(size, lb, ub, flags)
}
}
+Type_Hindexed* Type_Hindexed::clone()
+{
+ 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_Hindexed::~Type_Hindexed()
{
Datatype::unref(old_type_);
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_);
+}
+
Type_Struct::Type_Struct(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths,
const MPI_Aint* block_indices, const MPI_Datatype* old_types)
: Datatype(size, lb, ub, flags)
}
}
+Type_Struct* Type_Struct::clone()
+{
+ return new Type_Struct(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_lengths_, this->block_indices_, this->old_types_);
+}
void Type_Struct::serialize(const void* noncontiguous_buf, void *contiguous_buf,
int count){
continue;
}
partner = np - 1;
- MPI_Send(MPI_BOTTOM, counts[j], offsettype, partner, tag, comm);
+ MPI_Datatype dup;
+ MPI_Type_dup(offsettype, &dup);
+ MPI_Send(MPI_BOTTOM, counts[j], dup, partner, tag, comm);
MPI_Type_free(&offsettype);
+ MPI_Type_free(&dup);
}
else if (rank == np - 1) {
partner = 0;
MPI_Type_free(&offsettype);
continue;
}
- MPI_Recv(MPI_BOTTOM, counts[j], offsettype, partner, tag, comm, &status);
+ MPI_Datatype dup;
+ MPI_Type_dup(offsettype, &dup);
+ MPI_Recv(MPI_BOTTOM, counts[j], dup, partner, tag, comm, &status);
/* Test for correctness */
MPI_Get_count(&status, types[j], &count);
if (count != counts[j]) {
err++;
}
MPI_Type_free(&offsettype);
+ MPI_Type_free(&dup);
}
}
MTestFreeComm(&comm);