0

The following code gives this error message:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl'
what(): MPI_Test: MPI_ERR_TRUNCATE: message truncated

The problem might be related to a bug of boost::mpi which is discussed in this post. I want to be sure about reason of the error.

The code works if I loop only once (for (int z=0; z<1; ++z)) but for z<2 I get the mentioned error message.

#include <boost/mpi.hpp>

class MyClass
{
    std::vector<double> vec;

    public:

    void send_data(const boost::mpi::communicator& world, boost::mpi::request& req)
    {
        if (world.rank() == 0)
        {
            vec.resize(1000);
            req = world.isend(1, 0, vec);
        }
    }

    void recv_data(const boost::mpi::communicator& world)
    {
        if (world.rank() == 1)
        {
            while (true)
            {
                boost::mpi::request req = world.irecv(boost::mpi::any_source, 0, vec);
                if (!req.test())
                {
                    req.cancel();
                    //req.wait(); <-- hangs the program.
                    break;
                }
            }
        }
    }
};

int main()
{
    boost::mpi::environment env;
    boost::mpi::communicator world;

    MyClass myclass;

    for (int z=0; z<2; ++z) // works if loop only once.
    {
        boost::mpi::request req;

        myclass.send_data(world, req);
        world.barrier();
        myclass.recv_data(world);
        world.barrier();
        if (world.rank() == 0)
            req.wait();
    }

    return 0;
}
Shibli
  • 5,879
  • 13
  • 62
  • 126

1 Answers1

1

There is a bug when there are multiple irecv on the same communicator, tag, source for serialized types that seems very related. So you could try that with different tags. Nevertheless it wouldn't work due to the bug with cancel...

Zulan
  • 21,896
  • 6
  • 49
  • 109
  • Seems like the bug still exists. Using different tags for my messages resolved the error. – nareddyt Mar 04 '19 at 05:40
  • 1
    @nareddyt actually, it should have been fixed recently by this merged PR https://github.com/boostorg/mpi/pull/71 – Zulan Mar 04 '19 at 08:45