From e1bd4953336995f8694240561810c41d68d48246 Mon Sep 17 00:00:00 2001 From: David MacMahon Date: Mon, 13 Jun 2022 17:46:40 -0700 Subject: [PATCH 1/8] Avoid calling non-public h5fd_xxx_init() functions The h5fd_xxx_init() functions are not part of the HDF5 public API. A method of retrieving the hid_t value of drivers that uses public/supported API calls was suggested in a comment on a related github issue and is implemented in this commit. For more details see: https://github.com/HDFGroup/hdf5/issues/1809#issuecomment-1154397046 --- src/drivers/drivers.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/drivers/drivers.jl b/src/drivers/drivers.jl index 0cac96b22..03119e2dc 100644 --- a/src/drivers/drivers.jl +++ b/src/drivers/drivers.jl @@ -85,8 +85,12 @@ function set_driver!(p::Properties, ::POSIX) end function __init__() - DRIVERS[API.h5fd_core_init()] = Core - DRIVERS[API.h5fd_sec2_init()] = POSIX + fapl = HDF5.FileAccessProperties(fclose_degree=:default) + API.h5p_set_fapl_core(fapl, 4096, false) + DRIVERS[API.h5p_get_driver(fapl)] = Core + API.h5p_set_fapl_sec2(fapl) + DRIVERS[API.h5p_get_driver(fapl)] = POSIX + close(fapl) @require MPI="da04e1cc-30fd-572f-bb4f-1f8673147195" include("mpio.jl") end From e4917b721484e91b5e98caa263a400bdef9e8170 Mon Sep 17 00:00:00 2001 From: David MacMahon Date: Wed, 15 Jun 2022 08:59:10 -0700 Subject: [PATCH 2/8] Initialize fapl minimally in Drivers.__init__() --- src/drivers/drivers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/drivers.jl b/src/drivers/drivers.jl index 03119e2dc..f9ef784e5 100644 --- a/src/drivers/drivers.jl +++ b/src/drivers/drivers.jl @@ -85,7 +85,7 @@ function set_driver!(p::Properties, ::POSIX) end function __init__() - fapl = HDF5.FileAccessProperties(fclose_degree=:default) + fapl = HDF5.init!(HDF5.FileAccessProperties()) API.h5p_set_fapl_core(fapl, 4096, false) DRIVERS[API.h5p_get_driver(fapl)] = Core API.h5p_set_fapl_sec2(fapl) From afca05af4a5d935d187c500aa9728b88e175cb45 Mon Sep 17 00:00:00 2001 From: David MacMahon Date: Wed, 15 Jun 2022 09:01:33 -0700 Subject: [PATCH 3/8] Disable file locking in Drivers.__init() Unless the user has already set `HDF5_USE_FILE_LOCKING` in the environment, set it to `FALSE` to avoid causing problems with mmap'ing. This needs to be done before the first call to the HDF5 APIs. --- src/drivers/drivers.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/drivers/drivers.jl b/src/drivers/drivers.jl index f9ef784e5..d2ec23840 100644 --- a/src/drivers/drivers.jl +++ b/src/drivers/drivers.jl @@ -85,6 +85,11 @@ function set_driver!(p::Properties, ::POSIX) end function __init__() + # disable file locking as that can cause problems with mmap'ing + if !haskey(ENV, "HDF5_USE_FILE_LOCKING") + ENV["HDF5_USE_FILE_LOCKING"] = "FALSE" + end + fapl = HDF5.init!(HDF5.FileAccessProperties()) API.h5p_set_fapl_core(fapl, 4096, false) DRIVERS[API.h5p_get_driver(fapl)] = Core From 3db79a9adb7e6fb1fb15bee9887dbb20d60d50c9 Mon Sep 17 00:00:00 2001 From: David MacMahon Date: Wed, 15 Jun 2022 09:06:02 -0700 Subject: [PATCH 4/8] Change how parallel HDF5 suppport is detected Instead of detecting parallel HDF5 support by whether `h5fd_mpio_init()` throws an exception, parallel support is detected by finding the `H5Pset_fapl_mpio` symbol in any loaded library whose name matches `r"hdf5"i`. The documentation for `H5Pset_fapl_mpio()` states: > H5Pset_fapl_mpio() is available only in the parallel HDF5 library The detection has also been moved into `Drivers.__init__()` and the inclusion of `mpio.jl` (upon loading of the MPI package) will only happen if the HDF5 libraries have parallel support. --- src/drivers/drivers.jl | 15 ++++++++++++++- src/drivers/mpio.jl | 7 ------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/drivers/drivers.jl b/src/drivers/drivers.jl index d2ec23840..ff328c860 100644 --- a/src/drivers/drivers.jl +++ b/src/drivers/drivers.jl @@ -96,7 +96,20 @@ function __init__() API.h5p_set_fapl_sec2(fapl) DRIVERS[API.h5p_get_driver(fapl)] = POSIX close(fapl) - @require MPI="da04e1cc-30fd-572f-bb4f-1f8673147195" include("mpio.jl") + + # Check whether the loaded HDF5 libraries were compiled with parallel support. + loaded_libs = filter(contains(r"hdf5"i), Libc.Libdl.dllist()) + for libname in loaded_libs + has_mpio = Libc.Libdl.dlopen(libname) do lib + Libc.Libdl.dlsym(lib, :H5Pset_fapl_mpio; throw_error=false) !== nothing + end + if has_mpio + HDF5.HAS_PARALLEL[] = true + break + end + end + + @require MPI="da04e1cc-30fd-572f-bb4f-1f8673147195" (HDF5.has_parallel() && include("mpio.jl")) end end # module diff --git a/src/drivers/mpio.jl b/src/drivers/mpio.jl index 579d383b7..528fae9e2 100644 --- a/src/drivers/mpio.jl +++ b/src/drivers/mpio.jl @@ -42,13 +42,6 @@ end MPIO(comm::MPI.Comm; kwargs...) = MPIO(comm, MPI.Info(;kwargs...)) -# Check whether the HDF5 libraries were compiled with parallel support. -try - DRIVERS[API.h5fd_mpio_init()] = MPIO - HDF5.HAS_PARALLEL[] = true -catch e -end - function set_driver!(fapl::Properties, mpio::MPIO) HDF5.has_parallel() || error( "HDF5.jl has no parallel support." * From 77601242f205fd707efd5c842c60e9f6c95498af Mon Sep 17 00:00:00 2001 From: David MacMahon Date: Wed, 15 Jun 2022 09:26:13 -0700 Subject: [PATCH 5/8] Add DRIVERS entry for MPIO lazily in set_driver! --- src/drivers/mpio.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/drivers/mpio.jl b/src/drivers/mpio.jl index 528fae9e2..6231c1b53 100644 --- a/src/drivers/mpio.jl +++ b/src/drivers/mpio.jl @@ -53,6 +53,9 @@ function set_driver!(fapl::Properties, mpio::MPIO) GC.@preserve mpio begin API.h5p_set_fapl_mpio(fapl, mpi_to_h5(mpio.comm), mpi_to_h5(mpio.info)) end + + DRIVERS[API.h5p_get_driver(fapl)] = MPIO + return nothing end function get_driver(fapl::Properties, ::Type{MPIO}) From e9d513fc30c72bef096c7a6d7598974a21675d67 Mon Sep 17 00:00:00 2001 From: David MacMahon Date: Wed, 15 Jun 2022 09:49:14 -0700 Subject: [PATCH 6/8] Replace `contains()` with call to older `match()` This maintains compatibility with pre-1.5 versions of Julia. --- src/drivers/drivers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/drivers.jl b/src/drivers/drivers.jl index ff328c860..b68f507d2 100644 --- a/src/drivers/drivers.jl +++ b/src/drivers/drivers.jl @@ -98,7 +98,7 @@ function __init__() close(fapl) # Check whether the loaded HDF5 libraries were compiled with parallel support. - loaded_libs = filter(contains(r"hdf5"i), Libc.Libdl.dllist()) + loaded_libs = filter(s->match(r"hdf5"i, s) !== nothing, Libc.Libdl.dllist()) for libname in loaded_libs has_mpio = Libc.Libdl.dlopen(libname) do lib Libc.Libdl.dlsym(lib, :H5Pset_fapl_mpio; throw_error=false) !== nothing From 811c29de12e50a189c0bb6393ecc25c85281b39f Mon Sep 17 00:00:00 2001 From: David MacMahon Date: Wed, 15 Jun 2022 11:10:13 -0700 Subject: [PATCH 7/8] Improve usage of Libdl --- src/drivers/drivers.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/drivers/drivers.jl b/src/drivers/drivers.jl index b68f507d2..b342e2392 100644 --- a/src/drivers/drivers.jl +++ b/src/drivers/drivers.jl @@ -5,6 +5,7 @@ export POSIX import ..API import ..HDF5: HDF5, Properties, h5doc +using Libdl: dllist, dlopen, dlsym using Requires: @require @@ -98,10 +99,10 @@ function __init__() close(fapl) # Check whether the loaded HDF5 libraries were compiled with parallel support. - loaded_libs = filter(s->match(r"hdf5"i, s) !== nothing, Libc.Libdl.dllist()) + loaded_libs = filter(s->match(r"hdf5"i, s) !== nothing, dllist()) for libname in loaded_libs - has_mpio = Libc.Libdl.dlopen(libname) do lib - Libc.Libdl.dlsym(lib, :H5Pset_fapl_mpio; throw_error=false) !== nothing + has_mpio = dlopen(libname) do lib + dlsym(lib, :H5Pset_fapl_mpio; throw_error=false) !== nothing end if has_mpio HDF5.HAS_PARALLEL[] = true From 57c0e52306b7c41a2db9bf1c36c8095bef435ef3 Mon Sep 17 00:00:00 2001 From: David MacMahon Date: Wed, 15 Jun 2022 11:16:39 -0700 Subject: [PATCH 8/8] Use HDF5.API.libhdf5 rather than dllist() --- src/drivers/drivers.jl | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/drivers/drivers.jl b/src/drivers/drivers.jl index b342e2392..43a1e69ae 100644 --- a/src/drivers/drivers.jl +++ b/src/drivers/drivers.jl @@ -5,7 +5,7 @@ export POSIX import ..API import ..HDF5: HDF5, Properties, h5doc -using Libdl: dllist, dlopen, dlsym +using Libdl: dlopen, dlsym using Requires: @require @@ -98,16 +98,9 @@ function __init__() DRIVERS[API.h5p_get_driver(fapl)] = POSIX close(fapl) - # Check whether the loaded HDF5 libraries were compiled with parallel support. - loaded_libs = filter(s->match(r"hdf5"i, s) !== nothing, dllist()) - for libname in loaded_libs - has_mpio = dlopen(libname) do lib - dlsym(lib, :H5Pset_fapl_mpio; throw_error=false) !== nothing - end - if has_mpio - HDF5.HAS_PARALLEL[] = true - break - end + # Check whether the libhdf5 was compiled with parallel support. + HDF5.HAS_PARALLEL[] = dlopen(HDF5.API.libhdf5) do lib + dlsym(lib, :H5Pset_fapl_mpio; throw_error=false) !== nothing end @require MPI="da04e1cc-30fd-572f-bb4f-1f8673147195" (HDF5.has_parallel() && include("mpio.jl"))