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) {
    world.send(1, 0, my_vector);
} else {
  std::vector<int> my_vector2;
  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 */,
    const collection_size_type count(t.size());
    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 */,
    collection_size_type count(t.size());
    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?

View this message in context:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at