|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 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 <string.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* A simple performance test. The file name is taken as a
|
|
Packit Service |
c5cf8c |
command-line argument. */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define SIZE (1048576*4) /* read/write size per node in bytes */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static void handle_error(int errcode, const char *str)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
char msg[MPI_MAX_ERROR_STRING];
|
|
Packit Service |
c5cf8c |
int resultlen;
|
|
Packit Service |
c5cf8c |
MPI_Error_string(errcode, msg, &resultlen);
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "%s: %s\n", str, msg);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPI_CHECK(fn) { int errcode; errcode = (fn); if (errcode != MPI_SUCCESS) handle_error(errcode, #fn); }
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int *buf, i, j, mynod, nprocs, ntimes = 5, len, err, flag;
|
|
Packit Service |
c5cf8c |
double stim, read_tim, write_tim, new_read_tim, new_write_tim;
|
|
Packit Service |
c5cf8c |
double min_read_tim = 10000000.0, min_write_tim = 10000000.0, read_bw, write_bw;
|
|
Packit Service |
c5cf8c |
MPI_File fh;
|
|
Packit Service |
c5cf8c |
MPI_Status status;
|
|
Packit Service |
c5cf8c |
char *filename;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* process 0 takes the file name as a command-line argument and
|
|
Packit Service |
c5cf8c |
broadcasts it to other processes */
|
|
Packit Service |
c5cf8c |
if (!mynod) {
|
|
Packit Service |
c5cf8c |
i = 1;
|
|
Packit Service |
c5cf8c |
while ((i < argc) && strcmp("-fname", *argv)) {
|
|
Packit Service |
c5cf8c |
i++;
|
|
Packit Service |
c5cf8c |
argv++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (i >= argc) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "\n*# Usage: perf -fname filename\n\n");
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
argv++;
|
|
Packit Service |
c5cf8c |
len = strlen(*argv);
|
|
Packit Service |
c5cf8c |
filename = (char *) malloc(len + 1);
|
|
Packit Service |
c5cf8c |
strcpy(filename, *argv);
|
|
Packit Service |
c5cf8c |
MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Access size per process = %d bytes, ntimes = %d\n", SIZE, ntimes);
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
filename = (char *) malloc(len + 1);
|
|
Packit Service |
c5cf8c |
MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
buf = (int *) malloc(SIZE);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (j = 0; j < ntimes; j++) {
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_open(MPI_COMM_WORLD, filename,
|
|
Packit Service |
c5cf8c |
MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_seek(fh, mynod * SIZE, MPI_SEEK_SET));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
stim = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_write(fh, buf, SIZE, MPI_BYTE, &status));
|
|
Packit Service |
c5cf8c |
write_tim = MPI_Wtime() - stim;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_close(&fh));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
|
|
Packit Service |
c5cf8c |
MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_seek(fh, mynod * SIZE, MPI_SEEK_SET));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
stim = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_read(fh, buf, SIZE, MPI_BYTE, &status));
|
|
Packit Service |
c5cf8c |
read_tim = MPI_Wtime() - stim;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_close(&fh));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Allreduce(&write_tim, &new_write_tim, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
MPI_Allreduce(&read_tim, &new_read_tim, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
min_read_tim = (new_read_tim < min_read_tim) ? new_read_tim : min_read_tim;
|
|
Packit Service |
c5cf8c |
min_write_tim = (new_write_tim < min_write_tim) ? new_write_tim : min_write_tim;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (mynod == 0) {
|
|
Packit Service |
c5cf8c |
read_bw = (SIZE * nprocs) / (min_read_tim * 1024.0 * 1024.0);
|
|
Packit Service |
c5cf8c |
write_bw = (SIZE * nprocs) / (min_write_tim * 1024.0 * 1024.0);
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Write bandwidth without file sync = %f Mbytes/sec\n", write_bw);
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Read bandwidth without prior file sync = %f Mbytes/sec\n", read_bw);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
min_write_tim = 10000000.0;
|
|
Packit Service |
c5cf8c |
min_read_tim = 10000000.0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
flag = 0;
|
|
Packit Service |
c5cf8c |
for (j = 0; j < ntimes; j++) {
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
|
|
Packit Service |
c5cf8c |
MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_seek(fh, mynod * SIZE, MPI_SEEK_SET));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
stim = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_write(fh, buf, SIZE, MPI_BYTE, &status));
|
|
Packit Service |
c5cf8c |
err = MPI_File_sync(fh);
|
|
Packit Service |
c5cf8c |
write_tim = MPI_Wtime() - stim;
|
|
Packit Service |
c5cf8c |
if (err == MPI_ERR_UNKNOWN) {
|
|
Packit Service |
c5cf8c |
flag = 1;
|
|
Packit Service |
c5cf8c |
break;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_close(&fh));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
|
|
Packit Service |
c5cf8c |
MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_seek(fh, mynod * SIZE, MPI_SEEK_SET));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
stim = MPI_Wtime();
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_read(fh, buf, SIZE, MPI_BYTE, &status));
|
|
Packit Service |
c5cf8c |
read_tim = MPI_Wtime() - stim;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_close(&fh));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Allreduce(&write_tim, &new_write_tim, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
MPI_Allreduce(&read_tim, &new_read_tim, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
min_read_tim = (new_read_tim < min_read_tim) ? new_read_tim : min_read_tim;
|
|
Packit Service |
c5cf8c |
min_write_tim = (new_write_tim < min_write_tim) ? new_write_tim : min_write_tim;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (mynod == 0) {
|
|
Packit Service |
c5cf8c |
if (flag)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "MPI_File_sync returns error.\n");
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
read_bw = (SIZE * nprocs) / (min_read_tim * 1024.0 * 1024.0);
|
|
Packit Service |
c5cf8c |
write_bw = (SIZE * nprocs) / (min_write_tim * 1024.0 * 1024.0);
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Write bandwidth including file sync = %f Mbytes/sec\n", write_bw);
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Read bandwidth after file sync = %f Mbytes/sec\n", read_bw);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
free(buf);
|
|
Packit Service |
c5cf8c |
free(filename);
|
|
Packit Service |
c5cf8c |
MPI_Finalize();
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|