Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / fairness / fairness2m.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 #include "mpe.h"
11
12 int main(argc, argv)
13 int argc;
14 char **argv;
15 {
16     int rank, size, an_int; 
17     char *Current_Test = NULL;
18     int *num_array, i, j;
19     MPI_Status Status;
20     
21     MPI_Init(&argc, &argv);
22     MPE_Init_log();
23     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24     MPI_Comm_size(MPI_COMM_WORLD, &size);
25     Test_Init("fairness2m", rank);
26
27     /* Wait for everyone to be ready */
28     
29     if (rank == 0) { 
30         /* Initialize an array to keep statistics in */
31         num_array = (int *)malloc((size - 1) * sizeof(int));
32
33         /* Make sure everyone is ready */
34         MPI_Barrier(MPI_COMM_WORLD);
35
36         /* Wait for all of the senders to send all of their messages */
37         Test_Message("Waiting for all of the senders to say they're through.");
38         for (i = 0 ; i < size - 1; i++) {
39             MPI_Recv(&an_int, 1, MPI_INT, MPI_ANY_SOURCE, 5000,
40                      MPI_COMM_WORLD, &Status);
41             MPE_Log_receive(Status.MPI_SOURCE, 5000, sizeof(int));
42         }
43         Test_Message("Starting to dequeue messages...");
44         /* Now start dequeuing messages */
45         for (i = 0; i < size - 1; i++) {
46             /* Clear the buffer of counts */
47             memset(num_array, 0, (size - 1) * sizeof(int));
48             for (j = 0; j < 200; j++) {
49                 MPI_Recv(&an_int, 1, MPI_INT, MPI_ANY_SOURCE, 2000, 
50                          MPI_COMM_WORLD, &Status);
51                 MPE_Log_receive(Status.MPI_SOURCE, 2000, sizeof(int));
52                 num_array[Status.MPI_SOURCE - 1]++;
53             }
54             Test_Printf("Statistics for message group %d:\n", i + 1);
55             for (j = 0; j < size -1 ; j++)
56                 Test_Printf("%f%% of last 200 messages received \
57 were from source %d.\n",
58                             num_array[j]/2.0, j + 1);
59         }
60
61         free(num_array);
62         (void)Summarize_Test_Results();
63
64         MPE_Finish_log("/home/bridges/fairness2.log");
65         MPI_Finalize();
66
67     } else {
68         MPI_Request ReqArray[200];
69         MPI_Status StatArray[200];
70         
71         MPI_Barrier(MPI_COMM_WORLD);
72         an_int = rank;
73         
74         Test_Message("About to send all of the little messages.");
75         /* Send 200 tiny messages - nonblocking so we don't deadlock */
76         for (i = 0; i < 200; i++) {
77             MPI_Isend(&an_int, 1, MPI_INT, 0, 2000, MPI_COMM_WORLD, 
78                       &ReqArray[i]);
79             MPE_Log_send(0, 2000, sizeof(int));
80         }
81         Test_Message("Sending the final message.");
82         /* Tell receiver we've sent all of our messages */
83         MPI_Send(&an_int, 1, MPI_INT, 0, 5000, MPI_COMM_WORLD);
84         MPE_Log_send(0, 5000, sizeof(int));
85
86         Test_Message("Waiting on the nonblocking requests.");
87         MPI_Waitall(200,ReqArray,StatArray);
88         (void)Summarize_Test_Results();
89
90         MPE_Finish_log("/home/bridges/fairness2.log");
91         MPI_Finalize();
92     }
93
94     return 0;
95 }
96
97
98
99