From 50f71c9b009f87d37e4a0c49e89f322293ff6070 Mon Sep 17 00:00:00 2001 From: Matthias Troyer Date: Thu, 29 Jul 2010 03:27:09 +0000 Subject: [PATCH] Changes required to make Boost.MPI work with Boost.Serialization after breaking changes for 1.44 [SVN r64423] --- include/boost/mpi/datatype.hpp | 20 ++++++++++++++++ include/boost/mpi/datatype_fwd.hpp | 4 +++- .../mpi/detail/binary_buffer_iprimitive.hpp | 3 ++- .../mpi/detail/binary_buffer_oprimitive.hpp | 3 ++- .../boost/mpi/detail/ignore_iprimitive.hpp | 7 ------ .../mpi/detail/ignore_skeleton_oarchive.hpp | 3 +++ .../boost/mpi/detail/packed_iprimitive.hpp | 5 ++-- .../boost/mpi/detail/packed_oprimitive.hpp | 5 ++-- include/boost/mpi/intercommunicator.hpp | 4 ++-- include/boost/mpi/packed_iarchive.hpp | 23 +++++++++++++++---- include/boost/mpi/packed_oarchive.hpp | 19 +++++++++++---- src/packed_iarchive.cpp | 4 ---- src/packed_oarchive.cpp | 5 ---- src/packed_skeleton_iarchive.cpp | 8 +------ src/packed_skeleton_oarchive.cpp | 6 ----- src/text_skeleton_oarchive.cpp | 5 +--- 16 files changed, 72 insertions(+), 52 deletions(-) diff --git a/include/boost/mpi/datatype.hpp b/include/boost/mpi/datatype.hpp index f929319..517126b 100644 --- a/include/boost/mpi/datatype.hpp +++ b/include/boost/mpi/datatype.hpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include // for std::pair namespace boost { namespace mpi { @@ -298,6 +300,7 @@ BOOST_MPI_DATATYPE(unsigned __int64, MPI_UNSIGNED_LONG_LONG, builtin); BOOST_MPI_DATATYPE(signed char, MPI_SIGNED_CHAR, builtin); #endif + #endif // Doxygen namespace detail { @@ -325,6 +328,23 @@ struct is_mpi_datatype : boost::mpl::bool_ {}; + +#ifndef BOOST_MPI_DOXYGEN +// direct support for special primitive data types of the serialization library +BOOST_MPI_DATATYPE(boost::archive::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 // Doxygen + + } } // end namespace boost::mpi // define a macro to make explicit designation of this more transparent diff --git a/include/boost/mpi/datatype_fwd.hpp b/include/boost/mpi/datatype_fwd.hpp index 20dedb5..3a5f941 100644 --- a/include/boost/mpi/datatype_fwd.hpp +++ b/include/boost/mpi/datatype_fwd.hpp @@ -25,7 +25,9 @@ template struct is_mpi_logical_datatype; template struct is_mpi_complex_datatype; template struct is_mpi_byte_datatype; template struct is_mpi_datatype; -template MPI_Datatype get_mpi_datatype(const T& x = T()); +template MPI_Datatype get_mpi_datatype(const T& x); +template MPI_Datatype get_mpi_datatype() + { return get_mpi_datatype(T());} /// a dummy data type giving MPI_PACKED as its MPI_Datatype struct packed {}; diff --git a/include/boost/mpi/detail/binary_buffer_iprimitive.hpp b/include/boost/mpi/detail/binary_buffer_iprimitive.hpp index ccfae15..2bc028f 100644 --- a/include/boost/mpi/detail/binary_buffer_iprimitive.hpp +++ b/include/boost/mpi/detail/binary_buffer_iprimitive.hpp @@ -88,7 +88,8 @@ public: load_impl(&t, sizeof(T)); } - void load( std::string & s) + template + void load(std::basic_string & s) { unsigned int l; load(l); diff --git a/include/boost/mpi/detail/binary_buffer_oprimitive.hpp b/include/boost/mpi/detail/binary_buffer_oprimitive.hpp index 4d0d80e..facf360 100644 --- a/include/boost/mpi/detail/binary_buffer_oprimitive.hpp +++ b/include/boost/mpi/detail/binary_buffer_oprimitive.hpp @@ -79,7 +79,8 @@ public: save_impl(&t, sizeof(T)); } - void save(const std::string &s) + template + void save(const std::basic_string &s) { unsigned int l = static_cast(s.size()); save(l); diff --git a/include/boost/mpi/detail/ignore_iprimitive.hpp b/include/boost/mpi/detail/ignore_iprimitive.hpp index 9a8ece5..724d711 100644 --- a/include/boost/mpi/detail/ignore_iprimitive.hpp +++ b/include/boost/mpi/detail/ignore_iprimitive.hpp @@ -42,13 +42,6 @@ public: typedef is_mpi_datatype use_array_optimization; -#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS - friend class archive::load_access; -protected: -#else -public: -#endif - /// don't do anything when loading primitive types template void load(T & t) diff --git a/include/boost/mpi/detail/ignore_skeleton_oarchive.hpp b/include/boost/mpi/detail/ignore_skeleton_oarchive.hpp index ce77bd7..06a6bd5 100644 --- a/include/boost/mpi/detail/ignore_skeleton_oarchive.hpp +++ b/include/boost/mpi/detail/ignore_skeleton_oarchive.hpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace boost { namespace mpi { namespace detail { @@ -53,6 +54,7 @@ protected: BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(archive::class_id_optional_type) BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(archive::version_type) +BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(archive::library_version_type) BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(archive::class_id_type) BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(archive::class_id_reference_type) BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(archive::object_id_type) @@ -60,6 +62,7 @@ BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(archive::object_reference_type) BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(archive::tracking_type) BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(archive::class_name_type) BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(serialization::collection_size_type) +BOOST_ARCHIVE_IGNORE_IMPLEMENTATION(serialization::item_version_type) void save_override(std::string const & s, int) { diff --git a/include/boost/mpi/detail/packed_iprimitive.hpp b/include/boost/mpi/detail/packed_iprimitive.hpp index 58ba6bf..9471a00 100644 --- a/include/boost/mpi/detail/packed_iprimitive.hpp +++ b/include/boost/mpi/detail/packed_iprimitive.hpp @@ -86,7 +86,8 @@ public: load_impl(&t, get_mpi_datatype(t), 1); } - void load( std::string & s) + template + void load(std::basic_string & s) { unsigned int l; load(l); @@ -96,7 +97,7 @@ public: #endif s.resize(l); // note breaking a rule here - could be a problem on some platform - load_impl(const_cast(s.data()),MPI_CHAR,l); + load_impl(const_cast(s.data()),get_mpi_datatype(CharType()),l); } private: diff --git a/include/boost/mpi/detail/packed_oprimitive.hpp b/include/boost/mpi/detail/packed_oprimitive.hpp index 84d06b5..eb7ba2f 100644 --- a/include/boost/mpi/detail/packed_oprimitive.hpp +++ b/include/boost/mpi/detail/packed_oprimitive.hpp @@ -77,11 +77,12 @@ public: save_impl(&t, get_mpi_datatype(t), 1); } - void save(const std::string &s) + template + void save(const std::basic_string &s) { unsigned int l = static_cast(s.size()); save(l); - save_impl(s.data(),MPI_CHAR,s.size()); + save_impl(s.data(),get_mpi_datatype(CharType()),s.size()); } private: diff --git a/include/boost/mpi/intercommunicator.hpp b/include/boost/mpi/intercommunicator.hpp index 8a1fd98..ad246b5 100644 --- a/include/boost/mpi/intercommunicator.hpp +++ b/include/boost/mpi/intercommunicator.hpp @@ -59,9 +59,9 @@ private: * underlying MPI_Comm. This operation is used for "casting" from a * communicator to an intercommunicator. */ - explicit intercommunicator(const shared_ptr& comm_ptr) + explicit intercommunicator(const shared_ptr& cp) { - this->comm_ptr = comm_ptr; + this->comm_ptr = cp; } public: diff --git a/include/boost/mpi/packed_iarchive.hpp b/include/boost/mpi/packed_iarchive.hpp index 6b49def..d8b4376 100644 --- a/include/boost/mpi/packed_iarchive.hpp +++ b/include/boost/mpi/packed_iarchive.hpp @@ -20,10 +20,13 @@ #include #include -#include +#include #include #include #include +#include +#include +#include #include namespace boost { namespace mpi { @@ -44,7 +47,7 @@ namespace boost { namespace mpi { */ class BOOST_MPI_DECL packed_iarchive : public iprimitive - , public archive::basic_binary_iarchive + , public archive::detail::common_iarchive , public archive::detail::shared_ptr_helper { public: @@ -67,7 +70,7 @@ public: */ packed_iarchive(MPI_Comm const & comm, buffer_type & b, unsigned int flags = boost::archive::no_header, int position = 0) : iprimitive(b,comm,position), - archive::basic_binary_iarchive(flags) + archive::detail::common_iarchive(flags) {} /** @@ -87,7 +90,7 @@ public: ( MPI_Comm const & comm , std::size_t s=0, unsigned int flags = boost::archive::no_header) : iprimitive(internal_buffer_,comm) - , archive::basic_binary_iarchive(flags) + , archive::detail::common_iarchive(flags) , internal_buffer_(s) {} @@ -95,7 +98,7 @@ public: template void load_override(T& x, int version, mpl::false_) { - archive::basic_binary_iarchive::load_override(x,version); + archive::detail::common_iarchive::load_override(x,version); } // Load it directly using the primnivites @@ -115,6 +118,16 @@ public: load_override(x, version, use_optimized()); } + void load_override(archive::class_name_type & t, int) + { + std::string cn; + cn.reserve(BOOST_SERIALIZATION_MAX_KEY_SIZE); + * this->This() >> cn; + std::memcpy(t, cn.data(), cn.size()); + // borland tweak + t.t[cn.size()] = '\0'; + } + private: /// An internal buffer to be used when the user does not supply his /// own buffer. diff --git a/include/boost/mpi/packed_oarchive.hpp b/include/boost/mpi/packed_oarchive.hpp index 274b1f0..c873bb4 100644 --- a/include/boost/mpi/packed_oarchive.hpp +++ b/include/boost/mpi/packed_oarchive.hpp @@ -20,9 +20,12 @@ #include #include -#include +#include #include #include +#include +#include +#include namespace boost { namespace mpi { @@ -43,7 +46,7 @@ namespace boost { namespace mpi { class BOOST_MPI_DECL packed_oarchive : public oprimitive, - public archive::basic_binary_oarchive + public archive::detail::common_oarchive { public: /** @@ -62,7 +65,7 @@ public: */ packed_oarchive( MPI_Comm const & comm, buffer_type & b, unsigned int flags = boost::archive::no_header) : oprimitive(b,comm), - archive::basic_binary_oarchive(flags) + archive::detail::common_oarchive(flags) {} /** @@ -78,14 +81,14 @@ public: */ packed_oarchive ( MPI_Comm const & comm, unsigned int flags = boost::archive::no_header) : oprimitive(internal_buffer_,comm), - archive::basic_binary_oarchive(flags) + archive::detail::common_oarchive(flags) {} // Save everything else in the usual way, forwarding on to the Base class template void save_override(T const& x, int version, mpl::false_) { - archive::basic_binary_oarchive::save_override(x,version); + archive::detail::common_oarchive::save_override(x,version); } // Save it directly using the primnivites @@ -103,6 +106,12 @@ public: save_override(x, version, use_optimized()); } + // explicitly convert to char * to avoid compile ambiguities + void save_override(const archive::class_name_type & t, int){ + const std::string s(t); + * this->This() << s; + } + private: /// An internal buffer to be used when the user does not supply his /// own buffer. diff --git a/src/packed_iarchive.cpp b/src/packed_iarchive.cpp index 4fceb73..a0ea5a6 100644 --- a/src/packed_iarchive.cpp +++ b/src/packed_iarchive.cpp @@ -11,15 +11,11 @@ #include #include -#include -#include -#include namespace boost { namespace archive { // explicitly instantiate all required templates -template class basic_binary_iarchive ; template class detail::archive_serializer_map ; } } // end namespace boost::archive diff --git a/src/packed_oarchive.cpp b/src/packed_oarchive.cpp index 4f5ad28..d340a40 100644 --- a/src/packed_oarchive.cpp +++ b/src/packed_oarchive.cpp @@ -8,17 +8,12 @@ #define BOOST_ARCHIVE_SOURCE #include - #include #include -#include -#include -#include namespace boost { namespace archive { // explicitly instantiate all required templates template class detail::archive_serializer_map ; -template class basic_binary_oarchive ; } } // end namespace boost::archive diff --git a/src/packed_skeleton_iarchive.cpp b/src/packed_skeleton_iarchive.cpp index 99b7d04..97115c2 100644 --- a/src/packed_skeleton_iarchive.cpp +++ b/src/packed_skeleton_iarchive.cpp @@ -10,22 +10,16 @@ #include #include - #include -#include -#include -#include - namespace boost { namespace archive { // explicitly instantiate all required templates -template class basic_binary_iarchive ; +// template class basic_binary_iarchive ; template class detail::archive_serializer_map ; template class detail::archive_serializer_map< mpi::detail::forward_skeleton_iarchive< boost::mpi::packed_skeleton_iarchive, boost::mpi::packed_iarchive> > ; -//template class binary_iarchive_impl ; } } // end namespace boost::archive diff --git a/src/packed_skeleton_oarchive.cpp b/src/packed_skeleton_oarchive.cpp index 8a33241..5cfecc0 100644 --- a/src/packed_skeleton_oarchive.cpp +++ b/src/packed_skeleton_oarchive.cpp @@ -8,12 +8,8 @@ #define BOOST_ARCHIVE_SOURCE #include - #include #include -#include -#include -#include namespace boost { namespace archive { // explicitly instantiate all required templates @@ -22,7 +18,5 @@ template class detail::archive_serializer_map ; template class detail::archive_serializer_map< mpi::detail::forward_skeleton_oarchive< boost::mpi::packed_skeleton_oarchive, boost::mpi::packed_oarchive> > ; -template class basic_binary_oarchive ; -//template class binary_oarchive_impl ; } } // end namespace boost::archive diff --git a/src/text_skeleton_oarchive.cpp b/src/text_skeleton_oarchive.cpp index dea8c8f..7817ea7 100644 --- a/src/text_skeleton_oarchive.cpp +++ b/src/text_skeleton_oarchive.cpp @@ -11,13 +11,10 @@ #include #include -#include -#include -#include namespace boost { namespace archive { // explicitly instantiate all required templates -template class detail::archive_serializer_map; +// template class detail::archive_serializer_map; } } // end namespace boost::archive