/* -*- Mode: C; c-basic-offset:4 ; -*- */ #include "mpi.h" #include "mpio.h" /* not necessary with MPICH 1.1.1 or HPMPI 1.4 */ #include #include #include /* tests whether atomicity semantics are satisfied for overlapping accesses in atomic mode. The probability of detecting errors is higher if you run it on 8 or more processes. */ /* The file name is taken as a command-line argument. */ #define BUFSIZE 10000 /* no. of integers */ int main(int argc, char **argv) { int *writebuf, *readbuf, i, mynod, nprocs, len, err; char *filename; MPI_Datatype newtype; MPI_File fh; MPI_Status status; MPI_Info info; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &mynod); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); /* process 0 takes the file name as a command-line argument and broadcasts it to other processes */ if (!mynod) { i = 1; while ((i < argc) && strcmp("-fname", *argv)) { i++; argv++; } if (i >= argc) { fprintf(stderr, "\n*# Usage: coll_test -fname filename\n\n"); MPI_Abort(MPI_COMM_WORLD, 1); } argv++; len = strlen(*argv); filename = (char *) malloc(len+1); strcpy(filename, *argv); MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD); } else { MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); filename = (char *) malloc(len+1); MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD); } writebuf = (int *) malloc(BUFSIZE*sizeof(int)); readbuf = (int *) malloc(BUFSIZE*sizeof(int)); /* test atomicity of contiguous accesses */ /* initialize file to all zeros */ if (!mynod) { MPI_File_delete(filename, MPI_INFO_NULL); MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); for (i=0; i