1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2008 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
14 #define ERROR_MARGIN 0.5
16 int main(int argc, char *argv[])
24 MPI_Init(&argc, &argv);
25 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26 MPI_Comm_size(MPI_COMM_WORLD, &size);
28 /* Allocate memory regions to communicate */
29 sbuf = (char *) malloc(SIZE);
30 rbuf = (char *) malloc(size * SIZE);
32 /* Touch the buffers to make sure they are allocated */
33 for (i = 0; i < SIZE; i++)
35 for (i = 0; i < SIZE * size; i++)
38 /* Time when rank 0 gathers the data */
39 MPI_Barrier(MPI_COMM_WORLD);
41 for (i = 0; i < ITER; i++) {
42 MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 0, MPI_COMM_WORLD);
43 MPI_Barrier(MPI_COMM_WORLD);
48 /* Time when rank 1 gathers the data */
49 MPI_Barrier(MPI_COMM_WORLD);
51 for (j = 0; j < ITER; j++) {
52 MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 1, MPI_COMM_WORLD);
53 MPI_Barrier(MPI_COMM_WORLD);
56 ts = (t2 - t1) / ITER;
59 MPI_Send(&ts, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
61 MPI_Recv(&ts, 1, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD, &status);
63 /* Print out the results */
65 if ((ts / t) > (1 + ERROR_MARGIN)) { /* If the difference is more than 10%, it's an error */
66 printf("%.3f\t%.3f\n", 1000000.0 * ts, 1000000.0 * t);
67 printf("Too much difference in performance\n");
70 printf(" No Errors\n");