OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
DataTypes.h
Go to the documentation of this file.
1 //
2 // File DataTypes
3 // Definition of MPI types following the implementation of Boost.MPI.
4 //
5 // Copyright (c) 2017, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // Implemented as part of the PhD thesis
9 // "Precise Simulations of Multibunches in High Intensity Cyclotrons"
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 #ifndef IPPL_MPI_DATATYPES_H
22 #define IPPL_MPI_DATATYPES_H
23 
24 #include <mpi.h>
25 
26 template<typename> struct is_ippl_mpi_datatype: std::false_type {};
27 
28 template <typename T> MPI_Datatype get_mpi_datatype(const T& /*x*/)
29 {
30  static_assert(is_ippl_mpi_datatype<T>::value,
31  "type isn't an MPI type");
32  return get_mpi_datatype(T());
33 }
34 
35 
36 #define IPPL_MPI_DATATYPE(CppType, MPIType) \
37 template<> \
38 inline MPI_Datatype \
39 get_mpi_datatype< CppType >(const CppType&) { return MPIType; } \
40  \
41 template<> \
42 struct is_ippl_mpi_datatype<CppType>: std::true_type {};
43 
44 
45 IPPL_MPI_DATATYPE(char, MPI_CHAR);
46 
47 IPPL_MPI_DATATYPE(short, MPI_SHORT);
48 
49 IPPL_MPI_DATATYPE(int, MPI_INT);
50 
51 IPPL_MPI_DATATYPE(long, MPI_LONG);
52 
53 IPPL_MPI_DATATYPE(long long, MPI_LONG_LONG);
54 
55 IPPL_MPI_DATATYPE(unsigned char, MPI_UNSIGNED_CHAR);
56 
57 IPPL_MPI_DATATYPE(unsigned short, MPI_UNSIGNED_SHORT);
58 
59 IPPL_MPI_DATATYPE(unsigned int, MPI_UNSIGNED);
60 
61 IPPL_MPI_DATATYPE(unsigned long, MPI_UNSIGNED_LONG);
62 
63 IPPL_MPI_DATATYPE(unsigned long long, MPI_UNSIGNED_LONG_LONG);
64 
65 IPPL_MPI_DATATYPE(float, MPI_FLOAT);
66 
67 IPPL_MPI_DATATYPE(double, MPI_DOUBLE);
68 
69 IPPL_MPI_DATATYPE(long double, MPI_LONG_DOUBLE);
70 
71 IPPL_MPI_DATATYPE(bool, MPI_CXX_BOOL);
72 
73 #endif
#define IPPL_MPI_DATATYPE(CppType, MPIType)
Definition: DataTypes.h:36
MPI_Datatype get_mpi_datatype(const T &)
Definition: DataTypes.h:28