Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_8_x'
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / order.c
1 #include <stdio.h>
2 #include "mpi.h"
3
4 #if defined(NEEDS_STDLIB_PROTOTYPES)
5 #include "protofix.h"
6 #endif
7
8
9 int main( int argc, char *argv[] )
10 {
11     int easy;
12     int rank;
13     int size;
14     int a;
15     int b;
16     MPI_Request request;
17     MPI_Status  status;
18     double t0;
19     
20     MPI_Init(&argc, &argv);
21     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22     MPI_Comm_size(MPI_COMM_WORLD, &size);
23
24     /* This test depends on a working wtime.  Make a simple check */
25     t0 = MPI_Wtime();
26     if (t0 == 0 && MPI_Wtime() == 0) {
27         int loopcount = 1000000;
28         /* This test is too severe (systems with fast 
29            processors and large MPI_Wtick values can 
30            fail.  Try harder to test MPI_Wtime */
31         while (loopcount-- && MPI_Wtime() == 0) ;
32         if (loopcount <= 0) {
33             fprintf( stderr, 
34                      "MPI_WTIME is returning 0; a working value is needed\n\
35 for this test.\n" );
36             MPI_Abort( MPI_COMM_WORLD, 1 );
37         }
38         t0 = MPI_Wtime();
39     }
40
41     easy = 1;
42
43     MPI_Barrier( MPI_COMM_WORLD );
44     if (rank == 0)
45     {
46         MPI_Irecv(&a, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &request);
47         MPI_Recv(&b, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &status);
48         MPI_Wait(&request, &status);
49         /* Check for correct values: */
50         if (a == 1 && b == 2) {
51             printf( " No Errors\n" );
52         }
53         else {
54             printf("rank = %d, a = %d, b = %d\n", rank, a, b);
55         }
56     }
57     else
58     {
59         MPI_Wtime();
60         smpi_sleep(easy);
61   //while (MPI_Wtime() - t1 < easy) ;
62         a = 1;
63         b = 2;
64         MPI_Send(&a, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
65         MPI_Send(&b, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
66     }
67     
68
69     MPI_Finalize();
70     return 0;
71 }