Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / fairness / fairness2.c
1 /*
2  * This program should be run with at least 8 nodes just to (un)fair
3  *
4  * Patrick Bridges * bridges@mcs.anl.gov * patrick@CS.MsState.Edu 
5  */
6
7 #include <stdio.h>
8 #include "test.h"
9 #include "mpi.h"
10
11 int main(argc, argv)
12 int argc;
13 char **argv;
14 {
15     int rank, size, an_int; 
16     char *Current_Test = NULL;
17     int *num_array, i, j;
18     MPI_Status Status;
19     
20     MPI_Init(&argc, &argv);
21     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22     MPI_Comm_size(MPI_COMM_WORLD, &size);
23     Test_Init("fairness2", rank);
24
25     /* Wait for everyone to be ready */
26     
27     if (rank == 0) { 
28         /* Initialize an array to keep statistics in */
29         num_array = (int *)malloc((size - 1) * sizeof(int));
30
31         /* Make sure everyone is ready */
32         MPI_Barrier(MPI_COMM_WORLD);
33
34         /* Wait for all of the senders to send all of their messages */
35         Test_Message("Waiting for all of the senders to say they're through.");
36         for (i = 0 ; i < size - 1; i++)
37             MPI_Recv(&an_int, 1, MPI_INT, MPI_ANY_SOURCE, 5000,
38                      MPI_COMM_WORLD, &Status);
39         
40         Test_Message("Starting to dequeue messages...");
41         /* Now start dequeuing messages */
42         for (i = 0; i < size - 1; i++) {
43             /* Clear the buffer of counts */
44             memset(num_array, 0, (size - 1) * sizeof(int));
45             for (j = 0; j < 200; j++) {
46                 MPI_Recv(&an_int, 1, MPI_INT, MPI_ANY_SOURCE, 2000, 
47                          MPI_COMM_WORLD, &Status);
48                 num_array[Status.MPI_SOURCE - 1]++;
49             }
50             Test_Printf("Statistics for message group %d:\n", i + 1);
51             for (j = 0; j < size -1 ; j++)
52                 Test_Printf("%f%% of last 200 messages received \
53 were from source %d.\n",
54                             num_array[j]/2.0, j + 1);
55         }
56
57         free(num_array);
58         (void)Summarize_Test_Results();
59         MPI_Finalize();
60
61     } else {
62         MPI_Request ReqArray[200];
63         MPI_Status StatArray[200];
64         
65         MPI_Barrier(MPI_COMM_WORLD);
66         an_int = rank;
67         
68         Test_Message("About to send all of the little messages.");
69         /* Send 200 tiny messages - nonblocking so we don't deadlock */
70         for (i = 0; i < 200; i++)
71             MPI_Isend(&an_int, 1, MPI_INT, 0, 2000, MPI_COMM_WORLD, 
72                       &ReqArray[i]);
73
74         Test_Message("Sending the final message.");
75         /* Tell receiver we've sent all of our messages */
76         MPI_Send(&an_int, 1, MPI_INT, 0, 5000, MPI_COMM_WORLD);
77         Test_Message("Waiting on the nonblocking requests.");
78         MPI_Waitall(200,ReqArray,StatArray);
79         (void)Summarize_Test_Results();
80         MPI_Finalize();
81     }
82
83     return 0;
84 }
85
86
87