Boost logo

Boost Users :

Subject: Re: [Boost-users] Performance optimization in Boost using std::vector<>
From: saloo (salmanarshad9_at_[hidden])
Date: 2015-02-12 06:37:38


Thanks Gonzalo for a detailed explanation

So what I understand is to change the code in boost to following code :

#include <boost/mpi.hpp>
#include <iostream>
#include <boost/serialization/vector.hpp>
namespace mpi = boost::mpi;

int main()
{
  mpi::environment env;
  mpi::communicator world;
std::vector<int> my_vector;

if (world.rank() == 0) {
    my_vector.push_back(17);
    my_vector.push_back(38);
    world.send(1, 0, my_vector);
} else {
  std::vector<int> my_vector2;
  my_vector2.reserve(2);
  world.recv(0, 0, my_vector2);
}
  return 0;
}

What is the best option in boost to achieve a good performance? I saw in the
code of boost/serialization/vector.hpp that they have an optimized version
which keeps track of size and uses serialization wrapper of make_array. How
can I force boost to use optimized version for serializing? Below is the
code from boost/serialization/vector.hpp:

// the optimized versions

template<class Archive, class U, class Allocator>
inline void save(
    Archive & ar,
    const std::vector<U, Allocator> &t,
    const unsigned int /* file_version */,
    mpl::true_
){
    const collection_size_type count(t.size());
    ar << BOOST_SERIALIZATION_NVP(count);
    if (!t.empty())
        ar << make_array(detail::get_data(t),t.size());
}

template<class Archive, class U, class Allocator>
inline void load(
    Archive & ar,
    std::vector<U, Allocator> &t,
    const unsigned int /* file_version */,
    mpl::true_
){
    collection_size_type count(t.size());
    ar >> BOOST_SERIALIZATION_NVP(count);
    t.resize(count);
    unsigned int item_version=0;
    if(BOOST_SERIALIZATION_VECTOR_VERSIONED(ar.get_library_version())) {
        ar >> BOOST_SERIALIZATION_NVP(item_version);
    }
    if (!t.empty())
        ar >> make_array(detail::get_data(t),t.size());
  }

Or should I skip the boost completely and go to basic MPI commands to send
vector as MPI derived data type? Then I should keep in mind what you said
about std::unique_ptr and Vect<T> and also reserving memory in recieve
buffer at beginning of pragram and reusing it to prevent memopry allocation
during send/recieve. How can I reach a good perfomance solution using boost?
 Thanks

--
View this message in context: http://boost.2283326.n4.nabble.com/Performance-optimization-in-Boost-using-std-vector-tp4672196p4672215.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net