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_DETAIL_MPI_DATATYPE_OPRIMITIVE_HPP
10 #define BOOST_MPI_DETAIL_MPI_DATATYPE_OPRIMITIVE_HPP
12 #include <boost/mpi/config.hpp>
13 #include <cstddef> // size_t
15 #include <boost/config.hpp>
16 #if defined(BOOST_NO_STDC_NAMESPACE)
22 #include <boost/mpi/datatype_fwd.hpp>
23 #include <boost/mpi/exception.hpp>
24 #include <boost/throw_exception.hpp>
25 #include <boost/assert.hpp>
26 #include <boost/mpl/placeholders.hpp>
27 #include <boost/serialization/array.hpp>
31 #include <boost/mpi/detail/antiques.hpp>
33 namespace boost { namespace mpi { namespace detail {
35 /////////////////////////////////////////////////////////////////////////
36 // class mpi_data_type_oprimitive - creation of custom MPI data types
38 class mpi_datatype_primitive
42 // trivial default constructor
43 mpi_datatype_primitive()
44 : is_committed(false),
48 mpi_datatype_primitive(void const* orig)
49 : is_committed(false),
52 #if defined(MPI_VERSION) && MPI_VERSION >= 2
53 BOOST_MPI_CHECK_RESULT(MPI_Get_address,(const_cast<void*>(orig), &origin));
55 BOOST_MPI_CHECK_RESULT(MPI_Address,(const_cast<void*>(orig), &origin));
59 void save_binary(void const *address, std::size_t count)
61 save_impl(address,MPI_BYTE,count);
64 // fast saving of arrays of MPI types
66 void save_array(serialization::array_wrapper<T> const& x, unsigned int /* version */)
69 save_impl(x.address(), boost::mpi::get_mpi_datatype(*x.address()), x.count());
72 typedef is_mpi_datatype<mpl::_1> use_array_optimization;
74 // create and return the custom MPI data type
75 MPI_Datatype get_mpi_datatype()
79 #if defined(MPI_VERSION) && MPI_VERSION >= 2
80 BOOST_MPI_CHECK_RESULT(MPI_Type_create_struct,
89 BOOST_MPI_CHECK_RESULT(MPI_Type_struct,
98 BOOST_MPI_CHECK_RESULT(MPI_Type_commit,(&datatype_));
106 // default saving of primitives.
108 void save(const T & t)
110 save_impl(&t, boost::mpi::get_mpi_datatype(t), 1);
115 void save_impl(void const * p, MPI_Datatype t, int l)
117 BOOST_ASSERT ( !is_committed );
119 // store address, type and length
122 #if defined(MPI_VERSION) && MPI_VERSION >= 2
123 BOOST_MPI_CHECK_RESULT(MPI_Get_address,(const_cast<void*>(p), &a));
125 BOOST_MPI_CHECK_RESULT(MPI_Address,(const_cast<void*>(p), &a));
127 addresses.push_back(a-origin);
129 lengths.push_back(l);
132 std::vector<MPI_Aint> addresses;
133 std::vector<MPI_Datatype> types;
134 std::vector<int> lengths;
137 MPI_Datatype datatype_;
142 } } } // end namespace boost::mpi::detail
145 #endif // BOOST_MPI_DETAIL_MPI_DATATYPE_OPRIMITIVE_HPP