1 // (C) Copyright 2005 Matthias Troyer
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Authors: Matthias Troyer
9 #ifndef BOOST_MPI_PACKED_IPRIMITIVE_HPP
10 #define BOOST_MPI_PACKED_IPRIMITIVE_HPP
12 #include <boost/mpi/config.hpp>
14 #include <cstddef> // size_t
15 #include <boost/config.hpp>
16 #include <boost/mpi/datatype.hpp>
17 #include <boost/mpi/exception.hpp>
18 #include <boost/assert.hpp>
19 #include <boost/serialization/array.hpp>
20 #include <boost/serialization/detail/get_data.hpp>
22 #include <boost/mpi/allocator.hpp>
24 namespace boost
{ namespace mpi
{
26 /// deserialization using MPI_Unpack
28 class BOOST_MPI_DECL packed_iprimitive
31 /// the type of the buffer from which the data is unpacked upon deserialization
32 typedef std::vector
<char, allocator
<char> > buffer_type
;
34 packed_iprimitive(buffer_type
& b
, MPI_Comm
const & comm
, int position
= 0)
46 void const* address () const
51 const std::size_t& size() const
53 return size_
= buffer_
.size();
56 void resize(std::size_t s
)
61 void load_binary(void *address
, std::size_t count
)
63 load_impl(address
,MPI_BYTE
,count
);
66 // fast saving of arrays of fundamental types
68 void load_array(serialization::array
<T
> const& x
, unsigned int /* file_version */)
71 load_impl(x
.address(), get_mpi_datatype(*x
.address()), x
.count());
75 void load(serialization::array
<T
> const& x
)
80 typedef is_mpi_datatype
<mpl::_1
> use_array_optimization
;
82 // default saving of primitives.
86 load_impl(&t
, get_mpi_datatype(t
), 1);
89 void load( std::string
& s
)
93 // borland de-allocator fixup
94 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
98 // note breaking a rule here - could be a problem on some platform
99 load_impl(const_cast<char *>(s
.data()),MPI_CHAR
,l
);
104 void load_impl(void * p
, MPI_Datatype t
, int l
)
106 BOOST_MPI_CHECK_RESULT(MPI_Unpack
,
107 (const_cast<char*>(boost::serialization::detail::get_data(buffer_
)), buffer_
.size(), &position
, p
, l
, t
, comm
));
110 buffer_type
& buffer_
;
111 mutable std::size_t size_
;
116 } } // end namespace boost::mpi
118 #endif // BOOST_MPI_PACKED_IPRIMITIVE_HPP