1 /* -----------------------------------------------------------------------
3 * Lab: Parallel Processing Performance Tools
6 * You will need to stop the deadlocked program with <ctrl>\
7 * Author: Roslyn Leibensperger Last revised: 3/19/97 RYL
9 * Modified by Bill Gropp (ANL) to use Iprobe to detect the message and
10 * always produce output (no need to abort a deadlocked program).
11 * Unfortunately(?), the version of POE that had this bug is no longer
12 * available, so we can't test whether using Iprobe would show the same
14 * ------------------------------------------------------------------------ */
17 #define MSGLEN 100 /* length of message in elements */
21 int main( int argc, char *argv[] )
23 float message1 [MSGLEN], /* message buffers */
26 int rank, /* rank of task in communicator */
27 dest=0, source=0, /* rank in communicator of destination */
28 /* and source tasks */
29 send_tag=0, recv_tag=0, /* message tags */
31 int errs = 0, toterrs;
32 MPI_Status status; /* status of communication */
33 MPI_Status statuses[2];
34 MPI_Request requests[2];
36 MPI_Init( &argc, &argv );
37 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
38 MPI_Comm_size( MPI_COMM_WORLD, &size );
40 printf( "Must run with exactly 2 processes\n" );
41 MPI_Abort( MPI_COMM_WORLD, 1 );
43 /* printf ( " Task %d initialized\n", rank ); */
45 /* initialize message buffers */
46 for ( i=0; i<MSGLEN; i++ )
52 /* ---------------------------------------------------------------
53 * each task sets its message tags for the send and receive, plus
54 * the destination for the send, and the source for the receive
55 * --------------------------------------------------------------- */
71 /* ---------------------------------------------------------------
72 * send and receive messages
73 * --------------------------------------------------------------- */
74 /* printf ( " Task %d has sent the message\n", rank ); */
75 MPI_Isend ( message1, MSGLEN, MPI_FLOAT, dest, send_tag, MPI_COMM_WORLD, &requests[0] );
76 MPI_Irecv ( message2, MSGLEN, MPI_FLOAT, source, recv_tag, MPI_COMM_WORLD, &requests[1] );
78 /* See if we can receive the message on COMM_SELF...
79 * This should *never* be possible, but if TV is to be believed may happen
82 MPI_Iprobe( MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_SELF, &flag, &status );
85 printf ( " Task %d has received the message on COMM_SELF !\n", rank );
88 MPI_Recv( message3, MSGLEN, MPI_FLOAT, source, send_tag, MPI_COMM_WORLD,
90 MPI_Send( message3, MSGLEN, MPI_FLOAT, dest, recv_tag, MPI_COMM_WORLD );
91 MPI_Waitall( 2, requests, statuses );
92 MPI_Reduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD );
95 printf( "No errors\n" );
97 printf( "Error in handling MPI_COMM_SELF\n" );