【问题标题】:Is there a limit for the message size in mpi using boost::mpi?使用 boost::mpi 对 mpi 中的消息大小有限制吗?
【发布时间】:2015-03-14 00:19:04
【问题描述】:

我目前正在使用 boost::mpi 在 openMPI 之上编写一个模拟,并且一切正常。但是,一旦我扩大系统规模并因此必须发送更大的 std::vectors 就会出错。

我已将问题简化为以下问题:

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

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

    std::vector<char> a;
    std::vector<char> b;
    if (world.rank() == 0) {
        for (size_t i = 1; i < 1E10; i *= 2) {
            a.resize(i);
            std::cout << "a " << a.size();
            world.isend(0, 0, a);
            world.recv(0, 0, b);
            std::cout << "\tB " << b.size() << std::endl;
        }
    }
    return 0;
}

打印出来:

a 1 B 1
a 2 B 2
a 4 B 4
....
a 16384 B 16384
a 32768 B 32768
a 65536 B 65536
a 131072    B 0
a 262144    B 0
a 524288    B 0
a 1048576   B 0
a 2097152   B 0

我知道 mpi 消息大小是有限制的,但 65kB 对我来说似乎有点小。 有没有办法发送更大的消息?

【问题讨论】:

  • 根据this,您甚至不应该接近最大值。消息大小。不过不知道这里出了什么问题。
  • 如果将isend 更改为send 会发生什么?可能是非阻塞发送导致了问题。
  • @NathanOliver :如果我将 isend 更改为发送,它只会在写入 a 65536 B 65536 行后停止(阻塞)。
  • @tk - 你能查询recv返回的status吗?这可能会为您指明一个方向。
  • @NathanOliver 好的,我试过了:status.error() 总是返回 0。

标签: c++ mpi openmpi boost-mpi


【解决方案1】:

消息大小的限制与MPI_Send相同:INT_MAX。

问题是您没有等待isend 完成,然后在下一次迭代中调整向量a 的大小。这意味着isend 将由于向量a 中的重新分配而读取无效数据。请注意,缓冲区a 通过引用传递给boost::mpi,因此在isend 操作完成之前,您不能更改缓冲区a。

如果您使用valgrind 运行程序,您将在 i = 131072 时看到无效读取。

您的程序工作到 65536 字节的原因是,如果消息小于组件 btl_eager_limit,OpenMPI 将直接发送消息。对于self 组件(发送到自己的进程),这恰好是128*1024 字节。由于boost::serialization 将std::vector 的大小添加到字节流中,因此只要使用128*1024 = 131072 作为输入大小,就会超过eager_limit。

要修复您的代码,请保存来自isend() 的boost::mpi::request 返回值,然后将wait() 添加到循环末尾:

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

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

    std::vector<char> a;
    std::vector<char> b;
    if (world.rank() == 0) {
        for (size_t i = 1; i < 1E9; i *= 2) {
            a.resize(i);
            std::cout << "a " << a.size();
            mpi::request req = world.isend(0, 0, a);
            world.recv(0, 0, b);
            std::cout << "\tB " << b.size() << std::endl;
            req.wait();
        }
    }
    return 0;
}

【讨论】:

    猜你喜欢
    • 2011-05-15
    • 1970-01-01
    • 2015-08-20
    • 2019-10-25
    • 2014-10-02
    • 2018-05-25
    • 2015-08-10
    • 1970-01-01
    • 2013-03-27
    相关资源
    最近更新 更多