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
15 int rank, size, an_int;
16 char *Current_Test = NULL;
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);
25 /* Wait for everyone to be ready */
28 /* Initialize an array to keep statistics in */
29 num_array = (int *)malloc((size - 1) * sizeof(int));
31 /* Make sure everyone is ready */
32 MPI_Barrier(MPI_COMM_WORLD);
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);
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]++;
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);
58 (void)Summarize_Test_Results();
62 MPI_Request ReqArray[200];
63 MPI_Status StatArray[200];
65 MPI_Barrier(MPI_COMM_WORLD);
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,
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();