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 static int verbose = 0;
18 int main(int argc, char *argv[])
26 MPI_Init(&argc, &argv);
27 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
28 MPI_Comm_size(MPI_COMM_WORLD, &size);
30 if (getenv("MPITEST_VERBOSE"))
33 /* Allocate memory regions to communicate */
34 sbuf = (char *) malloc(SIZE);
35 rbuf = (char *) malloc(size * SIZE);
37 /* Touch the buffers to make sure they are allocated */
38 for (i = 0; i < SIZE; i++)
40 for (i = 0; i < SIZE * size; i++)
43 /* Time when rank 0 gathers the data */
44 MPI_Barrier(MPI_COMM_WORLD);
46 for (i = 0; i < ITER; i++) {
47 MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 0, MPI_COMM_WORLD);
48 MPI_Barrier(MPI_COMM_WORLD);
53 /* Time when rank 1 gathers the data */
54 MPI_Barrier(MPI_COMM_WORLD);
56 for (j = 0; j < ITER; j++) {
57 MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 1, MPI_COMM_WORLD);
58 MPI_Barrier(MPI_COMM_WORLD);
61 ts = (t2 - t1) / ITER;
64 MPI_Send(&ts, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
66 MPI_Recv(&ts, 1, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD, &status);
68 /* Print out the results */
70 if ((ts / t) > (1 + ERROR_MARGIN)) { /* If the difference is more than 10%, it's an error */
71 printf("%.3f\t%.3f\n", 1000000.0 * ts, 1000000.0 * t);
72 printf("Too much difference in performance\n");
75 printf(" No Errors\n");