3#ifndef DUNE_MPITRAITS_HH
4#define DUNE_MPITRAITS_HH
42 static MPI_Datatype datatype;
43 static MPI_Datatype vectortype;
45 static inline MPI_Datatype getType()
47 if(datatype==MPI_DATATYPE_NULL) {
48 MPI_Type_contiguous(
sizeof(T),MPI_BYTE,&datatype);
49 MPI_Type_commit(&datatype);
61#define ComposeMPITraits(p,m) \
63 struct MPITraits<p>{ \
64 static inline MPI_Datatype getType(){ \
69 ComposeMPITraits(
char, MPI_CHAR);
70 ComposeMPITraits(
unsigned char,MPI_UNSIGNED_CHAR);
71 ComposeMPITraits(
short,MPI_SHORT);
72 ComposeMPITraits(
unsigned short,MPI_UNSIGNED_SHORT);
73 ComposeMPITraits(
int,MPI_INT);
74 ComposeMPITraits(
unsigned int,MPI_UNSIGNED);
75 ComposeMPITraits(
long,MPI_LONG);
76 ComposeMPITraits(
unsigned long,MPI_UNSIGNED_LONG);
77 ComposeMPITraits(
float,MPI_FLOAT);
78 ComposeMPITraits(
double,MPI_DOUBLE);
79 ComposeMPITraits(
long double,MPI_LONG_DOUBLE);
82#undef ComposeMPITraits
86 template<
class K,
int n>
89 static MPI_Datatype datatype;
90 static MPI_Datatype vectortype;
92 static inline MPI_Datatype getType()
94 if(datatype==MPI_DATATYPE_NULL) {
96 MPI_Type_commit(&vectortype);
100 MPI_Get_address(&fvector, &base);
101 MPI_Get_address(&(fvector[0]), &displ);
105 MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype);
106 MPI_Type_commit(&datatype);
113 template<
class K,
int n>
114 MPI_Datatype MPITraits<FieldVector<K,n> >::datatype = MPI_DATATYPE_NULL;
115 template<
class K,
int n>
116 MPI_Datatype MPITraits<FieldVector<K,n> >::vectortype = {MPI_DATATYPE_NULL};
120 class bigunsignedint;
123 struct MPITraits<bigunsignedint<k> >
125 static MPI_Datatype datatype;
126 static MPI_Datatype vectortype;
128 static inline MPI_Datatype getType()
130 if(datatype==MPI_DATATYPE_NULL) {
131 MPI_Type_contiguous(bigunsignedint<k>::n, MPITraits<std::uint16_t>::getType(),
134 bigunsignedint<k> data;
137 MPI_Get_address(&data, &base);
138 MPI_Get_address(&(data.digit), &displ);
141 MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype);
142 MPI_Type_commit(&datatype);
152 MPI_Datatype MPITraits<bigunsignedint<k> >::datatype = MPI_DATATYPE_NULL;
154 MPI_Datatype MPITraits<bigunsignedint<k> >::vectortype = MPI_DATATYPE_NULL;
156 template<
typename T1,
typename T2>
157 struct MPITraits<
std::pair<T1,T2 > >
160 inline static MPI_Datatype getType();
162 static MPI_Datatype type;
164 template<
typename T1,
typename T2>
165 MPI_Datatype MPITraits<std::pair<T1,T2> >::getType()
167 if(type==MPI_DATATYPE_NULL) {
168 int length[2] = {1, 1};
170 MPI_Datatype types[2] = {MPITraits<T1>::getType(),
171 MPITraits<T2>::getType()};
173 using Pair = std::pair<T1, T2>;
174 static_assert(std::is_standard_layout<Pair>::value,
"offsetof() is only defined for standard layout types");
175 disp[0] = offsetof(Pair, first);
176 disp[1] = offsetof(Pair, second);
179 MPI_Type_create_struct(2, length, disp, types, &tmp);
181 MPI_Type_create_resized(tmp, 0,
sizeof(Pair), &type);
182 MPI_Type_commit(&type);
189 template<
typename T1,
typename T2>
190 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: alignedallocator.hh:10
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:38