It looks like a garden variety race condition -- MCW rank 1 is probably calling MPI_Iprobe before the message has actually been delivered by MCW rank 0.
Try putting in a sleep(1) (or some other kind of delay) before your MPI_Iprobe, and I'll bet that the first call to MPI_Iprobe will return has_message=1. Or just use MPI_Probe -- it blocks, unlike MPI_Iprobe. On Jul 22, 2011, at 4:29 PM, Rodrigo Oliveira wrote: > Hi there. > > I have an application in which I need to terminate a process anytime due an > external command. In order to maintain the consistence of the processes, I > need to receive the messages that were already sent to the terminating > process. I used the MPI_Iprobe to check whether there is messages to be > received, but I noticed that I have to call this function twice. Otherwise it > does not work properly. The code bellow exemplifies what happens. Can anyone > help me? Is there another way to do what I need? > > Thanks in advance. > > > #include "mpi.h" > #include <stdio.h> > > int main(int argc, char *argv[]) { > int rank, size, i; > MPI_Status status; > > MPI_Init(&argc, &argv); > MPI_Comm_size(MPI_COMM_WORLD, &size); > MPI_Comm_rank(MPI_COMM_WORLD, &rank); > > if (size < 2) { > printf("Please run with two processes.\n"); fflush(stdout); > MPI_Finalize(); > return 0; > } > if (rank == 0) { > for (i=0; i<10; i++) { > MPI_Send(&i, 1, MPI_INT, 1, 123, MPI_COMM_WORLD); > } > } > if (rank == 1) { > int value, has_message; > MPI_Status status; > sleep (2); > > // Code bellow does not work properly > MPI_Iprobe(0, 123, MPI_COMM_WORLD, &has_message, &status); > while (has_message) { > MPI_Recv(&value, 1, MPI_INT, 0, 123, MPI_COMM_WORLD, > &status); > printf("Process %d received message %d.\n", rank, > value); > MPI_Iprobe(0, 123, MPI_COMM_WORLD, &has_message, > &status); > } > > // Calling MPI_Iprobe twice for each incoming message makes the > code work. > /* > MPI_Iprobe(0, 123, MPI_COMM_WORLD, &has_message, &status); > MPI_Iprobe(0, 123, MPI_COMM_WORLD, &has_message, &status); > while (has_message) { > MPI_Recv(&value, 1, MPI_INT, 0, 123, MPI_COMM_WORLD, > &status); > printf("Process %d received message %d.\n", rank, > value); > MPI_Iprobe(0, 123, MPI_COMM_WORLD, &has_message, > &status); > MPI_Iprobe(0, 123, MPI_COMM_WORLD, &has_message, > &status); > } > */ > > fflush(stdout); > } > MPI_Finalize(); > return 0; > } > _______________________________________________ > users mailing list > us...@open-mpi.org > http://www.open-mpi.org/mailman/listinfo.cgi/users -- Jeff Squyres jsquy...@cisco.com For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/