diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-02-04 22:43:00 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-02-04 22:43:00 (GMT) |
commit | 1b147875db41924cc04bd2cd577676b197ae34ab (patch) | |
tree | dad62fe010c89dfc1db13202aa24fe03d936c3fb | |
parent | c238a6c13cdd0107fdf2c5ee0145a9b3d773fc92 (diff) | |
download | hdf5-1b147875db41924cc04bd2cd577676b197ae34ab.zip hdf5-1b147875db41924cc04bd2cd577676b197ae34ab.tar.gz hdf5-1b147875db41924cc04bd2cd577676b197ae34ab.tar.bz2 |
[svn-r8151] Purpose:
Bug fix
Description:
Fix h5tools routines to not try to call MPI_Init() unless an MPI-based
VFD is actually used.
Platforms tested:
FreeBSD 4.9 (sleipnir) w/parallel
Linux 2.4 (verbena) w/parallel
-rw-r--r-- | tools/h5dump/h5dump.c | 20 | ||||
-rw-r--r-- | tools/h5ls/h5ls.c | 22 | ||||
-rw-r--r-- | tools/lib/h5tools.c | 316 | ||||
-rw-r--r-- | tools/lib/h5tools.h | 3 |
4 files changed, 176 insertions, 185 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index b69d3b9..76c7b04 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -542,10 +542,8 @@ static const dump_functions *dump_function_table; static void leave(int ret) { - H5close(); -#ifdef H5_HAVE_PARALLEL - MPI_Finalize(); -#endif + h5tools_close(); + exit(ret); } @@ -2784,10 +2782,6 @@ main(int argc, const char *argv[]) struct handler_t *hand; int i; -#ifdef H5_HAVE_PARALLEL - MPI_Init(&argc, &argv); -#endif - dump_header_format = &standardformat; dump_function_table = &ddl_function_table; @@ -2841,7 +2835,7 @@ main(int argc, const char *argv[]) } fname = argv[opt_ind]; - fid = h5tools_fopen(fname, driver, NULL, 0); + fid = h5tools_fopen(fname, driver, NULL, 0, argc, argv); if (fid < 0) { error_msg(progname, "unable to open file \"%s\"\n", fname); @@ -3010,19 +3004,13 @@ done: /* To Do: clean up XML table */ - h5tools_close(); #ifdef H5_WANT_H5_V1_6_COMPAT H5Eset_auto(func, edata); #else H5Eset_auto(H5E_DEFAULT, func, edata); #endif /* H5_WANT_H5_V1_6_COMPAT */ - H5close(); -#ifdef H5_HAVE_PARALLEL - MPI_Finalize(); -#endif - - return d_status; + leave(d_status); } /*------------------------------------------------------------------------- diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index 9302ca8..447119e 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -1974,10 +1974,8 @@ get_width(void) static void leave(int ret) { - H5close(); -#ifdef H5_HAVE_PARALLEL - MPI_Finalize(); -#endif + h5tools_close(); + exit(ret); } @@ -1999,7 +1997,7 @@ leave(int ret) *------------------------------------------------------------------------- */ int -main (int argc, char *argv[]) +main (int argc, const char *argv[]) { hid_t file=-1, root=-1; char *fname=NULL, *oname=NULL, *x; @@ -2013,10 +2011,6 @@ main (int argc, char *argv[]) char drivername[50]; char *preferred_driver=NULL; -#ifdef H5_HAVE_PARALLEL - MPI_Init(&argc, &argv); -#endif - /* Initialize h5tools lib */ h5tools_init(); @@ -2198,7 +2192,7 @@ main (int argc, char *argv[]) file = -1; while (fname && *fname) { - file = h5tools_fopen(fname, preferred_driver, drivername, sizeof drivername); + file = h5tools_fopen(fname, preferred_driver, drivername, sizeof drivername, argc, argv); if (file>=0) { if (verbose_g) { @@ -2244,11 +2238,5 @@ main (int argc, char *argv[]) } H5Fclose(file); } - h5tools_close(); - - H5close(); -#ifdef H5_HAVE_PARALLEL - MPI_Finalize(); -#endif - return 0; + leave(0); } diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 95d64e4..b07742b 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -53,6 +53,39 @@ FILE *rawdatastream; /* should initialize to stdout but gcc moans about it /* module-scoped variables */ static int h5tools_init_g; /* if h5tools lib has been initialized */ +static int h5tools_mpi_init_g; /* if MPI_Init() has been called */ + +/* Names of VFDs */ +static const char *drivernames[]={ + "sec2", + "family", + "split", + "multi", +#ifdef H5_HAVE_STREAM + "stream", +#endif /* H5_HAVE_STREAM */ +#ifdef H5_HAVE_PARALLEL + "mpio", + "mpiposix" +#endif /* H5_HAVE_PARALLEL */ +}; + +/* This enum should match the entries in the above drivers_list since they + * are indexes into the drivers_list array. */ +enum { + SEC2_IDX = 0 + ,FAMILY_IDX + ,SPLIT_IDX + ,MULTI_IDX +#ifdef H5_HAVE_STREAM + ,STREAM_IDX +#endif /* H5_HAVE_STREAM */ +#ifdef H5_HAVE_PARALLEL + ,MPIO_IDX + ,MPIPOSIX_IDX +#endif /* H5_HAVE_PARALLEL */ +} driver_idx; +#define NUM_DRIVERS (sizeof(drivernames) / sizeof(drivernames[0])) /*------------------------------------------------------------------------- * Audience: Public @@ -107,11 +140,118 @@ h5tools_close(void) rawdatastream = NULL; } + /* Shut down the library */ + H5close(); + +#ifdef H5_HAVE_PARALLEL + /* Check if we need to shut down MPI */ + if(h5tools_mpi_init_g) { + MPI_Finalize(); + h5tools_mpi_init_g=0; + } /* end if */ +#endif + h5tools_init_g = 0; } } /*------------------------------------------------------------------------- + * Audience: Private + * Chapter: H5Tools Library + * Purpose: Get a FAPL for a driver + * Description: + * Get a FAPL for a given VFL driver name. + * Return: + * None + * Programmer: + * Quincey Koziol, 2004-02-04 + * Modifications: + *------------------------------------------------------------------------- + */ +static hid_t +h5tools_get_fapl(const char *driver, unsigned *drivernum, int argc, const char *argv[]) +{ + hid_t fapl = H5P_DEFAULT; + + /* Determine which driver the user wants to open the file with. Try + * that driver. If it can't open it, then fail. */ + if (!strcmp(driver, drivernames[SEC2_IDX])) { + if(drivernum) + *drivernum = SEC2_IDX; + } else if (!strcmp(driver, drivernames[FAMILY_IDX])) { + /* FAMILY Driver */ + if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { + H5Pset_fapl_family(fapl, (hsize_t)0, H5P_DEFAULT); + + if(drivernum) + *drivernum = FAMILY_IDX; + } /* end if */ + } else if (!strcmp(driver, drivernames[SPLIT_IDX])) { + /* SPLIT Driver */ + if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { + H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT); + + if(drivernum) + *drivernum = SPLIT_IDX; + } /* end if */ + } else if (!strcmp(driver, drivernames[MULTI_IDX])) { + /* MULTI Driver */ + if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { + H5Pset_fapl_multi(fapl, NULL, NULL, NULL, NULL, TRUE); + + if(drivernum) + *drivernum = MULTI_IDX; + } /* end if */ +#ifdef H5_HAVE_STREAM + } else if (!strcmp(driver, drivernames[STREAM_IDX])) { + /* STREAM Driver */ + if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { + H5Pset_fapl_stream(fapl, NULL); + + if(drivernum) + *drivernum = STREAM_IDX; + } /* end if */ +#endif /* H5_HAVE_STREAM */ +#ifdef H5_HAVE_PARALLEL + } else if (!strcmp(driver, drivernames[MPIO_IDX])) { + /* MPI-I/O Driver */ + if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { + H5Pset_fapl_mpio(fapl, MPI_COMM_WORLD, MPI_INFO_NULL); + + /* Initialize the MPI library, if it wasn't already */ + if(!h5tools_mpi_init_g) { + MPI_Init(&argc, &argv); + + h5tools_mpi_init_g=1; + } /* end if */ + + if(drivernum) + *drivernum = MPIO_IDX; + } /* end if */ + } else if (!strcmp(driver, drivernames[MPIPOSIX_IDX])) { + /* MPI-I/O Driver */ + if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { + H5Pset_fapl_mpiposix(fapl, MPI_COMM_WORLD, TRUE); + + /* Initialize the MPI library, if it wasn't already */ + if(!h5tools_mpi_init_g) { + MPI_Init(&argc, &argv); + + h5tools_mpi_init_g=1; + } /* end if */ + + if(drivernum) + *drivernum = MPIPOSIX_IDX; + } /* end if */ +#endif /* H5_HAVE_PARALLEL */ + } else { + fapl=(-1); + } + + return(fapl); +} + +/*------------------------------------------------------------------------- * Audience: Public * Chapter: H5Tools Library * Purpose: Open a file with various VFL drivers. @@ -168,177 +308,49 @@ h5tools_close(void) */ hid_t h5tools_fopen(const char *fname, const char *driver, char *drivername, - size_t drivername_size) + size_t drivername_size, int argc, const char *argv[]) { - static struct d_list { - const char *name; - hid_t fapl; - } drivers_list[] = { - { "sec2", FAIL } - ,{ "family", FAIL } - ,{ "split", FAIL } - ,{ "multi", FAIL } -#ifdef H5_HAVE_STREAM - ,{ "stream", FAIL } -#endif /* H5_HAVE_STREAM */ -#ifdef H5_HAVE_PARALLEL - ,{ "mpio", FAIL } - ,{ "mpiposix", FAIL } -#endif /* H5_HAVE_PARALLEL */ - }; - /* This enum should match the entries in the above drivers_list since they - * are indexes into the drivers_list array. */ - enum { - SEC2_IDX = 0 - ,FAMILY_IDX - ,SPLIT_IDX - ,MULTI_IDX -#ifdef H5_HAVE_STREAM - ,STREAM_IDX -#endif /* H5_HAVE_STREAM */ -#ifdef H5_HAVE_PARALLEL - ,MPIO_IDX - ,MPIPOSIX_IDX -#endif /* H5_HAVE_PARALLEL */ - }; -#define NUM_DRIVERS (sizeof(drivers_list) / sizeof(struct d_list)) - - static int initialized = 0; - register unsigned drivernum; - hid_t fid = FAIL; - hid_t fapl = H5P_DEFAULT; - - if (!initialized) { - /* Build a list of file access property lists which we should try - * when opening the file. Eventually we'd like some way for the - * user to augment/replace this list interactively. */ - ++initialized; - - /* SEC2 Driver */ - drivers_list[SEC2_IDX].fapl = H5P_DEFAULT; - - /* FAMILY Driver */ - drivers_list[FAMILY_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_family(fapl, (hsize_t)0, H5P_DEFAULT); - - /* SPLIT Driver */ - drivers_list[SPLIT_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT); - - /* MULTI Driver */ - drivers_list[MULTI_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_multi(fapl, NULL, NULL, NULL, NULL, TRUE); - -#ifdef H5_HAVE_STREAM - /* STREAM Driver */ - drivers_list[STREAM_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_stream(fapl, NULL); -#endif /* H5_HAVE_STREAM */ - -#ifdef H5_HAVE_PARALLEL - /* MPI-IO Driver */ - drivers_list[MPIO_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_mpio(fapl, MPI_COMM_WORLD, MPI_INFO_NULL); - - /* MPI-POSIX Driver */ - drivers_list[MPIPOSIX_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_mpiposix(fapl, MPI_COMM_WORLD, TRUE); -#endif /* H5_HAVE_PARALLEL */ - } + unsigned drivernum; + hid_t fid = FAIL; + hid_t fapl = H5P_DEFAULT; if (driver && *driver) { - /* Determine which driver the user wants to open the file with. Try - * that driver. If it can't open it, then fail. */ - if (!strcmp(driver, drivers_list[SEC2_IDX].name)) { - H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, - drivers_list[SEC2_IDX].fapl); - } H5E_END_TRY; - - if (fid == FAIL) - goto done; - - drivernum = SEC2_IDX; - } else if (!strcmp(driver, drivers_list[FAMILY_IDX].name)) { - H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, - drivers_list[FAMILY_IDX].fapl); - } H5E_END_TRY; - - if (fid == FAIL) - goto done; - - drivernum = FAMILY_IDX; - } else if (!strcmp(driver, drivers_list[SPLIT_IDX].name)) { - H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, - drivers_list[SPLIT_IDX].fapl); - } H5E_END_TRY; - - if (fid == FAIL) - goto done; - - drivernum = SPLIT_IDX; - } else if (!strcmp(driver, drivers_list[MULTI_IDX].name)) { - H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, - drivers_list[MULTI_IDX].fapl); - } H5E_END_TRY; - - if (fid == FAIL) - goto done; - - drivernum = MULTI_IDX; -#ifdef H5_HAVE_STREAM - } else if (!strcmp(driver, drivers_list[STREAM_IDX].name)) { - H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, - drivers_list[STREAM_IDX].fapl); - } H5E_END_TRY; + /* Get the correct FAPL for the given driver */ + if((fapl=h5tools_get_fapl(driver,&drivernum,argc,argv))<0) + goto done; - if (fid == FAIL) - goto done; + H5E_BEGIN_TRY { + fid = H5Fopen(fname, H5F_ACC_RDONLY, fapl); + } H5E_END_TRY; - drivernum = STREAM_IDX; -#endif /* H5_HAVE_STREAM */ -#ifdef H5_HAVE_PARALLEL - } else if (!strcmp(driver, drivers_list[MPIO_IDX].name)) { - H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, - drivers_list[MPIO_IDX].fapl); - } H5E_END_TRY; - if (fid == FAIL) - goto done; - drivernum = MPIO_IDX; - } else if (!strcmp(driver, drivers_list[MPIPOSIX_IDX].name)) { - H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, - drivers_list[MPIO_IDX].fapl); - } H5E_END_TRY; - if (fid == FAIL) - goto done; - drivernum = MPIPOSIX_IDX; -#endif /* H5_HAVE_PARALLEL */ - } else { + if (fid == FAIL) goto done; - } + } else { /* Try to open the file using each of the drivers */ for (drivernum = 0; drivernum < NUM_DRIVERS; drivernum++) { + /* Get the correct FAPL for the given driver */ + if((fapl=h5tools_get_fapl(drivernames[drivernum],NULL,argc,argv))<0) + goto done; + H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, - drivers_list[drivernum].fapl); + fid = H5Fopen(fname, H5F_ACC_RDONLY, fapl); } H5E_END_TRY; if (fid != FAIL) break; + else { + /* Close the FAPL */ + H5Pclose(fapl); + fapl=H5P_DEFAULT; + } /* end else */ } } /* Save the driver name */ if (drivername && drivername_size) { if (fid != FAIL) { - strncpy(drivername, drivers_list[drivernum].name, drivername_size); + strncpy(drivername, drivernames[drivernum], drivername_size); drivername[drivername_size - 1] = '\0'; } else { /*no file opened*/ @@ -347,6 +359,8 @@ h5tools_fopen(const char *fname, const char *driver, char *drivername, } done: + if(fapl!=H5P_DEFAULT) + H5Pclose(fapl); return fid; } diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 5ba9798..80349d5 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -472,7 +472,8 @@ extern FILE *rawdatastream; /*output stream for raw data */ extern void h5tools_init(void); extern void h5tools_close(void); extern hid_t h5tools_fopen(const char *fname, const char *driver, - char *drivername, size_t drivername_len); + char *drivername, size_t drivername_len, + int argc, const char *argv[]); extern int h5tools_dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_typ, struct subset_t *sset, int indentlevel); extern int h5tools_dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, |