/* smpi_datatype.cpp -- MPI primitives to handle datatypes */
-/* Copyright (c) 2009-2020. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2009-2021. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
const MPI_Datatype name = &_XBT_CONCAT(mpi_, name);
// Predefined data types
+CREATE_MPI_DATATYPE_NULL(MPI_DATATYPE_NULL, -1)
+CREATE_MPI_DATATYPE(MPI_DOUBLE, 0, double)
+CREATE_MPI_DATATYPE(MPI_INT, 1, int)
CREATE_MPI_DATATYPE(MPI_CHAR, 2, char)
CREATE_MPI_DATATYPE(MPI_SHORT, 3, short)
-CREATE_MPI_DATATYPE(MPI_INT, 1, int)
CREATE_MPI_DATATYPE(MPI_LONG, 4, long)
+CREATE_MPI_DATATYPE(MPI_FLOAT, 5, float)
+CREATE_MPI_DATATYPE(MPI_BYTE, 6, int8_t)
CREATE_MPI_DATATYPE(MPI_LONG_LONG, 7, long long)
CREATE_MPI_DATATYPE(MPI_SIGNED_CHAR, 8, signed char)
CREATE_MPI_DATATYPE(MPI_UNSIGNED_CHAR, 9, unsigned char)
CREATE_MPI_DATATYPE(MPI_UNSIGNED, 11, unsigned int)
CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG, 12, unsigned long)
CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG_LONG, 13, unsigned long long)
-CREATE_MPI_DATATYPE(MPI_FLOAT, 5, float)
-CREATE_MPI_DATATYPE(MPI_DOUBLE, 0, double)
CREATE_MPI_DATATYPE(MPI_LONG_DOUBLE, 14, long double)
CREATE_MPI_DATATYPE(MPI_WCHAR, 15, wchar_t)
CREATE_MPI_DATATYPE(MPI_C_BOOL, 16, bool)
-CREATE_MPI_DATATYPE(MPI_BYTE, 6, int8_t)
CREATE_MPI_DATATYPE(MPI_INT8_T, 17, int8_t)
CREATE_MPI_DATATYPE(MPI_INT16_T, 18, int16_t)
CREATE_MPI_DATATYPE(MPI_INT32_T, 19, int32_t)
CREATE_MPI_DATATYPE(MPI_REAL4, 39, float)
CREATE_MPI_DATATYPE(MPI_REAL8, 40, double)
CREATE_MPI_DATATYPE(MPI_REAL16, 41, long double)
-CREATE_MPI_DATATYPE_NULL(MPI_DATATYPE_NULL, -1)
CREATE_MPI_DATATYPE(MPI_COMPLEX8, 42, float_float)
CREATE_MPI_DATATYPE(MPI_COMPLEX16, 43, double_double)
CREATE_MPI_DATATYPE(MPI_COMPLEX32, 44, double_double)
// Internal use only
CREATE_MPI_DATATYPE(MPI_PTR, 54, void*)
CREATE_MPI_DATATYPE(MPI_COUNT, 55, long long)
-
+#define NUM_BASIC_DATATYPES 57
namespace simgrid{
namespace smpi{
Datatype::Datatype(int size, MPI_Aint lb, MPI_Aint ub, int flags) : size_(size), lb_(lb), ub_(ub), flags_(flags)
{
+ this->add_f();
#if SIMGRID_HAVE_MC
if(MC_is_active())
MC_ignore(&(refcount_), sizeof(refcount_));
}
// for predefined types, so refcount_ = 0.
-Datatype::Datatype(char* name, int ident, int size, MPI_Aint lb, MPI_Aint ub, int flags)
+Datatype::Datatype(const char* name, int ident, int size, MPI_Aint lb, MPI_Aint ub, int flags)
: name_(name), id(std::to_string(ident)), size_(size), lb_(lb), ub_(ub), flags_(flags), refcount_(0)
{
id2type_lookup.insert({id, this});
Datatype::Datatype(Datatype* datatype, int* ret)
: size_(datatype->size_), lb_(datatype->lb_), ub_(datatype->ub_), flags_(datatype->flags_)
{
+ this->add_f();
*ret = this->copy_attrs(datatype);
}
if(flags_ & DT_FLAG_PREDEFINED)
return;
-
+ //prevent further usage
+ flags_ &= ~ DT_FLAG_COMMITED;
+ F2C::free_f(this->c2f());
//if still used, mark for deletion
if(refcount_!=0){
flags_ |=DT_FLAG_DESTROYED;
return;
}
-
cleanup_attr<Datatype>();
delete contents_;
}
if (datatype->refcount_ > 0)
datatype->refcount_--;
- if (datatype->refcount_ == 0 && not(datatype->flags_ & DT_FLAG_PREDEFINED))
- delete datatype;
-
#if SIMGRID_HAVE_MC
if(MC_is_active())
MC_ignore(&(datatype->refcount_), sizeof(datatype->refcount_));
#endif
+
+ if (datatype->refcount_ == 0 && not(datatype->flags_ & DT_FLAG_PREDEFINED))
+ delete datatype;
}
void Datatype::commit()
void Datatype::get_name(char* name, int* length) const
{
- *length = name_.length();
+ *length = static_cast<int>(name_.length());
if (not name_.empty()) {
name_.copy(name, *length);
name[*length] = '\0';
{
return static_cast<Datatype*>(F2C::f2c(id));
}
+
} // namespace smpi
} // namespace simgrid