Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_8_x'
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / fairness / fairness.c
1 /* 
2  * Program to test the fairness of the MPI implementation over source.
3  * All of the programs wait on a barrier, then node 0 starts receiving
4  * small messages using ANY_SOURCE from all of the other nodes who
5  * send as much as they can.  Node 0 collects statistics on the rate
6  * messages are received from each source. (Every N messages it
7  * prints out what percentage of the last N received were from each
8  * source. It does this for <size-1> times.
9  *
10  * This program should be run with at least 8 nodes just to be (un)fair
11  *
12  * Patrick Bridges * bridges@mcs.anl.gov * patrick@CS.MsState.Edu 
13  */
14
15 #include <stdio.h>
16 #include "test.h"
17 #include "mpi.h"
18 #define MPG 200
19 #define MSZ 1
20 int main(argc, argv)
21 int argc;
22 char **argv;
23 {
24     int rank, size, an_int[MSZ]; 
25     char *Current_Test = NULL;
26     int *num_array, i, j;
27     MPI_Status Status;
28     
29     MPI_Init(&argc, &argv);
30     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31     MPI_Comm_size(MPI_COMM_WORLD, &size);
32     Test_Init("fairness", rank);
33
34     /* Wait for everyone to be ready */
35     
36     if (rank == 0) { 
37         /* Initialize an array to keep statistics in */
38         num_array = (int *)malloc((size - 1) * sizeof(int));
39
40         MPI_Barrier(MPI_COMM_WORLD);
41         
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 < MPG; j++) {
46                 MPI_Recv(an_int, MSZ, 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 %d messages received \
53 were from source %d.\n",
54                             num_array[j]*100.0/MPG, MPG, j + 1);
55         }
56         free(num_array);
57         (void)Summarize_Test_Results();
58         MPI_Finalize();
59
60     } else {
61         MPI_Barrier(MPI_COMM_WORLD);
62         for (i = 0; i < MPG; i++) {
63             MPI_Send(an_int, MSZ, MPI_INT, 0, 2000, MPI_COMM_WORLD);
64         }
65         MPI_Finalize();
66     }
67
68     return 0;
69 }
70
71
72