3#ifndef DUNE_MPITRAITS_HH
4#define DUNE_MPITRAITS_HH
43 static MPI_Datatype datatype;
44 static MPI_Datatype vectortype;
46 static inline MPI_Datatype getType()
48 if(datatype==MPI_DATATYPE_NULL) {
49 MPI_Type_contiguous(
sizeof(T),MPI_BYTE,&datatype);
50 MPI_Type_commit(&datatype);
54 static constexpr bool is_intrinsic =
false;
62#define ComposeMPITraits(p,m) \
64 struct MPITraits<p>{ \
65 static inline MPI_Datatype getType(){ \
68 static constexpr bool is_intrinsic = true; \
71 ComposeMPITraits(
char, MPI_CHAR);
72 ComposeMPITraits(
unsigned char,MPI_UNSIGNED_CHAR);
73 ComposeMPITraits(
short,MPI_SHORT);
74 ComposeMPITraits(
unsigned short,MPI_UNSIGNED_SHORT);
75 ComposeMPITraits(
int,MPI_INT);
76 ComposeMPITraits(
unsigned int,MPI_UNSIGNED);
77 ComposeMPITraits(
long,MPI_LONG);
78 ComposeMPITraits(
unsigned long,MPI_UNSIGNED_LONG);
79 ComposeMPITraits(
float,MPI_FLOAT);
80 ComposeMPITraits(
double,MPI_DOUBLE);
81 ComposeMPITraits(
long double,MPI_LONG_DOUBLE);
82 ComposeMPITraits(std::complex<double>, MPI_CXX_DOUBLE_COMPLEX);
83 ComposeMPITraits(std::complex<long double>, MPI_CXX_LONG_DOUBLE_COMPLEX);
84 ComposeMPITraits(std::complex<float>, MPI_CXX_FLOAT_COMPLEX);
87#undef ComposeMPITraits
91 template<
class K,
int n>
94 static MPI_Datatype datatype;
95 static MPI_Datatype vectortype;
97 static inline MPI_Datatype getType()
99 if(datatype==MPI_DATATYPE_NULL) {
101 MPI_Type_commit(&vectortype);
105 MPI_Get_address(&fvector, &base);
106 MPI_Get_address(&(fvector[0]), &displ);
110 MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype);
111 MPI_Type_commit(&datatype);
118 template<
class K,
int n>
119 MPI_Datatype MPITraits<FieldVector<K,n> >::datatype = MPI_DATATYPE_NULL;
120 template<
class K,
int n>
121 MPI_Datatype MPITraits<FieldVector<K,n> >::vectortype = {MPI_DATATYPE_NULL};
125 class bigunsignedint;
128 struct MPITraits<bigunsignedint<k> >
130 static MPI_Datatype datatype;
131 static MPI_Datatype vectortype;
133 static inline MPI_Datatype getType()
135 if(datatype==MPI_DATATYPE_NULL) {
136 MPI_Type_contiguous(bigunsignedint<k>::n, MPITraits<std::uint16_t>::getType(),
139 bigunsignedint<k> data;
142 MPI_Get_address(&data, &base);
143 MPI_Get_address(&(data.digit), &displ);
146 MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype);
147 MPI_Type_commit(&datatype);
157 MPI_Datatype MPITraits<bigunsignedint<k> >::datatype = MPI_DATATYPE_NULL;
159 MPI_Datatype MPITraits<bigunsignedint<k> >::vectortype = MPI_DATATYPE_NULL;
161 template<
typename T1,
typename T2>
162 struct MPITraits<
std::pair<T1,T2 > >
165 inline static MPI_Datatype getType();
167 static MPI_Datatype type;
169 template<
typename T1,
typename T2>
170 MPI_Datatype MPITraits<std::pair<T1,T2> >::getType()
172 if(type==MPI_DATATYPE_NULL) {
173 int length[2] = {1, 1};
175 MPI_Datatype types[2] = {MPITraits<T1>::getType(),
176 MPITraits<T2>::getType()};
178 using Pair = std::pair<T1, T2>;
179 static_assert(std::is_standard_layout<Pair>::value,
"offsetof() is only defined for standard layout types");
180 disp[0] = offsetof(Pair, first);
181 disp[1] = offsetof(Pair, second);
184 MPI_Type_create_struct(2, length, disp, types, &tmp);
186 MPI_Type_create_resized(tmp, 0,
sizeof(Pair), &type);
187 MPI_Type_commit(&type);
194 template<
typename T1,
typename T2>
195 MPI_Datatype MPITraits<std::pair<T1,T2> >::type=MPI_DATATYPE_NULL;
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Dune namespace.
Definition: alignedallocator.hh:11
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:39