File indexing completed on 2026-08-07 08:53:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef BOOST_MPI_DATATYPE_HPP
0018 #define BOOST_MPI_DATATYPE_HPP
0019
0020 #include <boost/mpi/config.hpp>
0021 #include <boost/mpi/datatype_fwd.hpp>
0022 #include <mpi.h>
0023 #include <boost/config.hpp>
0024 #include <boost/mpl/bool.hpp>
0025 #include <boost/mpl/or.hpp>
0026 #include <boost/mpl/and.hpp>
0027 #include <boost/mpi/detail/mpi_datatype_cache.hpp>
0028 #include <boost/mpl/assert.hpp>
0029 #include <boost/archive/basic_archive.hpp>
0030 #include <boost/serialization/library_version_type.hpp>
0031 #include <boost/serialization/item_version_type.hpp>
0032 #include <utility> // for std::pair
0033
0034 #if defined(__cplusplus) && (201103L <= __cplusplus)
0035 #include <array>
0036 #endif
0037
0038 namespace boost { namespace mpi {
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 template<typename T>
0050 struct is_mpi_integer_datatype
0051 : public boost::mpl::false_ { };
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 template<typename T>
0063 struct is_mpi_floating_point_datatype
0064 : public boost::mpl::false_ { };
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 template<typename T>
0076 struct is_mpi_logical_datatype
0077 : public boost::mpl::false_ { };
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 template<typename T>
0089 struct is_mpi_complex_datatype
0090 : public boost::mpl::false_ { };
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 template<typename T>
0102 struct is_mpi_byte_datatype
0103 : public boost::mpl::false_ { };
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 template<typename T>
0126 struct is_mpi_builtin_datatype
0127 : boost::mpl::or_<is_mpi_integer_datatype<T>,
0128 is_mpi_floating_point_datatype<T>,
0129 is_mpi_logical_datatype<T>,
0130 is_mpi_complex_datatype<T>,
0131 is_mpi_byte_datatype<T> >
0132 {
0133 };
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161 template<typename T>
0162 struct is_mpi_datatype
0163 : public is_mpi_builtin_datatype<T>
0164 {
0165 };
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189 template<typename T> MPI_Datatype get_mpi_datatype(const T& x)
0190 {
0191 BOOST_MPL_ASSERT((is_mpi_datatype<T>));
0192 return detail::mpi_datatype_cache().datatype(x);
0193 }
0194
0195
0196 #ifndef BOOST_MPI_DOXYGEN
0197
0198
0199 #define BOOST_MPI_DATATYPE(CppType, MPIType, Kind) \
0200 template<> \
0201 inline MPI_Datatype \
0202 get_mpi_datatype< CppType >(const CppType&) { return MPIType; } \
0203 \
0204 template<> \
0205 struct BOOST_JOIN(is_mpi_,BOOST_JOIN(Kind,_datatype))< CppType > \
0206 : boost::mpl::true_ \
0207 {}
0208
0209
0210 BOOST_MPI_DATATYPE(packed, MPI_PACKED, builtin);
0211
0212
0213 BOOST_MPI_DATATYPE(char, MPI_CHAR, builtin);
0214
0215
0216 #if !defined(MSMPI_VER)
0217
0218 BOOST_MPI_DATATYPE(bool, MPI_CXX_BOOL, logical);
0219 #else
0220
0221 BOOST_MPI_DATATYPE(bool, MPI_C_BOOL, logical);
0222 #endif
0223
0224
0225 BOOST_MPI_DATATYPE(short, MPI_SHORT, integer);
0226
0227
0228 BOOST_MPI_DATATYPE(int, MPI_INT, integer);
0229
0230
0231 BOOST_MPI_DATATYPE(long, MPI_LONG, integer);
0232
0233
0234 BOOST_MPI_DATATYPE(float, MPI_FLOAT, floating_point);
0235
0236
0237 BOOST_MPI_DATATYPE(double, MPI_DOUBLE, floating_point);
0238
0239
0240 BOOST_MPI_DATATYPE(long double, MPI_LONG_DOUBLE, floating_point);
0241
0242
0243 BOOST_MPI_DATATYPE(unsigned char, MPI_UNSIGNED_CHAR, builtin);
0244
0245
0246 BOOST_MPI_DATATYPE(unsigned short, MPI_UNSIGNED_SHORT, integer);
0247
0248
0249 BOOST_MPI_DATATYPE(unsigned, MPI_UNSIGNED, integer);
0250
0251
0252 BOOST_MPI_DATATYPE(unsigned long, MPI_UNSIGNED_LONG, integer);
0253
0254
0255 #define BOOST_MPI_LIST2(A, B) A, B
0256
0257 BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(float, int)>, MPI_FLOAT_INT,
0258 builtin);
0259
0260 BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(double, int)>, MPI_DOUBLE_INT,
0261 builtin);
0262
0263 BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(long double, int)>,
0264 MPI_LONG_DOUBLE_INT, builtin);
0265
0266 BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(long, int>), MPI_LONG_INT,
0267 builtin);
0268
0269 BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(short, int>), MPI_SHORT_INT,
0270 builtin);
0271
0272 BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(int, int>), MPI_2INT, builtin);
0273 #undef BOOST_MPI_LIST2
0274
0275
0276 template <class T, class U>
0277 struct is_mpi_datatype<std::pair<T,U> >
0278 : public mpl::and_<is_mpi_datatype<T>,is_mpi_datatype<U> >
0279 {
0280 };
0281
0282
0283 #if defined(__cplusplus) && (201103L <= __cplusplus)
0284 template<class T, std::size_t N>
0285 struct is_mpi_datatype<std::array<T, N> >
0286 : public is_mpi_datatype<T>
0287 {
0288 };
0289 #endif
0290
0291
0292 #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && \
0293 (defined(MPI_WCHAR) || (BOOST_MPI_VERSION >= 2))
0294 BOOST_MPI_DATATYPE(wchar_t, MPI_WCHAR, builtin);
0295 #endif
0296
0297
0298 #if defined(BOOST_HAS_LONG_LONG) && \
0299 (defined(MPI_LONG_LONG_INT) || (BOOST_MPI_VERSION >= 2))
0300 BOOST_MPI_DATATYPE(long long, MPI_LONG_LONG_INT, builtin);
0301 #elif defined(BOOST_HAS_MS_INT64) && \
0302 (defined(MPI_LONG_LONG_INT) || (BOOST_MPI_VERSION >= 2))
0303 BOOST_MPI_DATATYPE(__int64, MPI_LONG_LONG_INT, builtin);
0304 #endif
0305
0306
0307
0308
0309
0310
0311 #if defined(BOOST_HAS_LONG_LONG) && \
0312 (defined(MPI_UNSIGNED_LONG_LONG) \
0313 || (BOOST_MPI_VERSION >= 2))
0314 BOOST_MPI_DATATYPE(unsigned long long, MPI_UNSIGNED_LONG_LONG, builtin);
0315 #elif defined(BOOST_HAS_MS_INT64) && \
0316 (defined(MPI_UNSIGNED_LONG_LONG) \
0317 || (BOOST_MPI_VERSION >= 2))
0318 BOOST_MPI_DATATYPE(unsigned __int64, MPI_UNSIGNED_LONG_LONG, builtin);
0319 #endif
0320
0321
0322 #if defined(MPI_SIGNED_CHAR) || (BOOST_MPI_VERSION >= 2)
0323 BOOST_MPI_DATATYPE(signed char, MPI_SIGNED_CHAR, builtin);
0324 #endif
0325
0326
0327 #endif
0328
0329 #ifndef BOOST_MPI_DOXYGEN
0330
0331 BOOST_MPI_DATATYPE(boost::serialization::library_version_type, get_mpi_datatype(uint_least16_t()), integer);
0332 BOOST_MPI_DATATYPE(boost::archive::version_type, get_mpi_datatype(uint_least8_t()), integer);
0333 BOOST_MPI_DATATYPE(boost::archive::class_id_type, get_mpi_datatype(int_least16_t()), integer);
0334 BOOST_MPI_DATATYPE(boost::archive::class_id_reference_type, get_mpi_datatype(int_least16_t()), integer);
0335 BOOST_MPI_DATATYPE(boost::archive::class_id_optional_type, get_mpi_datatype(int_least16_t()), integer);
0336 BOOST_MPI_DATATYPE(boost::archive::object_id_type, get_mpi_datatype(uint_least32_t()), integer);
0337 BOOST_MPI_DATATYPE(boost::archive::object_reference_type, get_mpi_datatype(uint_least32_t()), integer);
0338 BOOST_MPI_DATATYPE(boost::archive::tracking_type, get_mpi_datatype(bool()), builtin);
0339 BOOST_MPI_DATATYPE(boost::serialization::collection_size_type, get_mpi_datatype(std::size_t()), integer);
0340 BOOST_MPI_DATATYPE(boost::serialization::item_version_type, get_mpi_datatype(uint_least8_t()), integer);
0341 #endif
0342
0343
0344 } }
0345
0346
0347
0348
0349 #define BOOST_IS_MPI_DATATYPE(T) \
0350 namespace boost { \
0351 namespace mpi { \
0352 template<> \
0353 struct is_mpi_datatype< T > : mpl::true_ {}; \
0354 }} \
0355
0356
0357
0358 #endif