forked from fmihpc/dccrg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdccrg_get_cell_datatype.hpp
344 lines (309 loc) · 8.42 KB
/
dccrg_get_cell_datatype.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
Functions for dccrg to obtain the MPI Datatype from cell data.
Copyright 2014, 2015, 2016 Ilja Honkonen
Copyright 2018 Finnish Meteorological Institute
Dccrg is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
as published by the Free Software Foundation.
Dccrg is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with dccrg. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DCCRG_GET_CELL_DATATYPE_HPP
#define DCCRG_GET_CELL_DATATYPE_HPP
#include "cstdint"
#include "tuple"
#include "type_traits"
#include "mpi.h"
#include "boost/function_types/property_tags.hpp"
#include "boost/mpl/vector.hpp"
#include "boost/tti/has_member_function.hpp"
namespace dccrg {
namespace detail {
BOOST_TTI_HAS_MEMBER_FUNCTION(get_mpi_datatype)
/*!
Returns the MPI transfer info from given cell.
Version for get_mpi_datatype(const uint64_t, ..., const int) const.
*/
template<
class Cell_Data
> typename std::enable_if<
has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<
const uint64_t,
const int,
const int,
const bool,
const int
>,
boost::function_types::const_qualified
>::value,
std::tuple<
void*,
int,
MPI_Datatype
>
>::type get_cell_mpi_datatype(
const Cell_Data& cell,
const uint64_t cell_id,
const int sender,
const int receiver,
const bool receiving,
const int neighborhood_id
) {
return cell.get_mpi_datatype(
cell_id,
sender,
receiver,
receiving,
neighborhood_id
);
}
/*!
Returns the MPI transfer info from given cell.
Version for get_mpi_datatype(const uint64_t, ..., const int).
*/
template<
class Cell_Data
> typename std::enable_if<
has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<
const uint64_t,
const int,
const int,
const bool,
const int
>
>::value,
std::tuple<
void*,
int,
MPI_Datatype
>
>::type get_cell_mpi_datatype(
Cell_Data& cell,
const uint64_t cell_id,
const int sender,
const int receiver,
const bool receiving,
const int neighborhood_id
) {
return cell.get_mpi_datatype(
cell_id,
sender,
receiver,
receiving,
neighborhood_id
);
}
/*!
Returns the MPI transfer info from given cell.
Version for get_mpi_datatype() const.
Gives precedence to get_mpi_datatype which takes arguments.
*/
template<
class Cell_Data
> typename std::enable_if<
has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<>,
boost::function_types::const_qualified
>::value
and not
has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<
const uint64_t,
const int,
const int,
const bool,
const int
>,
boost::function_types::const_qualified
>::value,
std::tuple<
void*,
int,
MPI_Datatype
>
>::type get_cell_mpi_datatype(
const Cell_Data& cell,
const uint64_t /*cell_id*/,
const int /*sender*/,
const int /*receiver*/,
const bool /*receiving*/,
const int /*neighborhood_id*/
) {
return cell.get_mpi_datatype();
}
/*!
Returns the MPI transfer info from given cell.
Version for get_mpi_datatype().
Gives precedence to get_mpi_datatype which takes arguments.
*/
template<
class Cell_Data
> typename std::enable_if<
has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<>
>::value
and not
has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<
const uint64_t,
const int,
const int,
const bool,
const int
>
>::value,
std::tuple<
void*,
int,
MPI_Datatype
>
>::type get_cell_mpi_datatype(
Cell_Data& cell,
const uint64_t /*cell_id*/,
const int /*sender*/,
const int /*receiver*/,
const bool /*receiving*/,
const int /*neighborhood_id*/
) {
return cell.get_mpi_datatype();
}
// give a human-readable error message
template<class Cell_Data> std::tuple<void*, int, MPI_Datatype> get_mpi_datatype_basic(Cell_Data&) {
static_assert(
not std::is_same<Cell_Data, Cell_Data>::value,
"Cell_Data given to dccrg is not a supported type and "
"doesn't have get_mpi_datatype() member function either"
);
return std::make_tuple(nullptr, -1, MPI_DATATYPE_NULL);
}
#define DCCRG_GET_MPI_DATATYPE_BASIC(CPP, MPI) \
std::tuple< \
void*, int, MPI_Datatype \
> inline get_mpi_datatype_basic(CPP& cell) { \
return std::make_tuple((void*) &cell, 1, MPI); \
}
DCCRG_GET_MPI_DATATYPE_BASIC(char, MPI_CHAR)
DCCRG_GET_MPI_DATATYPE_BASIC(signed char, MPI_CHAR)
DCCRG_GET_MPI_DATATYPE_BASIC(unsigned char, MPI_UNSIGNED_CHAR)
DCCRG_GET_MPI_DATATYPE_BASIC(short int, MPI_SHORT)
DCCRG_GET_MPI_DATATYPE_BASIC(unsigned short int, MPI_UNSIGNED_SHORT)
DCCRG_GET_MPI_DATATYPE_BASIC(int, MPI_INT)
DCCRG_GET_MPI_DATATYPE_BASIC(unsigned int, MPI_UNSIGNED)
DCCRG_GET_MPI_DATATYPE_BASIC(long int, MPI_LONG)
DCCRG_GET_MPI_DATATYPE_BASIC(unsigned long int, MPI_UNSIGNED_LONG)
DCCRG_GET_MPI_DATATYPE_BASIC(long long int, MPI_LONG_LONG)
DCCRG_GET_MPI_DATATYPE_BASIC(unsigned long long int, MPI_UNSIGNED_LONG_LONG)
DCCRG_GET_MPI_DATATYPE_BASIC(float, MPI_FLOAT)
DCCRG_GET_MPI_DATATYPE_BASIC(double, MPI_DOUBLE)
DCCRG_GET_MPI_DATATYPE_BASIC(long double, MPI_LONG_DOUBLE)
DCCRG_GET_MPI_DATATYPE_BASIC(wchar_t, MPI_WCHAR)
DCCRG_GET_MPI_DATATYPE_BASIC(bool, MPI_CXX_BOOL)
#ifdef DCCRG_USER_COMPLEX
DCCRG_GET_MPI_DATATYPE_BASIC(std::complex<float>, MPI_CXX_FLOAT_COMPLEX)
DCCRG_GET_MPI_DATATYPE_BASIC(std::complex<double>, MPI_CXX_DOUBLE_COMPLEX)
DCCRG_GET_MPI_DATATYPE_BASIC(std::complex<long double>, MPI_CXX_LONG_DOUBLE_COMPLEX)
#endif
#undef DCCRG_GET_MPI_DATATYPE_BASIC
#define DCCRG_GET_MPI_DATATYPE_ARRAY(CPP, MPI) \
template<size_t N> std::tuple< \
void*, int, MPI_Datatype \
> inline get_mpi_datatype_basic(std::array<CPP, N>& cell) { \
return std::make_tuple((void*) cell.data(), cell.size(), MPI); \
}
DCCRG_GET_MPI_DATATYPE_ARRAY(char, MPI_CHAR)
DCCRG_GET_MPI_DATATYPE_ARRAY(signed char, MPI_CHAR)
DCCRG_GET_MPI_DATATYPE_ARRAY(unsigned char, MPI_UNSIGNED_CHAR)
DCCRG_GET_MPI_DATATYPE_ARRAY(short int, MPI_SHORT)
DCCRG_GET_MPI_DATATYPE_ARRAY(unsigned short int, MPI_UNSIGNED_SHORT)
DCCRG_GET_MPI_DATATYPE_ARRAY(int, MPI_INT)
DCCRG_GET_MPI_DATATYPE_ARRAY(unsigned int, MPI_UNSIGNED)
DCCRG_GET_MPI_DATATYPE_ARRAY(long int, MPI_LONG)
DCCRG_GET_MPI_DATATYPE_ARRAY(unsigned long int, MPI_UNSIGNED_LONG)
DCCRG_GET_MPI_DATATYPE_ARRAY(long long int, MPI_LONG_LONG)
DCCRG_GET_MPI_DATATYPE_ARRAY(unsigned long long int, MPI_UNSIGNED_LONG_LONG)
DCCRG_GET_MPI_DATATYPE_ARRAY(float, MPI_FLOAT)
DCCRG_GET_MPI_DATATYPE_ARRAY(double, MPI_DOUBLE)
DCCRG_GET_MPI_DATATYPE_ARRAY(long double, MPI_LONG_DOUBLE)
DCCRG_GET_MPI_DATATYPE_ARRAY(wchar_t, MPI_WCHAR)
#ifdef DCCRG_USER_COMPLEX
DCCRG_GET_MPI_DATATYPE_ARRAY(std::complex<float>, MPI_CXX_FLOAT_COMPLEX)
DCCRG_GET_MPI_DATATYPE_ARRAY(std::complex<double>, MPI_CXX_DOUBLE_COMPLEX)
DCCRG_GET_MPI_DATATYPE_ARRAY(std::complex<long double>, MPI_CXX_LONG_DOUBLE_COMPLEX)
#endif
#undef DCCRG_GET_MPI_DATATYPE_ARRAY
/*!
Returns the MPI transfer info from given cell.
Version for cell that doesn't have get_mpi_datatype().
*/
template<
class Cell_Data
> typename std::enable_if<
not has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<
const uint64_t,
const int,
const int,
const bool,
const int
>,
boost::function_types::const_qualified
>::value
and not has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<
const uint64_t,
const int,
const int,
const bool,
const int
>
>::value
and not has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<>,
boost::function_types::const_qualified
>::value
and not has_member_function_get_mpi_datatype<
Cell_Data,
std::tuple<void*, int, MPI_Datatype>,
boost::mpl::vector<>
>::value,
std::tuple<
void*,
int,
MPI_Datatype
>
>::type get_cell_mpi_datatype(
Cell_Data& cell,
const uint64_t /*cell_id*/,
const int /*sender*/,
const int /*receiver*/,
const bool /*receiving*/,
const int /*neighborhood_id*/
) {
return get_mpi_datatype_basic(cell);
}
}} // namespaces
#endif