I am trying to write MPI send / receive code, but I have a problem. I want to check the receipt of a message. If I have a message from any source, read this. Otherwise, continue the code.
MPI_Comm_size(MPI_COMM_WORLD,&p);
MPI_Comm_rank(MPI_COMM_WORLD,&id);
MPI_Status status;
int source,ask,request,answer,tag=10;
for(i=first; i<last; i++){
if(there is a message for my id){
MPI_Recv(&request,1,MPI_INT,MPI_ANY_SOURCE,tag,MPI_COMM_WORLD,&status);
answer = request*request;
source = status.MPI_SOURCE;
MPI_Send(&answer,1,MPI_INT,source,tag+1,MPI_COMM_WORLD);
}
square=i*i;
if(last < square){
MPI_Send(&square,1,MPI_INT,id-1,tag,MPI_COMM_WORLD);
MPI_Recv(&square,1,MPI_INT,id-1,tag+1,MPI_COMM_WORLD,&status);
}
local[i]=square;
}
If I cannot verify receipt of a message with an if statement, can I verify by timeout or wait? * I know this code is trivial, but I hope it can help us.
thank
source
share