|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2008 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include <sys/time.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define SIZE 100000
|
|
Packit Service |
c5cf8c |
#define ITER 1000
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define ERROR_MARGIN 0.5
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static int verbose = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
char *sbuf, *rbuf;
|
|
Packit Service |
c5cf8c |
int i, j;
|
|
Packit Service |
c5cf8c |
double t1, t2, t, ts;
|
|
Packit Service |
c5cf8c |
int rank, size;
|
|
Packit Service |
c5cf8c |
MPI_Status status;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (getenv("MPITEST_VERBOSE"))
|
|
Packit Service |
c5cf8c |
verbose = 1;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Allocate memory regions to communicate */
|
|
Packit Service |
c5cf8c |
sbuf = (char *) malloc(SIZE);
|
|
Packit Service |
c5cf8c |
rbuf = (char *) malloc(size * SIZE);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Touch the buffers to make sure they are allocated */
|
|
Packit Service |
c5cf8c |
for (i = 0; i < SIZE; i++)
|
|
Packit Service |
c5cf8c |
sbuf[i] = '0';
|
|
Packit Service |
c5cf8c |
for (i = 0; i < SIZE * size; i++)
|
|
Packit Service |
c5cf8c |
rbuf[i] = '0';
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Time when rank 0 gathers the data */
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
t1 = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
for (i = 0; i < ITER; i++) {
|
|
Packit Service |
c5cf8c |
MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
t2 = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
t = (t2 - t1) / ITER;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Time when rank 1 gathers the data */
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
t1 = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
for (j = 0; j < ITER; j++) {
|
|
Packit Service |
c5cf8c |
MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 1, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
t2 = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
ts = (t2 - t1) / ITER;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (rank == 1)
|
|
Packit Service |
c5cf8c |
MPI_Send(&ts, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
if (rank == 0)
|
|
Packit Service |
c5cf8c |
MPI_Recv(&ts, 1, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD, &status);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Print out the results */
|
|
Packit Service |
c5cf8c |
if (!rank) {
|
|
Packit Service |
c5cf8c |
if ((ts / t) > (1 + ERROR_MARGIN)) { /* If the difference is more than 10%, it's an error */
|
|
Packit Service |
c5cf8c |
printf("%.3f\t%.3f\n", 1000000.0 * ts, 1000000.0 * t);
|
|
Packit Service |
c5cf8c |
printf("Too much difference in performance\n");
|
|
Packit Service |
c5cf8c |
} else
|
|
Packit Service |
c5cf8c |
printf(" No Errors\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Finalize();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|