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);
63#define ComposeMPITraits(p,m) \
65 struct MPITraits<p>{ \
66 static inline MPI_Datatype getType(){ \
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);
84#undef ComposeMPITraits
88 template<
class K,
int n>
91 static MPI_Datatype datatype;
92 static MPI_Datatype vectortype;
94 static inline MPI_Datatype getType()
96 if(datatype==MPI_DATATYPE_NULL) {
98 MPI_Type_commit(&vectortype);
102 MPI_Get_address(&fvector, &base);
103 MPI_Get_address(&(fvector[0]), &displ);
107 MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype);
108 MPI_Type_commit(&datatype);
115 template<
class K,
int n>
116 MPI_Datatype MPITraits<FieldVector<K,n> >::datatype = MPI_DATATYPE_NULL;
117 template<
class K,
int n>
118 MPI_Datatype MPITraits<FieldVector<K,n> >::vectortype = {MPI_DATATYPE_NULL};
122 class bigunsignedint;
125 struct MPITraits<bigunsignedint<k> >
127 static MPI_Datatype datatype;
128 static MPI_Datatype vectortype;
130 static inline MPI_Datatype getType()
132 if(datatype==MPI_DATATYPE_NULL) {
133 MPI_Type_contiguous(bigunsignedint<k>::n, MPITraits<std::uint16_t>::getType(),
136 bigunsignedint<k> data;
139 MPI_Get_address(&data, &base);
140 MPI_Get_address(&(data.digit), &displ);
143 MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype);
144 MPI_Type_commit(&datatype);
154 MPI_Datatype MPITraits<bigunsignedint<k> >::datatype = MPI_DATATYPE_NULL;
156 MPI_Datatype MPITraits<bigunsignedint<k> >::vectortype = MPI_DATATYPE_NULL;
158 template<
typename T1,
typename T2>
159 struct MPITraits<
std::pair<T1,T2 > >
162 inline static MPI_Datatype getType();
164 static MPI_Datatype type;
166 template<
typename T1,
typename T2>
167 MPI_Datatype MPITraits<std::pair<T1,T2> >::getType()
169 if(type==MPI_DATATYPE_NULL) {
170 int length[2] = {1, 1};
172 MPI_Datatype types[2] = {MPITraits<T1>::getType(),
173 MPITraits<T2>::getType()};
175 using Pair = std::pair<T1, T2>;
176 static_assert(std::is_standard_layout<Pair>::value,
"offsetof() is only defined for standard layout types");
177 disp[0] = offsetof(Pair, first);
178 disp[1] = offsetof(Pair, second);
181 MPI_Type_create_struct(2, length, disp, types, &tmp);
183 MPI_Type_create_resized(tmp, 0,
sizeof(Pair), &type);
184 MPI_Type_commit(&type);
191 template<
typename T1,
typename T2>
192 MPI_Datatype MPITraits<std::pair<T1,T2> >::type=MPI_DATATYPE_NULL;
vector space out of a tensor product of fields.
Definition: fvector.hh:93
Dune namespace.
Definition: alignment.hh:11
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:39