Commit 7934e8f5 authored by Michael Kuron's avatar Michael Kuron
Browse files

Don’t call MPI_Type_free after MPI_Finalize

Vector2, Vector3 and Matrix3 define their own MPITrait::type functions that return an MPI_Datatype for them. It is created the first time the function is called and put into a static variable. It is therefore destroyed after the main() function exits, which is usually after MPI_Finalize has been called. Freeing the MPI_Datatype is therefore not possible and mpi::datatype cannot be used.
parent b82da6d8
......@@ -1839,3 +1839,30 @@ namespace mpi {
};
}
}
//======================================================================================================================
//
// MPI Datatype
//
//======================================================================================================================
namespace walberla {
template< typename T>
struct MPITrait< Matrix3<T> >
{
static inline MPI_Datatype type()
{
// cannot use mpi::Datatype here because its destructor calls MPI_Type_free and static variables are destroyed after the MPI_Finalize
static MPI_Datatype datatype;
static bool initialized = false;
if( ! initialized ) {
MPI_Type_contiguous(9, MPITrait<T>::type(), &datatype );
MPI_Type_commit( &datatype );
initialized = true;
}
return datatype;
}
};
} // namespace walberla
......@@ -1696,13 +1696,13 @@ namespace walberla {
{
static inline MPI_Datatype type()
{
static mpi::Datatype datatype;
// cannot use mpi::Datatype here because its destructor calls MPI_Type_free and static variables are destroyed after the MPI_Finalize
static MPI_Datatype datatype;
static bool initialized = false;
if( ! initialized ) {
MPI_Datatype newDatatype;
MPI_Type_contiguous(2, MPITrait<T>::type(), &newDatatype );
datatype.init( newDatatype );
MPI_Type_contiguous(2, MPITrait<T>::type(), &datatype );
MPI_Type_commit( &datatype );
initialized = true;
}
return datatype;
......
......@@ -1895,13 +1895,13 @@ namespace walberla {
{
static inline MPI_Datatype type()
{
static mpi::Datatype datatype;
// cannot use mpi::Datatype here because its destructor calls MPI_Type_free and static variables are destroyed after the MPI_Finalize
static MPI_Datatype datatype;
static bool initialized = false;
if( ! initialized ) {
MPI_Datatype newDatatype;
MPI_Type_contiguous(3, MPITrait<T>::type(), &newDatatype );
datatype.init( newDatatype );
MPI_Type_contiguous(3, MPITrait<T>::type(), &datatype );
MPI_Type_commit( &datatype );
initialized = true;
}
return datatype;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment