c++ - boost mpi:在 mpi 消息中传递的字符串变量是否有最大长度?
问题描述
在下面的测试代码中,如果我将 SIZE 参数设置为远高于 960,则不会传输任何消息。在 boost mpi 消息中传递的字符串变量是否有最大长度?也许字符串序列化存在限制,但我无法在文档中找到和限制......非常感谢任何帮助。
//compile: mpic++ -Wall gather-002.cpp -o gather-002 -lboost_mpi -lboost_serialization
//run: mpirun -np 4 ./gather-002
#include <boost/mpi.hpp>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
#define SIZE 960
namespace mpi = boost::mpi;
using namespace std;
int main(int argc, char* argv[])
{
mpi::environment env(argc, argv);
mpi::communicator world;
if (world.rank() == 0) {
string my_string = "MAIN";
for (int proc = 0; proc < world.size(); ++proc){
string outmessage = "";
for (int i = 0; i < SIZE; i++) outmessage = outmessage + "-";
world.send(proc, 0, outmessage);
}
vector<string> all_strings;
gather(world, my_string, all_strings, 0);
for (int proc = 0; proc < world.size(); ++proc)
cout << "Process #" << proc << " " << all_strings[proc] << endl;
}
else {
string inmessage;
world.recv(0,0,inmessage);
gather(world, inmessage, 0);
}
return 0;
}
解决方案
您的程序在world.send(0, 0, outmessage)
.
对于足够小的字符串,您的 MPI 库使调用成为非阻塞的,并且程序恰好运行。当超过 MPI 库用于消息大小的任何阈值时,它会切换到阻塞调用。由于没有人收到消息,发送无法继续,程序挂起。请注意,标准不需要所描述的行为:您不能依赖 MPI 库对小尺寸使用非阻塞。
从 MPI 3.1 标准,第 3.2.4 节:
Source=destination 是允许的,即进程可以向自己发送消息。(但是,使用上述阻塞发送和接收操作这样做是不安全的,因为这可能会导致死锁。
解决方案是不要从进程 0 向自身发送任何内容。
可以发送的最大大小是INT_MAX
,这取决于您可以给 MPI_Send 的最大计数。有关更多信息,请参阅此问题。
推荐阅读
- swift - 将 CharacterSet 转换为字符串或数组或字符集
- regex - Nginx,重定向的正则表达式无法正常工作
- java - Avro 模式演变在反序列化时抛出 EOFException
- android - 如何通过选择带有位置自动完成功能的标记来绘制路线?
- c# - 如何使用 c# 命令安装/添加虚拟打印机?
- javascript - 更改时引导日期选择器
- javascript - 在 ckeditor 中插入 html 会导致语法错误(laravel)
- filter - 如何过滤非空白行?
- jquery - 如何使用 jQuery 将动态数据添加到 selectpicker 上的选项?
- android - com.bumptech.glide.load.engine.GlideException 类:加载资源失败