Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This used to work by accident
[simgrid.git] / teshsuite / smpi / mpich-test / coll / barrier.c
1 /* This program provides some simple verification of the MPI_Barrier
2  * program.  All of the clients send a message to indicate that they
3  * are alive (a simple character string) and then the all of the
4  * clients enter an MPI_Barrier.  The server then Iprobes for a while
5  * to make sure that none of the "through barrier" messages that the
6  * clients send after leaving the barrier arive before the server enters 
7  * the barrier. The server then enters the barrier, and upon leaving,
8  * waits for a message from each client.
9  */
10
11 #include "test.h"
12 #include "mpi.h"
13
14 #define WAIT_TIMES 500
15
16 int
17 main( int argc, char **argv)
18 {
19     int rank, size, i, recv_flag, ret, passed;
20     MPI_Status Status;
21     char message[17];
22     MPI_Init(&argc, &argv);
23     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24     MPI_Comm_size(MPI_COMM_WORLD, &size);
25
26     if (rank == 0) {
27         Test_Init("barrier", rank);
28         /* Receive the startup messages from each of the 
29            other clients */
30         for (i = 0; i < size - 1; i++) {
31             MPI_Recv(message, 17, MPI_CHAR, MPI_ANY_SOURCE, 2000, 
32                      MPI_COMM_WORLD, &Status);
33         }
34
35         /* Now use Iprobe to make sure no more messages arive for a
36             while */
37         passed = 1;
38         for (i = 0; i < WAIT_TIMES; i++){
39             recv_flag = 0;
40             MPI_Iprobe(MPI_ANY_SOURCE, 2000, MPI_COMM_WORLD, 
41                        &recv_flag, &Status);
42             if (recv_flag)
43                 passed = 0;
44         }
45
46         if (passed)
47             Test_Passed("Barrier Test 1");
48         else
49             Test_Failed("Barrier Test 1");
50
51         /* Now go into the barrier myself */
52         MPI_Barrier(MPI_COMM_WORLD);
53
54         /* And get everyones message who came out */
55         for (i = 0; i < size - 1; i++) {
56             MPI_Recv(message, 13, MPI_CHAR, MPI_ANY_SOURCE, 2000, 
57                      MPI_COMM_WORLD, &Status);
58         }
59
60         /* Now use Iprobe to make sure no more messages arive for a
61             while */
62         passed = 1;
63         for (i = 0; i < WAIT_TIMES; i++){
64             recv_flag = 0;
65             MPI_Iprobe(MPI_ANY_SOURCE, 2000, MPI_COMM_WORLD, 
66                        &recv_flag, &Status);
67             if (recv_flag)
68                 passed = 0;
69         }
70         if (passed)
71             Test_Passed("Barrier Test 2");
72         else
73             Test_Failed("Barrier Test 2");
74
75         Test_Waitforall( );
76         ret = Summarize_Test_Results();
77         Test_Finalize();
78         MPI_Finalize();
79         return ret;
80     } else {
81         MPI_Send((char*)"Entering Barrier", 17, MPI_CHAR, 0, 2000, MPI_COMM_WORLD);
82         MPI_Barrier(MPI_COMM_WORLD);
83         MPI_Send((char*)"Past Barrier", 13, MPI_CHAR, 0, 2000, MPI_COMM_WORLD);
84         Test_Waitforall( );
85         MPI_Finalize();
86         return 0;
87     }
88 }