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 / persistent.c
1 #include "mpi.h"
2 #include <stdio.h>
3
4 #if defined(NEEDS_STDLIB_PROTOTYPES)
5 #include "protofix.h"
6 #endif
7
8 int main( int argc, char **argv )
9 {
10     int rank, size, i, len, actlen, expected_len;
11     MPI_Request rq;
12     MPI_Status status;
13     double data[100];
14
15     len = 100;
16     MPI_Init( &argc, &argv );
17     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
18     MPI_Comm_size( MPI_COMM_WORLD, &size );
19
20     if (size < 3 ) {
21         fprintf( stderr, "This test requires more than 2 proceses\n" );
22         MPI_Finalize();
23         return 1;
24         }
25
26     if (rank == 0) {
27         MPI_Recv_init( data, len, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, 
28                        MPI_COMM_WORLD, &rq );
29         for (i=1; i<size; i++) {
30             printf( "Receiving message %d\n", i );
31             MPI_Start( &rq );
32             MPI_Wait( &rq, &status );
33             if (status.MPI_SOURCE != status.MPI_TAG) {
34                 printf( "Error in received message (source and tag)\n" );
35                 printf( "Source was %d and tag was %d\n",
36                         status.MPI_SOURCE, status.MPI_TAG );
37                 }
38             MPI_Get_count( &status, MPI_DOUBLE, &actlen );
39             expected_len = (status.MPI_SOURCE < 10) ? status.MPI_SOURCE * 10 :
40                 100;
41             if (actlen != expected_len) {
42                 printf( "Got %d words, expected %d words\n", actlen, 
43                        expected_len );
44                 }
45             printf( "Received message %d\n", i );
46             }
47         MPI_Request_free( &rq );
48         printf( "Completed all receives\n" );
49         }
50     else {
51         MPI_Send( data, (rank < 10) ? rank * 10 : 100, 
52                   MPI_DOUBLE, 0, rank, MPI_COMM_WORLD );
53         }
54 MPI_Finalize();
55 return 0;
56 }