File indexing completed on 2025-01-18 09:40:57
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_MPI_BINARY_BUFFER_OPRIMITIVE_HPP
0010 #define BOOST_MPI_BINARY_BUFFER_OPRIMITIVE_HPP
0011
0012 #include <mpi.h>
0013 #include <iostream>
0014 #include <cstddef> // size_t
0015 #include <boost/config.hpp>
0016
0017 #include <boost/serialization/array.hpp>
0018 #include <boost/serialization/is_bitwise_serializable.hpp>
0019 #include <boost/assert.hpp>
0020 #include <boost/mpl/assert.hpp>
0021 #include <vector>
0022 #include <boost/mpi/allocator.hpp>
0023 #include <boost/mpl/always.hpp>
0024 #include <boost/type_traits/remove_const.hpp>
0025
0026 namespace boost { namespace mpi {
0027
0028
0029
0030 class BOOST_MPI_DECL binary_buffer_oprimitive
0031 {
0032 public:
0033
0034 typedef std::vector<char, allocator<char> > buffer_type;
0035
0036 binary_buffer_oprimitive(buffer_type & b, MPI_Comm const &)
0037 : buffer_(b)
0038 {
0039 }
0040
0041 void const * address() const
0042 {
0043 return detail::c_data(buffer_);
0044 }
0045
0046 const std::size_t& size() const
0047 {
0048 return size_ = buffer_.size();
0049 }
0050
0051 const std::size_t* size_ptr() const
0052 {
0053 return &size();
0054 }
0055
0056 void save_binary(void const *address, std::size_t count)
0057 {
0058 save_impl(address,count);
0059 }
0060
0061
0062 template<class T>
0063 void save_array(serialization::array_wrapper<T> const& x, unsigned int )
0064 {
0065
0066 BOOST_MPL_ASSERT((serialization::is_bitwise_serializable<BOOST_DEDUCED_TYPENAME remove_const<T>::type>));
0067 if (x.count())
0068 save_impl(x.address(), x.count()*sizeof(T));
0069 }
0070
0071 template<class T>
0072 void save(serialization::array_wrapper<T> const& x)
0073 {
0074 save_array(x,0u);
0075 }
0076
0077 typedef serialization::is_bitwise_serializable<mpl::_1> use_array_optimization;
0078
0079
0080 template<class T>
0081 void save(const T & t)
0082 {
0083 BOOST_MPL_ASSERT((serialization::is_bitwise_serializable<BOOST_DEDUCED_TYPENAME remove_const<T>::type>));
0084 save_impl(&t, sizeof(T));
0085 }
0086
0087 template<class CharType>
0088 void save(const std::basic_string<CharType> &s)
0089 {
0090 unsigned int l = static_cast<unsigned int>(s.size());
0091 save(l);
0092 save_impl(s.data(),s.size()*sizeof(CharType));
0093 }
0094
0095 private:
0096
0097 void save_impl(void const * p, int l)
0098 {
0099 char const* ptr = reinterpret_cast<char const*>(p);
0100 buffer_.insert(buffer_.end(),ptr,ptr+l);
0101 }
0102
0103 buffer_type& buffer_;
0104 mutable std::size_t size_;
0105 };
0106
0107 } }
0108
0109 #endif