5#ifndef DUNE_COMMON_PARALLEL_MPITRAITS_HH
6#define DUNE_COMMON_PARALLEL_MPITRAITS_HH
45 static MPI_Datatype datatype;
46 static MPI_Datatype vectortype;
48 static inline MPI_Datatype getType()
50 if(datatype==MPI_DATATYPE_NULL) {
51 MPI_Type_contiguous(
sizeof(T),MPI_BYTE,&datatype);
52 MPI_Type_commit(&datatype);
56 static constexpr bool is_intrinsic =
false;
64#define ComposeMPITraits(p,m) \
66 struct MPITraits<p>{ \
67 static inline MPI_Datatype getType(){ \
70 static constexpr bool is_intrinsic = true; \
73 ComposeMPITraits(
char, MPI_CHAR);
74 ComposeMPITraits(
unsigned char,MPI_UNSIGNED_CHAR);
75 ComposeMPITraits(
short,MPI_SHORT);
76 ComposeMPITraits(
unsigned short,MPI_UNSIGNED_SHORT);
77 ComposeMPITraits(
int,MPI_INT);
78 ComposeMPITraits(
unsigned int,MPI_UNSIGNED);
79 ComposeMPITraits(
long,MPI_LONG);
80 ComposeMPITraits(
unsigned long,MPI_UNSIGNED_LONG);
81 ComposeMPITraits(
float,MPI_FLOAT);
82 ComposeMPITraits(
double,MPI_DOUBLE);
83 ComposeMPITraits(
long double,MPI_LONG_DOUBLE);
84 ComposeMPITraits(std::complex<double>, MPI_CXX_DOUBLE_COMPLEX);
85 ComposeMPITraits(std::complex<long double>, MPI_CXX_LONG_DOUBLE_COMPLEX);
86 ComposeMPITraits(std::complex<float>, MPI_CXX_FLOAT_COMPLEX);
89#undef ComposeMPITraits
93 template<
class K,
int n>
96 static MPI_Datatype datatype;
97 static MPI_Datatype vectortype;
99 static inline MPI_Datatype getType()
101 if(datatype==MPI_DATATYPE_NULL) {
103 MPI_Type_commit(&vectortype);
107 MPI_Get_address(&fvector, &base);
108 MPI_Get_address(&(fvector[0]), &displ);
112 MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype);
113 MPI_Type_commit(&datatype);
120 template<
class K,
int n>
121 MPI_Datatype MPITraits<FieldVector<K,n> >::datatype = MPI_DATATYPE_NULL;
122 template<
class K,
int n>
123 MPI_Datatype MPITraits<FieldVector<K,n> >::vectortype = {MPI_DATATYPE_NULL};
127 class bigunsignedint;
130 struct MPITraits<bigunsignedint<k> >
132 static MPI_Datatype datatype;
133 static MPI_Datatype vectortype;
135 static inline MPI_Datatype getType()
137 if(datatype==MPI_DATATYPE_NULL) {
138 MPI_Type_contiguous(bigunsignedint<k>::n, MPITraits<std::uint16_t>::getType(),
141 bigunsignedint<k> data;
144 MPI_Get_address(&data, &base);
145 MPI_Get_address(&(data.digit), &displ);
148 MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype);
149 MPI_Type_commit(&datatype);
159 MPI_Datatype MPITraits<bigunsignedint<k> >::datatype = MPI_DATATYPE_NULL;
161 MPI_Datatype MPITraits<bigunsignedint<k> >::vectortype = MPI_DATATYPE_NULL;
163 template<
typename T1,
typename T2>
164 struct MPITraits<
std::pair<T1,T2 > >
167 inline static MPI_Datatype getType();
169 static MPI_Datatype type;
171 template<
typename T1,
typename T2>
172 MPI_Datatype MPITraits<std::pair<T1,T2> >::getType()
174 if(type==MPI_DATATYPE_NULL) {
175 int length[2] = {1, 1};
177 MPI_Datatype types[2] = {MPITraits<T1>::getType(),
178 MPITraits<T2>::getType()};
180 using Pair = std::pair<T1, T2>;
181 static_assert(std::is_standard_layout<Pair>::value,
"offsetof() is only defined for standard layout types");
182 disp[0] = offsetof(Pair, first);
183 disp[1] = offsetof(Pair, second);
186 MPI_Type_create_struct(2, length, disp, types, &tmp);
188 MPI_Type_create_resized(tmp, 0,
sizeof(Pair), &type);
189 MPI_Type_commit(&type);
196 template<
typename T1,
typename T2>
197 MPI_Datatype MPITraits<std::pair<T1,T2> >::type=MPI_DATATYPE_NULL;
vector space out of a tensor product of fields.
Definition: fvector.hh:91
Dune namespace.
Definition: alignedallocator.hh:13
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: mpitraits.hh:41