diff --git a/src/core/math/Matrix3.h b/src/core/math/Matrix3.h index 27a29b9450d6c9d95630440b7ffc346d6e0fa630..fe3c0e00cac880cb6d59b29af401e87226dc7c92 100644 --- a/src/core/math/Matrix3.h +++ b/src/core/math/Matrix3.h @@ -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 diff --git a/src/core/math/Vector2.h b/src/core/math/Vector2.h index 1ad6f9cab05d9eda80a0684d736e5921ba26b5d0..145bf302fb636ab269fbc8930c4fd74d5bf4844b 100644 --- a/src/core/math/Vector2.h +++ b/src/core/math/Vector2.h @@ -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; diff --git a/src/core/math/Vector3.h b/src/core/math/Vector3.h index f5b1ea819cff09f5813a162574ee318ab8bd7fa7..662d2dfa59c9d32eb89efdac064f01d03437b568 100644 --- a/src/core/math/Vector3.h +++ b/src/core/math/Vector3.h @@ -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;