123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- #ifndef BOOST_MPI_DATATYPE_HPP
- #define BOOST_MPI_DATATYPE_HPP
- #include <boost/mpi/config.hpp>
- #include <boost/mpi/datatype_fwd.hpp>
- #include <mpi.h>
- #include <boost/config.hpp>
- #include <boost/mpl/bool.hpp>
- #include <boost/mpl/or.hpp>
- #include <boost/mpl/and.hpp>
- #include <boost/mpi/detail/mpi_datatype_cache.hpp>
- #include <boost/mpl/assert.hpp>
- #include <boost/archive/basic_archive.hpp>
- #include <boost/serialization/library_version_type.hpp>
- #include <boost/serialization/item_version_type.hpp>
- #include <utility>
- #if defined(__cplusplus) && (201103L <= __cplusplus)
- #include <array>
- #endif
- namespace boost { namespace mpi {
- template<typename T>
- struct is_mpi_integer_datatype
- : public boost::mpl::false_ { };
- template<typename T>
- struct is_mpi_floating_point_datatype
- : public boost::mpl::false_ { };
- template<typename T>
- struct is_mpi_logical_datatype
- : public boost::mpl::false_ { };
- template<typename T>
- struct is_mpi_complex_datatype
- : public boost::mpl::false_ { };
- template<typename T>
- struct is_mpi_byte_datatype
- : public boost::mpl::false_ { };
- template<typename T>
- struct is_mpi_builtin_datatype
- : boost::mpl::or_<is_mpi_integer_datatype<T>,
- is_mpi_floating_point_datatype<T>,
- is_mpi_logical_datatype<T>,
- is_mpi_complex_datatype<T>,
- is_mpi_byte_datatype<T> >
- {
- };
- template<typename T>
- struct is_mpi_datatype
- : public is_mpi_builtin_datatype<T>
- {
- };
- template<typename T> MPI_Datatype get_mpi_datatype(const T& x)
- {
- BOOST_MPL_ASSERT((is_mpi_datatype<T>));
- return detail::mpi_datatype_cache().datatype(x);
- }
- #ifndef BOOST_MPI_DOXYGEN
- #define BOOST_MPI_DATATYPE(CppType, MPIType, Kind) \
- template<> \
- inline MPI_Datatype \
- get_mpi_datatype< CppType >(const CppType&) { return MPIType; } \
- \
- template<> \
- struct BOOST_JOIN(is_mpi_,BOOST_JOIN(Kind,_datatype))< CppType > \
- : boost::mpl::true_ \
- {}
- BOOST_MPI_DATATYPE(packed, MPI_PACKED, builtin);
- BOOST_MPI_DATATYPE(char, MPI_CHAR, builtin);
- BOOST_MPI_DATATYPE(short, MPI_SHORT, integer);
- BOOST_MPI_DATATYPE(int, MPI_INT, integer);
- BOOST_MPI_DATATYPE(long, MPI_LONG, integer);
- BOOST_MPI_DATATYPE(float, MPI_FLOAT, floating_point);
- BOOST_MPI_DATATYPE(double, MPI_DOUBLE, floating_point);
- BOOST_MPI_DATATYPE(long double, MPI_LONG_DOUBLE, floating_point);
- BOOST_MPI_DATATYPE(unsigned char, MPI_UNSIGNED_CHAR, builtin);
- BOOST_MPI_DATATYPE(unsigned short, MPI_UNSIGNED_SHORT, integer);
- BOOST_MPI_DATATYPE(unsigned, MPI_UNSIGNED, integer);
- BOOST_MPI_DATATYPE(unsigned long, MPI_UNSIGNED_LONG, integer);
- #define BOOST_MPI_LIST2(A, B) A, B
- BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(float, int)>, MPI_FLOAT_INT,
- builtin);
- BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(double, int)>, MPI_DOUBLE_INT,
- builtin);
- BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(long double, int)>,
- MPI_LONG_DOUBLE_INT, builtin);
- BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(long, int>), MPI_LONG_INT,
- builtin);
- BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(short, int>), MPI_SHORT_INT,
- builtin);
- BOOST_MPI_DATATYPE(std::pair<BOOST_MPI_LIST2(int, int>), MPI_2INT, builtin);
- #undef BOOST_MPI_LIST2
- template <class T, class U>
- struct is_mpi_datatype<std::pair<T,U> >
- : public mpl::and_<is_mpi_datatype<T>,is_mpi_datatype<U> >
- {
- };
- #if defined(__cplusplus) && (201103L <= __cplusplus)
- template<class T, std::size_t N>
- struct is_mpi_datatype<std::array<T, N> >
- : public is_mpi_datatype<T>
- {
- };
- #endif
- #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && \
- (defined(MPI_WCHAR) || (BOOST_MPI_VERSION >= 2))
- BOOST_MPI_DATATYPE(wchar_t, MPI_WCHAR, builtin);
- #endif
- #if defined(BOOST_HAS_LONG_LONG) && \
- (defined(MPI_LONG_LONG_INT) || (BOOST_MPI_VERSION >= 2))
- BOOST_MPI_DATATYPE(long long, MPI_LONG_LONG_INT, builtin);
- #elif defined(BOOST_HAS_MS_INT64) && \
- (defined(MPI_LONG_LONG_INT) || (BOOST_MPI_VERSION >= 2))
- BOOST_MPI_DATATYPE(__int64, MPI_LONG_LONG_INT, builtin);
- #endif
- #if defined(BOOST_HAS_LONG_LONG) && \
- (defined(MPI_UNSIGNED_LONG_LONG) \
- || (BOOST_MPI_VERSION >= 2))
- BOOST_MPI_DATATYPE(unsigned long long, MPI_UNSIGNED_LONG_LONG, builtin);
- #elif defined(BOOST_HAS_MS_INT64) && \
- (defined(MPI_UNSIGNED_LONG_LONG) \
- || (BOOST_MPI_VERSION >= 2))
- BOOST_MPI_DATATYPE(unsigned __int64, MPI_UNSIGNED_LONG_LONG, builtin);
- #endif
- #if defined(MPI_SIGNED_CHAR) || (BOOST_MPI_VERSION >= 2)
- BOOST_MPI_DATATYPE(signed char, MPI_SIGNED_CHAR, builtin);
- #endif
- #endif
- namespace detail {
- inline MPI_Datatype build_mpi_datatype_for_bool()
- {
-
- MPI_Datatype type;
- MPI_Type_contiguous(sizeof(bool), MPI_BYTE, &type);
- MPI_Type_commit(&type);
- return type;
- }
- }
- template<>
- inline MPI_Datatype get_mpi_datatype<bool>(const bool&)
- {
- static MPI_Datatype type = detail::build_mpi_datatype_for_bool();
- return type;
- }
- template<>
- struct is_mpi_datatype<bool>
- : boost::mpl::bool_<true>
- {};
- #ifndef BOOST_MPI_DOXYGEN
- BOOST_MPI_DATATYPE(boost::serialization::library_version_type, get_mpi_datatype(uint_least16_t()), integer);
- BOOST_MPI_DATATYPE(boost::archive::version_type, get_mpi_datatype(uint_least8_t()), integer);
- BOOST_MPI_DATATYPE(boost::archive::class_id_type, get_mpi_datatype(int_least16_t()), integer);
- BOOST_MPI_DATATYPE(boost::archive::class_id_reference_type, get_mpi_datatype(int_least16_t()), integer);
- BOOST_MPI_DATATYPE(boost::archive::class_id_optional_type, get_mpi_datatype(int_least16_t()), integer);
- BOOST_MPI_DATATYPE(boost::archive::object_id_type, get_mpi_datatype(uint_least32_t()), integer);
- BOOST_MPI_DATATYPE(boost::archive::object_reference_type, get_mpi_datatype(uint_least32_t()), integer);
- BOOST_MPI_DATATYPE(boost::archive::tracking_type, get_mpi_datatype(bool()), builtin);
- BOOST_MPI_DATATYPE(boost::serialization::collection_size_type, get_mpi_datatype(std::size_t()), integer);
- BOOST_MPI_DATATYPE(boost::serialization::item_version_type, get_mpi_datatype(uint_least8_t()), integer);
- #endif
- } }
- #define BOOST_IS_MPI_DATATYPE(T) \
- namespace boost { \
- namespace mpi { \
- template<> \
- struct is_mpi_datatype< T > : mpl::true_ {}; \
- }} \
- #endif
|