2 * This program should be run with at least 8 nodes just to (un)fair
4 * Patrick Bridges * bridges@mcs.anl.gov * patrick@CS.MsState.Edu
16 int rank, size, an_int;
17 char *Current_Test = NULL;
21 MPI_Init(&argc, &argv);
23 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24 MPI_Comm_size(MPI_COMM_WORLD, &size);
25 Test_Init("fairness2m", rank);
27 /* Wait for everyone to be ready */
30 /* Initialize an array to keep statistics in */
31 num_array = (int *)malloc((size - 1) * sizeof(int));
33 /* Make sure everyone is ready */
34 MPI_Barrier(MPI_COMM_WORLD);
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));
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]++;
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);
62 (void)Summarize_Test_Results();
64 MPE_Finish_log("/home/bridges/fairness2.log");
68 MPI_Request ReqArray[200];
69 MPI_Status StatArray[200];
71 MPI_Barrier(MPI_COMM_WORLD);
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,
79 MPE_Log_send(0, 2000, sizeof(int));
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));
86 Test_Message("Waiting on the nonblocking requests.");
87 MPI_Waitall(200,ReqArray,StatArray);
88 (void)Summarize_Test_Results();
90 MPE_Finish_log("/home/bridges/fairness2.log");