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")) verbose = 1;
32 /* Allocate memory regions to communicate */
33 sbuf = (char*) malloc(SIZE);
34 rbuf = (char*) malloc(size * SIZE);
36 /* Touch the buffers to make sure they are allocated */
37 for (i = 0; i < SIZE; i++) sbuf[i] = '0';
38 for (i = 0; i < SIZE * size; i++) rbuf[i] = '0';
40 /* Time when rank 0 gathers the data */
41 MPI_Barrier(MPI_COMM_WORLD);
43 for (i = 0; i < ITER; i++) {
44 MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 0, MPI_COMM_WORLD);
45 MPI_Barrier(MPI_COMM_WORLD);
50 /* Time when rank 1 gathers the data */
51 MPI_Barrier(MPI_COMM_WORLD);
53 for (j = 0; j < ITER; j++) {
54 MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 1, MPI_COMM_WORLD);
55 MPI_Barrier(MPI_COMM_WORLD);
61 MPI_Send(&ts, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
63 MPI_Recv(&ts, 1, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD, &status);
65 /* Print out the results */
67 if ((ts / t) > (1 + ERROR_MARGIN)) { /* If the difference is more than 10%, it's an error */
68 printf("%.3f\t%.3f\n", 1000000.0 * ts, 1000000.0 * t);
69 printf("Too much difference in performance\n");
71 else printf(" No Errors\n");