Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] Problems with MPI_Iprobe
From: Thatyene Louise Alves de Souza Ramos (thatyene_at_[hidden])
Date: 2011-08-02 15:15:05


I am having this problem too. If someone could help, I will appreciate!

On Fri, Jul 22, 2011 at 5:29 PM, Rodrigo Oliveira <rsilva.oliveira_at_[hidden]
> 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
> users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/users
>