Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / coll / nbcoll.c
1 #include "mpi.h"
2 #include <stdio.h>
3
4 int main( int argc, char *argv[] )
5 {
6     int rank, size;
7     MPI_Comm local_comm;
8     MPI_Request r;
9     MPI_Status status;
10     double t0;
11
12
13     MPI_Init( &argc, &argv );
14     MPI_Comm_size( MPI_COMM_WORLD, &size );
15     if (size < 3) {
16         fprintf( stderr, "Need at least 3 processors\n" );
17         MPI_Abort( MPI_COMM_WORLD, 1 );
18     }
19     
20     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
21     MPI_Comm_split( MPI_COMM_WORLD, rank < 2, rank, &local_comm );
22
23     MPI_Barrier( MPI_COMM_WORLD );
24     if (rank == 0) {
25         /* First, ensure ssend works */
26         t0 = MPI_Wtime();
27         MPI_Ssend( MPI_BOTTOM, 0, MPI_INT, 1, 1, MPI_COMM_WORLD );
28         t0 = MPI_Wtime() - t0;
29         if (t0 < 1.0) {
30             fprintf( stderr, "Ssend does not wait for recv!\n" );
31             fflush( stderr );
32             MPI_Abort( MPI_COMM_WORLD, 1 );
33         }
34         MPI_Barrier( MPI_COMM_WORLD );
35         /* Start the ssend after process 1 is well into its barrier */
36         t0 = MPI_Wtime();
37         while (MPI_Wtime() - t0 < 1.0) ;
38         MPI_Ssend( MPI_BOTTOM, 0, MPI_INT, 1, 0, MPI_COMM_WORLD );
39         MPI_Barrier( local_comm );
40         /* Send process 2 an alls well */
41         MPI_Send( MPI_BOTTOM, 0, MPI_INT, 2, 0, MPI_COMM_WORLD );
42     }
43     else if (rank == 1) {
44         t0 = MPI_Wtime();
45         while (MPI_Wtime() - t0 < 2.0) ;
46         MPI_Recv( MPI_BOTTOM, 0, MPI_INT, 0, 1, MPI_COMM_WORLD, &status );
47         MPI_Barrier( MPI_COMM_WORLD );
48         MPI_Irecv( MPI_BOTTOM, 0, MPI_INT, 0, 0, MPI_COMM_WORLD, &r );
49         MPI_Barrier( local_comm );
50         MPI_Wait( &r, &status );
51     }
52     else if (rank == 2) {
53         int flag;
54
55         MPI_Barrier( MPI_COMM_WORLD );
56         MPI_Irecv( MPI_BOTTOM, 0, MPI_INT, 0, 0, MPI_COMM_WORLD, &r );
57         t0 = MPI_Wtime();
58         while (MPI_Wtime() - t0 < 3.0) ;
59         MPI_Test( &r, &flag, &status );
60         if (!flag) {
61             fprintf( stderr, "Test failed!\n" );
62             fflush( stderr );
63             MPI_Abort( MPI_COMM_WORLD, 1 );
64         }
65         else
66             fprintf( stderr, "Test succeeded\n" );
67     }
68     else {
69         MPI_Barrier( MPI_COMM_WORLD );
70     }
71
72     MPI_Comm_free( &local_comm );
73     MPI_Finalize();
74     return 0;
75 }