Failure in 1D std::vector boost serialization

39 views Asked by At

I'm trying to serialize a std::vector as a member in the class, the attached code fails at throws segmentation fault that I've not been able to resolve this issue for weeks now. It's weird as it goes well in smaller size of container, but even this size is very small for memory issues.

#include <iostream>
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/mpi.hpp>
#include <boost/version.hpp>
class Dummy
{
private:
    std::vector<unsigned int> array;
    friend class boost::serialization::access;
    template <class T> 
    inline void serialize(T & ar, const unsigned int /*version*/)
    {ar & array;}
public:
    Dummy()
    {};
    Dummy(const int nDivs) 
    {array.resize(nDivs);}
    ~Dummy() {}; 
};
int main(int argc, char* const argv[]) 
{
    boost::mpi::environment   env; 

    boost::mpi::communicator  world;

    boost::mpi::request req; 

    std::cout << "Using Boost "     
          << BOOST_VERSION / 100000     << "."  // major version
          << BOOST_VERSION / 100 % 1000 << "."  // minor version
          << BOOST_VERSION % 100                // patch level
          << std::endl;

    int MASTER = 0; 
    int tag    = 0;
    std::size_t size = 10000;  
    std::vector<unsigned int> neighbrs = {0, 1, 2, 3};
    std::vector<Dummy> TobeSend (size, Dummy(2)); 
    std::vector<Dummy> TobeRecvd (size ,Dummy(1));

    for(auto itri:neighbrs)
    {
        int target = itri; 
        if(world.rank()!= target)
        {

            world.isend(target, tag, TobeSend);
            
        }
    }
    for(auto isource:neighbrs)
    {
        int source = isource;
        if(world.rank()!= source)
        {
            req= world.irecv(source, tag, TobeRecvd); 
            req.test(); 
        }
    }
    return 0; 
}

I'm building the code with: mpic++ -g mpidatatype.cpp -o output -lboost_mpi -lboost_serialization I've tried both version of 1.75 and 1.82. I'd appreciate help on this problem.

Here's the call stack as start of the program before sending occurs: enter image description here

1

There are 1 answers

2
MA19 On

So, I resolved this finally. The problem was missing

  namespace boost { namespace mpi {
      template<> struct is_mpi_datatype<Dummy>
        : public mpl::true_ { };
    } }

adding this line of code resolved my issue