Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove few tests which may never finish, and change one that used too much stack...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / probe.c
1 /* 
2    This is a test of probe to receive a message of unknown length
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include "mpi.h"
8 #include "test.h"
9
10 int main( int argc, char **argv ) 
11 {
12 int data, to, from, tag, maxlen, np, myid, src, dest;
13 MPI_Status status;
14
15 MPI_Init( &argc, &argv );
16 MPI_Comm_rank( MPI_COMM_WORLD, &myid );
17 MPI_Comm_size( MPI_COMM_WORLD, &np );
18
19 /* dest writes out the received stats; for the output to be
20    consistant (with the final check), it should be procees 0 */
21 if (argc > 1 && argv[1] && strcmp( "-alt", argv[1] ) == 0) {
22     dest = np - 1;
23     src  = 0;
24     }
25 else {
26     src  = np - 1;
27     dest = 0;
28     }
29
30 if (myid == src) {
31     to   = dest;
32     tag  = 2000;
33 #ifdef VERBOSE    
34     printf( "About to send\n" );
35 #endif
36     MPI_Send( &data, 1, MPI_INT, to, tag, MPI_COMM_WORLD );
37     }
38 else {
39     tag    = 2000;
40     from   = MPI_ANY_SOURCE;
41     MPI_Probe( from, tag, MPI_COMM_WORLD, &status );
42     MPI_Get_count( &status, MPI_INT, &maxlen );
43     /* Here I'd normally allocate space; I'll just check that it is ok */
44     if (maxlen > 1)
45         printf( "Error; size = %d\n", maxlen );
46 #ifdef VERBOSE
47     printf( "About to receive\n" );
48 #endif
49     MPI_Recv( &data, 1, MPI_INT, status.MPI_SOURCE, status.MPI_TAG, 
50               MPI_COMM_WORLD, &status );
51     }
52 MPI_Barrier( MPI_COMM_WORLD );
53 Test_Waitforall( );
54 MPI_Finalize();
55 return 0;
56 }