Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65997 - in trunk: boost/mpi boost/mpi/detail libs/mpi/test
From: troyer_at_[hidden]
Date: 2010-10-15 20:49:38


Author: troyer
Date: 2010-10-15 20:49:36 EDT (Fri, 15 Oct 2010)
New Revision: 65997
URL: http://svn.boost.org/trac/boost/changeset/65997

Log:
Fixed pointer serialization in Boost.MPI
Added:
   trunk/libs/mpi/test/pointer_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/mpi/detail/packed_iprimitive.hpp | 11 ++++-------
   trunk/boost/mpi/detail/packed_oprimitive.hpp | 28 +++++++++++++---------------
   trunk/boost/mpi/packed_iarchive.hpp | 3 +++
   trunk/boost/mpi/packed_oarchive.hpp | 3 +++
   trunk/libs/mpi/test/Jamfile.v2 | 1 +
   5 files changed, 24 insertions(+), 22 deletions(-)

Modified: trunk/boost/mpi/detail/packed_iprimitive.hpp
==============================================================================
--- trunk/boost/mpi/detail/packed_iprimitive.hpp (original)
+++ trunk/boost/mpi/detail/packed_iprimitive.hpp 2010-10-15 20:49:36 EDT (Fri, 15 Oct 2010)
@@ -10,7 +10,6 @@
 #define BOOST_MPI_PACKED_IPRIMITIVE_HPP
 
 #include <boost/mpi/config.hpp>
-#include <iostream>
 #include <cstddef> // size_t
 #include <boost/config.hpp>
 #include <boost/mpi/datatype.hpp>
@@ -71,11 +70,13 @@
         load_impl(x.address(), get_mpi_datatype(*x.address()), x.count());
     }
 
+/*
     template<class T>
     void load(serialization::array<T> const& x)
     {
       load_array(x,0u);
     }
+*/
 
     typedef is_mpi_datatype<mpl::_1> use_array_optimization;
 
@@ -83,7 +84,7 @@
     template<class T>
     void load( T & t)
     {
- load_impl(&t, get_mpi_datatype(t), 1);
+ load_impl(&t, get_mpi_datatype(t), 1);
     }
 
     template<class CharType>
