/* * (C) 1995-2001 Clemson University and Argonne National Laboratory. * * See COPYING in top-level directory. * * This is contributed by Robert Ross to the HDF5 software. * and was called mpi-io-test.c */ #include "hdf5.h" #ifdef H5_HAVE_PARALLEL /* mpi-perf.c * * This is derived from code given to me by Rajeev Thakur. Dunno where * it originated. * * It's purpose is to produce aggregate bandwidth numbers for varying * block sizes, number of processors, an number of iterations. * * This is strictly an mpi program - it is used to test the MPI I/O * functionality implemented by Romio. * * Compiling is usually easiest with something like: * mpicc -Wall -Wstrict-prototypes mpi-io-test.c -o mpi-io-test * * NOTE: This code assumes that all command line arguments make it out to all * the processes that make up the parallel job, which isn't always the case. * So if it doesn't work on some platform, that might be why. */ /* Modifications: * Albert Cheng, Apr 30, 20001 * Changed MPI_File_open to use MPI_COMM_WORLD (was MPI_COMM_SELF). * Albert Cheng, May 5, 20001 * Changed MPI_File_seek then MPI_File_write or MPI_File_read to just * MPI_File_write_at and MPI_File_read_at. Some compiler, e.g., IBM * mpcc_r does not support MPI_File_seek and MPI_File_read or MPI_File_write. */ #include #include #include #include #include #include #include #include #ifndef MPI_FILE_NULL /*MPIO may be defined in mpi.h already */ # include #endif /* DEFAULT VALUES FOR OPTIONS */ int64_t opt_block = 1048576*16; int opt_iter = 1; int opt_stripe = -1; int opt_correct = 0; int amode = O_RDWR | O_CREAT; char opt_file[256] = "/foo/test.out\0"; char opt_pvfstab[256] = "notset\0"; int opt_pvfstab_set = 0; /* function prototypes */ int parse_args(int argc, char **argv); double Wtime(void); extern int errno; extern int debug_on; /* globals needed for getopt */ extern char *optarg; extern int optind, opterr; int main(int argc, char **argv) { char *buf, *tmp, *buf2, *tmp2, *check; int i, j, mynod=0, nprocs=1, err, my_correct = 1, correct, myerrno; double stim, etim; double write_tim = 0; double read_tim = 0; double read_bw, write_bw; double max_read_tim, max_write_tim; double min_read_tim, min_write_tim; double ave_read_tim, ave_write_tim; int64_t iter_jump = 0; int64_t seek_position = 0; MPI_File fh; MPI_Status status; int nchars; /* startup MPI and determine the rank of this process */ MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &mynod); /* parse the command line arguments */ parse_args(argc, argv); if (mynod == 0) printf("# Using mpi-io calls.\n"); /* kindof a weird hack- if the location of the pvfstab file was * specified on the command line, then spit out this location into * the appropriate environment variable: */ #if H5_HAVE_SETENV /* no setenv or unsetenv */ if (opt_pvfstab_set) { if((setenv("PVFSTAB_FILE", opt_pvfstab, 1)) < 0){ perror("setenv"); goto die_jar_jar_die; } } #endif /* this is how much of the file data is covered on each iteration of * the test. used to help determine the seek offset on each * iteration */ iter_jump = nprocs * opt_block; /* setup a buffer of data to write */ if (!(tmp = (char *) malloc(opt_block + 256))) { perror("malloc"); goto die_jar_jar_die; } buf = tmp + 128 - (((long)tmp) % 128); /* align buffer */ if (opt_correct) { /* do the same buffer setup for verifiable data */ if (!(tmp2 = (char *) malloc(opt_block + 256))) { perror("malloc2"); goto die_jar_jar_die; } buf2 = tmp + 128 - (((long)tmp) % 128); } /* open the file for writing */ err = MPI_File_open(MPI_COMM_WORLD, opt_file, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); if (err < 0) { fprintf(stderr, "node %d, open error: %s\n", mynod, strerror(errno)); goto die_jar_jar_die; } /* now repeat the write operations the number of times * specified on the command line */ for (j=0; j < opt_iter; j++) { /* calculate the appropriate position depending on the iteration * and rank of the current process */ seek_position = (j*iter_jump)+(mynod*opt_block); if (opt_correct) /* fill in buffer for iteration */ { for (i=mynod+j, check=buf; i