我对这部分代码有些问题(我把它简化得更清楚了)。
//p is the number of processor (we suppose 2)
//vett is the vector who contains the elements to send
//disp is a vector whose elements are the index of the first element to send
//elem is a vector whose elements are the number of elements to send
//local_v is the destination vector (of dimension elem[rank])
//local_n is the number of elements that have to arrive (=elem[rank])
在我的情况下,循环只执行一次
for(unsigned int i = 1; i < p; i++){
if(rank==0){
MPI_Send(&vett[disp[i]], elem[i], MPI_INT, i, 0, MPI_COMM_WORLD);
}else{
MPI_Recv(&local_v, local_n, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
}
}
Processor1发送给另一个(在这种情况下只有处理器2)。我不确定我是否正确使用MPI_Send,特别是我不确定第一个输入参数是否正确...
答案 0 :(得分:-1)
在MPI_Recv
接收缓冲区后缺少[0]
,这就是整行:
MPI_Recv(&local_v[0], local_n, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);