@@ -91,10 +92,6 @@
     {
         unsigned int l;
         load(l);
- // borland de-allocator fixup
-// #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
-// if(NULL != s.data())
-// #endif
         s.resize(l);
         // note breaking a rule here - could be a problem on some platform
         load_impl(const_cast<CharType *>(s.data()),get_mpi_datatype(CharType()),l);
@@ -104,7 +101,7 @@
 
     void load_impl(void * p, MPI_Datatype t, int l)
     {
- BOOST_MPI_CHECK_RESULT(MPI_Unpack,
+ BOOST_MPI_CHECK_RESULT(MPI_Unpack,
         (const_cast<char*>(boost::serialization::detail::get_data(buffer_)), buffer_.size(), &position, p, l, t, comm));
     }
 

Modified: trunk/boost/mpi/detail/packed_oprimitive.hpp
==============================================================================
--- trunk/boost/mpi/detail/packed_oprimitive.hpp (original)
+++ trunk/boost/mpi/detail/packed_oprimitive.hpp 2010-10-15 20:49:36 EDT (Fri, 15 Oct 2010)
@@ -10,7 +10,6 @@
 #define BOOST_MPI_PACKED_OPRIMITIVE_HPP
 
 #include <boost/mpi/config.hpp>
-#include <iostream>
 #include <cstddef> // size_t
 #include <boost/config.hpp>
 
@@ -74,7 +73,7 @@
     template<class T>
     void save(const T & t)
     {
- save_impl(&t, get_mpi_datatype<T>(t), 1);
+ save_impl(&t, get_mpi_datatype<T>(t), 1);
     }
 
     template<class CharType>
@@ -88,23 +87,22 @@
 private:
 
     void save_impl(void const * p, MPI_Datatype t, int l)
- {
- // allocate enough memory
+ {
+ // allocate enough memory
       int memory_needed;
       BOOST_MPI_CHECK_RESULT(MPI_Pack_size,(l,t,comm,&memory_needed));
 
- int position = buffer_.size();
- buffer_.resize(position + memory_needed);
+ int position = buffer_.size();
+ buffer_.resize(position + memory_needed);
 
- // pack the data into the buffer
- BOOST_MPI_CHECK_RESULT(MPI_Pack,
- (const_cast<void*>(p), l, t, boost::serialization::detail::get_data(buffer_), buffer_.size(), &position, comm));
-
- // reduce the buffer size if needed
- BOOST_ASSERT(std::size_t(position) <= buffer_.size());
- if (std::size_t(position) < buffer_.size())
- buffer_.resize(position);
- }
+ // pack the data into the buffer
+ BOOST_MPI_CHECK_RESULT(MPI_Pack,
+ (const_cast<void*>(p), l, t, boost::serialization::detail::get_data(buffer_), buffer_.size(), &position, comm));
+ // reduce the buffer size if needed
+ BOOST_ASSERT(std::size_t(position) <= buffer_.size());
+ if (std::size_t(position) < buffer_.size())
+ buffer_.resize(position);
+ }
 
   buffer_type& buffer_;
   mutable std::size_t size_;

Modified: trunk/boost/mpi/packed_iarchive.hpp
==============================================================================
--- trunk/boost/mpi/packed_iarchive.hpp (original)
+++ trunk/boost/mpi/packed_iarchive.hpp 2010-10-15 20:49:36 EDT (Fri, 15 Oct 2010)
@@ -118,6 +118,9 @@
     load_override(x, version, use_optimized());
   }
 
+ // input archives need to ignore the optional information
+ void load_override(archive::class_id_optional_type & /*t*/, int){}
+
   void load_override(archive::class_name_type & t, int)
   {
     std::string cn;

Modified: trunk/boost/mpi/packed_oarchive.hpp
==============================================================================
--- trunk/boost/mpi/packed_oarchive.hpp (original)
+++ trunk/boost/mpi/packed_oarchive.hpp 2010-10-15 20:49:36 EDT (Fri, 15 Oct 2010)
@@ -108,6 +108,9 @@
     save_override(x, version, use_optimized());
   }
 
+ // input archives need to ignore the optional information
+ void save_override(const archive::class_id_optional_type & /*t*/, int){}
+
   // explicitly convert to char * to avoid compile ambiguities
   void save_override(const archive::class_name_type & t, int){
       const std::string s(t);

Modified: trunk/libs/mpi/test/Jamfile.v2
==============================================================================
--- trunk/libs/mpi/test/Jamfile.v2 (original)
+++ trunk/libs/mpi/test/Jamfile.v2 2010-10-15 20:49:36 EDT (Fri, 15 Oct 2010)
@@ -32,5 +32,6 @@
   # Note: Microsoft MPI fails all skeleton-content tests
   [ mpi-test skeleton_content_test : : : 2 3 4 7 8 13 17 ]
   [ mpi-test graph_topology_test : : : 2 7 13 ]
+ [ mpi-test pointer_test : : : 2 ]
   ;
 }

Added: trunk/libs/mpi/test/pointer_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/mpi/test/pointer_test.cpp 2010-10-15 20:49:36 EDT (Fri, 15 Oct 2010)
@@ -0,0 +1,44 @@
+// Copyright (C) 2005, 2006 Douglas Gregor.
+
+// Use, modification and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+// a test of pointer serialization
+#include <boost/mpi.hpp>
+#include <boost/test/minimal.hpp>
+#include <boost/serialization/shared_ptr.hpp>
+
+class A
+{
+ public:
+ int i;
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version)
+ {
+ ar & i;
+ }
+};
+
+int test_main(int argc, char* argv[])
+{
+ boost::mpi::environment env(argc, argv);
+ boost::mpi::communicator world;
+
+ if(world.rank() == 0)
+ {
+ boost::shared_ptr<A> p(new A);
+ p->i = 42;
+ world.send(1, 0, p);
+ }
+ else if(world.rank() == 1)
+ {
+ boost::shared_ptr<A> p;
+ world.recv(0, 0, p);
+ std::cout << p->i << std::endl;
+ BOOST_CHECK(p->i==42);
+ }
+ return 0;
+}
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk