【发布时间】:2019-11-08 09:16:14
【问题描述】:
当我想通过 MPI_Send 发送非常大的消息时遇到了一个问题:有多个处理器,我们需要传输的 int 总数是 2^25,我以 1000 的大小测试我的代码运行良好, 但是如果我把它设置为教授要求的尺寸,它会卡住很长时间,并返回一些这样的信息:
2 more processes have sent help message help-mpi-btl-base.txt / btl:no-nics
Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages
Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
mpiexec noticed that process rank 0 with PID 0 on node srv-p22-13 exited on signal 24 (CPU time limit exceeded).
我在每行代码之后都使用了“cout”,我确信它卡在 MPI_Send 行之前,Si 的大小超过 20,000,000。我不确定是不是这个原因?但是我搜索到 MPI_Send 的最大限制是 2^32-1...大于 2^25...所以我感到困惑。
这是我的代码的主要部分:
//This is send part
for(int i=0; i<5; i++){
if(i!=my_rank){//my_rank is from MPI_Comm_rank(MPI_COMM_WORLD, &my_rank)
int n = A.size();//A is a vector of int
int* Si= new int[n];//I want to convert vector to a int array
std::copy(A.begin(),A.end(),Si);
MPI_Send(&Si, n, Type, i, my_rank ,MPI_COMM_WORLD);//**The code stuck here and says CPU time limit exceeded
delete[] Si;
}
}
MPI_Barrier(MPI_COMM_WORLD);//I want all the processor finish sending part, then start receive and save in vector
//This is receive part
for(int i=0; i<5; i++){
if(i!=my_rank){
MPI_Status status;
MPI_Probe(i,i,MPI_COMM_WORLD,&status);
int rn = 0;
MPI_Get_count(&status, Type, &rn);
int* Ri = new int[rn];
MPI_Recv(Ri, rn, Type, i, i, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
/*Save received elements into vector A*/
for(int i=0; i<sizeof(Ri);i++){
inout.push_back(A);
}
}
}
【问题讨论】:
-
@rustyx size=5。谢谢你的提及,我会添加必要的值。
-
您能否发布更多代码,尤其是包含接收的部分?对于短数组,MPI 可能使用 缓冲 发送,它隐藏了一些死锁。对于较大的数组,使用 同步 发送,然后由于发送/接收调用的错误顺序而阻塞程序。
-
@jacob 感谢您的建议,我是 Stack 的新手,我看到它说不要粘贴整个代码,所以我想也许只发布有问题的部分就可以了......但你是对的,可能错误是基于structor,我已经添加了receive部分。
-
@jacob,我只是看看,它看起来很相似,谢谢你分享这个参考,我会通过它看看是否能解决我的问题。非常感谢!
-
@jacob 这真的解决了我的问题,谢谢!!!