Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_8_x'
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / selfvsworld.c
1 /* -----------------------------------------------------------------------
2  * Code:   mismatch.c
3  * Lab:    Parallel Processing Performance Tools
4  * Usage:  mismatch
5  *         Run on two nodes
6  *         You will need to stop the deadlocked program with <ctrl>\
7  * Author: Roslyn Leibensperger  Last revised: 3/19/97 RYL
8  *
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
13  * problem.
14  * ------------------------------------------------------------------------ */
15 #include <stdio.h>
16 #include "mpi.h"
17 #define MSGLEN 100            /* length of message in elements */
18 #define TAG_A 100
19 #define TAG_B 200
20
21 int main( int argc, char *argv[] ) 
22 {
23   float message1 [MSGLEN],    /* message buffers                      */
24         message2 [MSGLEN],
25         message3 [MSGLEN];
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                         */
30       flag, size, i;
31   int errs = 0, toterrs;
32   MPI_Status status;          /* status of communication              */
33   MPI_Status statuses[2];
34   MPI_Request requests[2];
35
36   MPI_Init( &argc, &argv );
37   MPI_Comm_rank( MPI_COMM_WORLD, &rank );
38   MPI_Comm_size( MPI_COMM_WORLD, &size );
39   if (size != 2) {
40       printf( "Must run with exactly 2 processes\n" );
41       MPI_Abort( MPI_COMM_WORLD, 1 );
42   }
43   /* printf ( " Task %d initialized\n", rank ); */
44
45   /* initialize message buffers */
46   for ( i=0; i<MSGLEN; i++ )  
47     {
48       message1[i] = 100;
49       message2[i] = -100;
50     }
51
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    * --------------------------------------------------------------- */
56   if ( rank == 0 )  
57     {
58       dest = 1;
59       source = 1;
60       send_tag = TAG_B;
61       recv_tag = TAG_A;
62   }
63   else if ( rank == 1)  
64     {
65       dest = 0;
66       source = 0;
67       send_tag = TAG_B;
68       recv_tag = TAG_A;
69     }
70
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] );
77
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
80    * with POE 2.4
81    */
82   MPI_Iprobe( MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_SELF, &flag, &status );
83   if (flag) {
84       errs++;
85       printf ( " Task %d has received the message on COMM_SELF !\n", rank );
86   }
87
88   MPI_Recv( message3, MSGLEN, MPI_FLOAT, source, send_tag, MPI_COMM_WORLD, 
89             &status );
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 );
93   if (rank == 0) {
94       if (toterrs == 0) 
95           printf( "No errors\n" );
96       else
97           printf( "Error in handling MPI_COMM_SELF\n" );
98   }
99
100   MPI_Finalize();
101   return 0;
102 }
103
104