【发布时间】:2019-10-25 10:01:37
【问题描述】:
在以下测试代码中,如果我将 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;
}
【问题讨论】:
-
您使用哪个
SIZE值来证明问题? -
您正在从 proc 0 发送到 proc 0,因此阻塞发送将死锁。也许您希望发送 proc 循环从 1 而不是 0 开始。