diff --git a/examples/ph5example.c b/examples/ph5example.c index 71802d8906..9d2142d780 100644 --- a/examples/ph5example.c +++ b/examples/ph5example.c @@ -11,10 +11,20 @@ * and the two datasets in it. Then each process reads a hyperslab from * each dataset in an independent mode and prints them out. * All processes collectively close the datasets and the file. + * + * The need of requirement of parallel file prefix is that in general + * the current working directory in which compiling is done, is not suitable + * for parallel I/O and there is no standard pathname for parallel file + * systems. In some cases, the parallel file name may even needs some + * parallel file type prefix such as: "pfs:/GF/...". Therefore, this + * example requires an explicite parallel file prefix. See the usage + * for more detail. */ #include #include "hdf5.h" +#include +#include #ifdef H5_HAVE_PARALLEL /* Temporary source code */ @@ -48,12 +58,19 @@ #define BYROW 1 /* divide into slabs of rows */ #define BYCOL 2 /* divide into blocks of columns */ +#define PARAPREFIX "HDF5_PARAPREFIX" /* file prefix environment variable name */ + /* dataset data type. Int's can be easily octo dumped. */ typedef int DATATYPE; /* global variables */ int nerrors = 0; /* errors count */ +#ifndef PATH_MAX +#define PATH_MAX 512 +#endif /* !PATH_MAX */ +char testfiles[2][PATH_MAX]; + int mpi_size, mpi_rank; /* mpi variables */ @@ -61,6 +78,7 @@ int mpi_size, mpi_rank; /* mpi variables */ int verbose = 0; /* verbose, default as no. */ int doread=1; /* read test */ int dowrite=1; /* write test */ +int docleanup=1; /* cleanup */ /* Prototypes */ void slab_set(hssize_t start[], hsize_t count[], hsize_t stride[], int mode); @@ -71,8 +89,11 @@ void phdf5writeInd(char *filename); void phdf5readInd(char *filename); void phdf5writeAll(char *filename); void phdf5readAll(char *filename); -void test_split_comm_access(char *filenames[]); +void test_split_comm_access(char filenames[][PATH_MAX]); int parse_options(int argc, char **argv); +void usage(void); +int mkfilenames(char *prefix); +void cleanup(void); /* @@ -826,7 +847,7 @@ if (verbose) * sooner or later due to barrier mixed up. */ void -test_split_comm_access(char *filenames[]) +test_split_comm_access(char filenames[][PATH_MAX]) { MPI_Comm comm; MPI_Info info = MPI_INFO_NULL; @@ -884,7 +905,11 @@ test_split_comm_access(char *filenames[]) void usage() { - printf("Usage: testphdf5 [-r] [-w] [-v]\n"); + printf("Usage: testphdf5 -f [-r] [-w] [-v]\n"); + printf("\t-f\tfile prefix for parallel test files.\n"); + printf("\t \te.g. pfs:/PFS/myname\n"); + printf("\t \tcan be set via $" PARAPREFIX ".\n"); + printf("\t-c\tno cleanup\n"); printf("\t-r\tno read\n"); printf("\t-w\tno write\n"); printf("\t-v\tverbose on\n"); @@ -893,16 +918,69 @@ usage() } +/* + * compose the test filename with the prefix supplied. + * return code: 0 if no error + * 1 otherwise. + */ +int +mkfilenames(char *prefix) +{ + int i, n; + size_t strsize; + + /* filename will be prefix/ParaEgN.h5 where N is 0 to 9. */ + /* So, string must be big enough to hold the prefix, / and 10 more chars */ + /* and the terminating null. */ + strsize = strlen(prefix) + 12; + if (strsize > PATH_MAX){ + printf("File prefix too long; Use a short path name.\n"); + return(1); + } + n = sizeof(testfiles)/sizeof(testfiles[0]); + if (n > 9){ + printf("Warning: Too many entries in testfiles. " + "Need to adjust the code to accommodate the large size.\n"); + } + for (i=0; i