1 #ifndef DIY_MPI_DATATYPES_HPP
2 #define DIY_MPI_DATATYPES_HPP
12 template<
class T> MPI_Datatype get_mpi_datatype();
19 struct is_mpi_datatype {
typedef false_type type; };
21 #define DIY_MPI_DATATYPE_MAP(cpp_type, mpi_type) \
22 template<> inline MPI_Datatype get_mpi_datatype<cpp_type>() { return mpi_type; } \
23 template<> struct is_mpi_datatype<cpp_type> { typedef true_type type; }; \
24 template<> struct is_mpi_datatype< std::vector<cpp_type> > { typedef true_type type; };
26 DIY_MPI_DATATYPE_MAP(
char, MPI_BYTE);
27 DIY_MPI_DATATYPE_MAP(
unsigned char, MPI_BYTE);
28 DIY_MPI_DATATYPE_MAP(
bool, MPI_BYTE);
29 DIY_MPI_DATATYPE_MAP(
int, MPI_INT);
30 DIY_MPI_DATATYPE_MAP(
unsigned, MPI_UNSIGNED);
31 DIY_MPI_DATATYPE_MAP(
long, MPI_LONG);
32 DIY_MPI_DATATYPE_MAP(
unsigned long, MPI_UNSIGNED_LONG);
33 DIY_MPI_DATATYPE_MAP(
long long, MPI_LONG_LONG_INT);
34 DIY_MPI_DATATYPE_MAP(
unsigned long long, MPI_UNSIGNED_LONG_LONG);
35 DIY_MPI_DATATYPE_MAP(
float, MPI_FLOAT);
36 DIY_MPI_DATATYPE_MAP(
double, MPI_DOUBLE);
42 static MPI_Datatype datatype() {
return get_mpi_datatype<T>(); }
43 static const void* address(
const T& x) {
return &x; }
44 static void* address(T& x) {
return &x; }
45 static int count(
const T&) {
return 1; }
49 struct mpi_datatype< std::vector<U> >
51 typedef std::vector<U> VecU;
53 static MPI_Datatype datatype() {
return get_mpi_datatype<U>(); }
54 static const void* address(
const VecU& x) {
return &x[0]; }
55 static void* address(VecU& x) {
return &x[0]; }
56 static int count(
const VecU& x) {
return static_cast<int>(x.size()); }