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.
14 #define WAIT_TIMES 500
17 main( int argc, char **argv)
19 int rank, size, i, recv_flag, ret, passed;
22 MPI_Init(&argc, &argv);
23 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24 MPI_Comm_size(MPI_COMM_WORLD, &size);
27 Test_Init("barrier", rank);
28 /* Receive the startup messages from each of the
30 for (i = 0; i < size - 1; i++) {
31 MPI_Recv(message, 17, MPI_CHAR, MPI_ANY_SOURCE, 2000,
32 MPI_COMM_WORLD, &Status);
35 /* Now use Iprobe to make sure no more messages arive for a
38 for (i = 0; i < WAIT_TIMES; i++){
40 MPI_Iprobe(MPI_ANY_SOURCE, 2000, MPI_COMM_WORLD,
47 Test_Passed("Barrier Test 1");
49 Test_Failed("Barrier Test 1");
51 /* Now go into the barrier myself */
52 MPI_Barrier(MPI_COMM_WORLD);
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);
60 /* Now use Iprobe to make sure no more messages arive for a
63 for (i = 0; i < WAIT_TIMES; i++){
65 MPI_Iprobe(MPI_ANY_SOURCE, 2000, MPI_COMM_WORLD,
71 Test_Passed("Barrier Test 2");
73 Test_Failed("Barrier Test 2");
76 ret = Summarize_Test_Results();
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);