我想运行一个程序来了解MPI_Isend和MPI_Irecv的工作原理。排名0的Isend和Irecv工作正常,但排名5的Irecv采用默认值。有人可以解释我吗?
#include<stdio.h>
#include<mpi.h>
#include<stdlib.h>
#include<string.h>
int main(int argc , char *argv[])
{
int rank;
int size;
int i;
int index;
int ph_number[10] ={1,2,3,4,5,6,7,8,9};
int recv_numb[10];
MPI_Status status;
MPI_Request request;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if(rank ==0)
{
MPI_Isend(&ph_number,8,MPI_INT,0,10,MPI_COMM_WORLD, &request);
MPI_Isend(&ph_number,8,MPI_INT,5,11,MPI_COMM_WORLD, &request);
MPI_Irecv(&recv_numb,9,MPI_INT,0,10,MPI_COMM_WORLD, &request);
printf("recv number[7] = %d \n \n ", recv_numb[7]);
}
if(rank==5)
{
MPI_Irecv(&recv_numb,9,MPI_INT,0,11,MPI_COMM_WORLD,&request);
printf("recv number[5] = %d in rank %d\n \n ",recv_numb[5],rank);
}
MPI_Finalize();
}
答案 0 :(得分:0)
MPI_Wait(&request, &status);
重点是排名&gt; 1正在非阻塞模式下接收并且您错过了数据。你必须检查 MPI_Irecv 的返回值,或者在接收后调用 MPI_Wait (但它没用,因为你可以简单地使用阻塞 MPI_Recv )。
rank 0 Isend() -- rank x Irecv()
\---- printf()
\-------------> //data are received now, but output is already printed