有没有办法强制 MPI始终阻止发送?这在寻找分布式算法中的死锁时可能很有用,否则依赖于缓冲 MPI 可能选择在 send 上执行。
例如,以下程序(使用 2 个进程运行)在我的机器上运行没有问题:
// C++
#include <iostream>
#include <thread>
// Boost
#include <boost/mpi.hpp>
namespace mpi = boost::mpi;
int main() {
using namespace std::chrono_literals;
mpi::environment env;
mpi::communicator world;
auto me = world.rank();
auto other = 1 - me;
char buffer[10] = {0};
while (true) {
world.send(other, 0, buffer);
world.recv(other, 0, buffer);
std::cout << "Node " << me << " received" << std::endl;
std::this_thread::sleep_for(200ms);
}
}
但是,如果我将缓冲区的大小更改为10000,它会无限期地阻塞。