|
| 1 | +/* Copyright 2022 Franz Poeschel |
| 2 | + * |
| 3 | + * This file is part of openPMD-api. |
| 4 | + * |
| 5 | + * openPMD-api is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of of either the GNU General Public License or |
| 7 | + * the GNU Lesser General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * openPMD-api is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License and the GNU Lesser General Public License |
| 15 | + * for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * and the GNU Lesser General Public License along with openPMD-api. |
| 19 | + * If not, see <http://www.gnu.org/licenses/>. |
| 20 | + */ |
| 21 | +#pragma once |
| 22 | + |
| 23 | +#include "openPMD/config.hpp" |
| 24 | + |
| 25 | +#if openPMD_HAVE_MPI |
| 26 | +#include <mpi.h> |
| 27 | +#endif |
| 28 | + |
| 29 | +#include <type_traits> |
| 30 | + |
| 31 | +namespace openPMD::auxiliary |
| 32 | +{ |
| 33 | +#if openPMD_HAVE_MPI |
| 34 | + |
| 35 | +namespace detail |
| 36 | +{ |
| 37 | + namespace |
| 38 | + { |
| 39 | + // see https://en.cppreference.com/w/cpp/language/if |
| 40 | + template <typename> |
| 41 | + inline constexpr bool dependent_false_v = false; |
| 42 | + } // namespace |
| 43 | +} // namespace detail |
| 44 | + |
| 45 | +namespace |
| 46 | +{ |
| 47 | + template <typename T> |
| 48 | + constexpr MPI_Datatype openPMD_MPI_type() |
| 49 | + { |
| 50 | + using T_decay = std::decay_t<T>; |
| 51 | + if constexpr (std::is_same_v<T_decay, char>) |
| 52 | + { |
| 53 | + return MPI_CHAR; |
| 54 | + } |
| 55 | + else if constexpr (std::is_same_v<T_decay, unsigned>) |
| 56 | + { |
| 57 | + return MPI_UNSIGNED; |
| 58 | + } |
| 59 | + else if constexpr (std::is_same_v<T_decay, unsigned long>) |
| 60 | + { |
| 61 | + return MPI_UNSIGNED_LONG; |
| 62 | + } |
| 63 | + else if constexpr (std::is_same_v<T_decay, unsigned long long>) |
| 64 | + { |
| 65 | + return MPI_UNSIGNED_LONG_LONG; |
| 66 | + } |
| 67 | + else |
| 68 | + { |
| 69 | + static_assert( |
| 70 | + detail::dependent_false_v<T>, |
| 71 | + "openPMD_MPI_type: Unsupported type."); |
| 72 | + } |
| 73 | + } |
| 74 | +} // namespace |
| 75 | + |
| 76 | +#endif |
| 77 | +} // namespace openPMD::auxiliary |
0 commit comments