LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Ralf Wildenhues (Ralf.Wildenhues_at_[hidden])
Date: 2004-08-29 05:54:40


* Ahmad Faraj wrote on Sun, Aug 29, 2004 at 03:12:40AM CEST:
> hi all;
> i have this code snippet, it gives me errors that i really cant explain:

Quick shot:

> int main (int argc, char *argv[])
> {
> MPI_Request * req;
> int my_rank;
> char tmp = 'a';
>
> MPI_Init(&argc, &argv);
> MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
>
> if(my_rank==0)
> {
> req = malloc(2 * sizeof(MPI_Request));

nits: req != NULL? stdlib.h included?

> MPI_Irecv(&tmp, 1, MPI_CHAR, 0, 3, MPI_COMM_WORLD, &req[0]);
> MPI_Isend(&tmp, 1, MPI_CHAR, 0, 3, MPI_COMM_WORLD, &req[1]);

This is a bug. You may not re-use the buffer &tmp at this point, as the
Irecv can write there until the Waitall is completed.

> MPI_Waitall(2, req, MPI_STATUSES_IGNORE);
>
> MPI_Request_free(&req[0]);
> MPI_Request_free(&req[1]);

MPI_Waitall deallocates the MPI_Request data. No need (and that fixes
the bug you reported) to call MPI_Request_free().

> free((char*)req);

cast to char* is not necessary.

> }
>
> return 0;
> }
>
> here is the error
> MPI_Request_free: invalid request handle (rank 0, MPI_COMM_WORLD)
> Rank (0, MPI_COMM_WORLD): Call stack within LAM:
> Rank (0, MPI_COMM_WORLD): - MPI_Request_free()
> Rank (0, MPI_COMM_WORLD): - main()

Regards,
Ralf