openPMD-api
 
Loading...
Searching...
No Matches
Mpi.hpp
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#include "openPMD/auxiliary/TypeTraits.hpp"
26
27#if openPMD_HAVE_MPI
28#include <mpi.h>
29
30#include <string>
31#include <vector>
32#endif
33
34#include <type_traits>
35
36namespace openPMD::auxiliary
37{
38#if openPMD_HAVE_MPI
39
40namespace
41{
42 template <typename T>
43 constexpr MPI_Datatype openPMD_MPI_type()
44 {
45 using T_decay = std::decay_t<T>;
46 if constexpr (std::is_same_v<T_decay, char>)
47 {
48 return MPI_CHAR;
49 }
50 else if constexpr (std::is_same_v<T_decay, signed char>)
51 {
52 return MPI_SIGNED_CHAR;
53 }
54 else if constexpr (std::is_same_v<T_decay, unsigned char>)
55 {
56 return MPI_UNSIGNED_CHAR;
57 }
58 else if constexpr (std::is_same_v<T_decay, short>)
59 {
60 return MPI_SHORT;
61 }
62 else if constexpr (std::is_same_v<T_decay, short unsigned>)
63 {
64 return MPI_UNSIGNED_SHORT;
65 }
66 else if constexpr (std::is_same_v<T_decay, unsigned>)
67 {
68 return MPI_UNSIGNED;
69 }
70 else if constexpr (std::is_same_v<T_decay, int>)
71 {
72 return MPI_INT;
73 }
74 else if constexpr (std::is_same_v<T_decay, long>)
75 {
76 return MPI_LONG;
77 }
78 else if constexpr (std::is_same_v<T_decay, long long>)
79 {
80 return MPI_LONG_LONG;
81 }
82 else if constexpr (std::is_same_v<T_decay, unsigned long>)
83 {
84 return MPI_UNSIGNED_LONG;
85 }
86 else if constexpr (std::is_same_v<T_decay, unsigned long long>)
87 {
88 return MPI_UNSIGNED_LONG_LONG;
89 }
90 else if constexpr (std::is_same_v<T_decay, float>)
91 {
92 return MPI_FLOAT;
93 }
94 else if constexpr (std::is_same_v<T_decay, double>)
95 {
96 return MPI_DOUBLE;
97 }
98 else if constexpr (std::is_same_v<T_decay, long double>)
99 {
100 return MPI_LONG_DOUBLE;
101 }
102 else
103 {
104 static_assert(
105 dependent_false_v<T>, "openPMD_MPI_type: Unsupported type.");
106 }
107 }
108} // namespace
109
119{
120 std::vector<char> char_buffer;
121 size_t line_length = 0;
122 size_t num_lines = 0;
123};
124
125/*
126 * These are mostly internal helper functions, so this defines only those that
127 * we need.
128 * Logically, these should be complemented by `collectStringsTo()` and
129 * `distributeStringsAsMatrixToAllRanks()`, but we don't need them (yet).
130 */
131
142StringMatrix collectStringsAsMatrixTo(
143 MPI_Comm communicator, int destRank, std::string const &thisRankString);
144
155std::vector<std::string> distributeStringsToAllRanks(
156 MPI_Comm communicator, std::string const &thisRankString);
157#endif
158} // namespace openPMD::auxiliary
Multiple variable-length strings represented in one single buffer with a fixed line width.
Definition Mpi.hpp:119