OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
26template<typename> struct is_ippl_mpi_datatype: std::false_type {};
27
28template <typename T> MPI_Datatype get_mpi_datatype(const T& /*x*/)
29{
31 "type isn't an MPI type");
32 return get_mpi_datatype(T());
33}
34
35
36#define IPPL_MPI_DATATYPE(CppType, MPIType) \
37template<> \
38inline MPI_Datatype \
39get_mpi_datatype< CppType >(const CppType&) { return MPIType; } \
40 \
41template<> \
42struct is_ippl_mpi_datatype<CppType>: std::true_type {};
43
44
45IPPL_MPI_DATATYPE(char, MPI_CHAR);
46
47IPPL_MPI_DATATYPE(short, MPI_SHORT);
48
49IPPL_MPI_DATATYPE(int, MPI_INT);
50
51IPPL_MPI_DATATYPE(long, MPI_LONG);
52
53IPPL_MPI_DATATYPE(long long, MPI_LONG_LONG);
54
55IPPL_MPI_DATATYPE(unsigned char, MPI_UNSIGNED_CHAR);
56
57IPPL_MPI_DATATYPE(unsigned short, MPI_UNSIGNED_SHORT);
58
59IPPL_MPI_DATATYPE(unsigned int, MPI_UNSIGNED);
60
61IPPL_MPI_DATATYPE(unsigned long, MPI_UNSIGNED_LONG);
62
63IPPL_MPI_DATATYPE(unsigned long long, MPI_UNSIGNED_LONG_LONG);
64
65IPPL_MPI_DATATYPE(float, MPI_FLOAT);
66
67IPPL_MPI_DATATYPE(double, MPI_DOUBLE);
68
69IPPL_MPI_DATATYPE(long double, MPI_LONG_DOUBLE);
70
71IPPL_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