File indexing completed on 2025-01-18 09:40:57
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_MPI_PACKED_IPRIMITIVE_HPP
0010 #define BOOST_MPI_PACKED_IPRIMITIVE_HPP
0011
0012 #include <boost/mpi/config.hpp>
0013 #include <cstddef> // size_t
0014 #include <boost/config.hpp>
0015 #include <boost/mpi/datatype.hpp>
0016 #include <boost/mpi/exception.hpp>
0017 #include <boost/mpi/detail/antiques.hpp>
0018 #include <boost/serialization/array.hpp>
0019 #include <vector>
0020 #include <boost/mpi/detail/antiques.hpp>
0021 #include <boost/mpi/allocator.hpp>
0022
0023 namespace boost { namespace mpi {
0024
0025
0026
0027 class BOOST_MPI_DECL packed_iprimitive
0028 {
0029 public:
0030
0031 typedef std::vector<char, allocator<char> > buffer_type;
0032
0033 packed_iprimitive(buffer_type & b, MPI_Comm const & comm, int position = 0)
0034 : buffer_(b),
0035 comm(comm),
0036 position(position)
0037 {
0038 }
0039
0040 void* address ()
0041 {
0042 return detail::c_data(buffer_);
0043 }
0044
0045 void const* address () const
0046 {
0047 return detail::c_data(buffer_);
0048 }
0049
0050 const std::size_t& size() const
0051 {
0052 return size_ = buffer_.size();
0053 }
0054
0055 void resize(std::size_t s)
0056 {
0057 buffer_.resize(s);
0058 }
0059
0060 void load_binary(void *address, std::size_t count)
0061 {
0062 load_impl(address,MPI_BYTE,count);
0063 }
0064
0065
0066 template<class T>
0067 void load_array(serialization::array_wrapper<T> const& x, unsigned int )
0068 {
0069 if (x.count())
0070 load_impl(x.address(), get_mpi_datatype(*x.address()), x.count());
0071 }
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 typedef is_mpi_datatype<mpl::_1> use_array_optimization;
0082
0083
0084 template<class T>
0085 void load( T & t)
0086 {
0087 load_impl(&t, get_mpi_datatype(t), 1);
0088 }
0089
0090 template<class CharType>
0091 void load(std::basic_string<CharType> & s)
0092 {
0093 unsigned int l;
0094 load(l);
0095 s.resize(l);
0096
0097 if (l)
0098 load_impl(const_cast<CharType *>(s.data()),
0099 get_mpi_datatype(CharType()),l);
0100 }
0101
0102 private:
0103
0104 void load_impl(void * p, MPI_Datatype t, int l)
0105 {
0106 BOOST_MPI_CHECK_RESULT(MPI_Unpack,
0107 (const_cast<char*>(detail::c_data(buffer_)), buffer_.size(), &position, p, l, t, comm));
0108 }
0109
0110 buffer_type & buffer_;
0111 mutable std::size_t size_;
0112 MPI_Comm comm;
0113 int position;
0114 };
0115
0116 } }
0117
0118 #endif