Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Preferences for using custom hdf5 library #1061

Merged
merged 41 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f7dc5c2
use system library using Preferences.jl
JoshuaLampert Apr 19, 2023
7d226ae
allow specific library filenames
JoshuaLampert Apr 19, 2023
3261f29
fix typo
JoshuaLampert Apr 19, 2023
0489e4d
Apply suggestions from code review
JoshuaLampert Apr 19, 2023
d60a8e6
import dlsym
JoshuaLampert Apr 19, 2023
93601ac
remove deps folder from Format check
JoshuaLampert Apr 19, 2023
7c34b18
set julia compat to 1.6
JoshuaLampert Apr 19, 2023
f292a51
extend docs
JoshuaLampert Apr 19, 2023
efbda60
format
JoshuaLampert Apr 20, 2023
0571a1d
bump version
JoshuaLampert Apr 20, 2023
99f695a
bump HDF5 compat versions of filters to 0.17
JoshuaLampert Apr 20, 2023
6eb754c
update HISTORY.md
JoshuaLampert Apr 20, 2023
2e5239b
add note on migration instructions
JoshuaLampert Apr 21, 2023
d190097
add example of LocalPreferences.toml in docs
JoshuaLampert Apr 21, 2023
00b320a
CI test for system libraries with Preferences
JoshuaLampert Apr 27, 2023
31f6114
format
JoshuaLampert Apr 27, 2023
1cc907d
fix pwd
JoshuaLampert Apr 27, 2023
3a440e7
add Project.toml
JoshuaLampert Apr 27, 2023
09167eb
rm Project.toml
JoshuaLampert Apr 27, 2023
63ca75d
add julia-actions to system library CI
JoshuaLampert Apr 27, 2023
91efbee
debug CI
JoshuaLampert Apr 27, 2023
37cc3c2
add Project.toml
JoshuaLampert Apr 27, 2023
e896d9d
remove additional julia-actions
JoshuaLampert Apr 27, 2023
bf1cebc
debug CI
JoshuaLampert Apr 27, 2023
369caa2
debug CI
JoshuaLampert Apr 27, 2023
ab7700c
explicitly state possible library names in docs
JoshuaLampert Apr 27, 2023
645f574
set prefs to each library
JoshuaLampert Apr 27, 2023
811650d
Merge branch 'master' into preferences
mkitti Apr 27, 2023
a8cb6ba
Merge branch 'master' into preferences
JoshuaLampert May 1, 2023
77f3e19
update docs (HDF5_jll comes with MPI)
JoshuaLampert May 29, 2023
99f3875
workaround
JoshuaLampert May 29, 2023
cf318da
Merge branch 'master' into preferences
mkitti May 30, 2023
1e183f0
fix workaround
JoshuaLampert May 30, 2023
bd14d4f
disable virtual dataset tests for libhdf5 version < 1.12
JoshuaLampert Jun 1, 2023
13ec550
fix typo in docs
JoshuaLampert Jun 1, 2023
8e98087
raise warning if JULIA_HDF5_PATH is detected
JoshuaLampert Jun 1, 2023
a156e60
format
JoshuaLampert Jun 1, 2023
5304ba5
Apply suggestions from code review
JoshuaLampert Jun 2, 2023
b89dda3
set both preferences in one call
JoshuaLampert Jun 2, 2023
7e5eec7
set both preferences in one call
JoshuaLampert Jun 2, 2023
37dde47
Apply suggestions from code review
JoshuaLampert Jun 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.jl.mem
/docs/build/
Manifest.toml
LocalPreferences.toml
14 changes: 8 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ name = "HDF5"
uuid = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
version = "0.16.14"

[compat]
Compat = "3.1.0, 4"
HDF5_jll = "~1.10.5, ~1.12.0"
Requires = "1.0"
julia = "1.3"
JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved
JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
HDF5_jll = "0234f1f7-429e-5d53-9886-15a909be8d59"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Compat = "3.1.0, 4"
HDF5_jll = "~1.10.5, ~1.12.0"
Requires = "1.0"
julia = "1.3"

[extras]
CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand All @@ -27,6 +28,7 @@ H5Zlz4 = "eb20ec05-5464-47b5-ba41-098e3c1068a3"
H5Zzstd = "f6f2d980-1ec6-471c-a70d-0270e22f1103"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
MPIPreferences = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
5 changes: 0 additions & 5 deletions deps/.gitignore

This file was deleted.

77 changes: 0 additions & 77 deletions deps/build.jl

This file was deleted.

23 changes: 17 additions & 6 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,35 @@ Starting from Julia 1.3, the HDF5 binaries are by default downloaded using the `

### Using custom or system provided HDF5 binaries

To use system-provided HDF5 binaries instead, set the environment variable `JULIA_HDF5_PATH` to the top-level installation directory HDF5, i.e. the library should be located in `${JULIA_HDF5_PATH}/lib` or `${JULIA_HDF5_PATH}/lib64`, or alternatively simply in `${JULIA_HDF5_PATH}`. Then run `import Pkg; Pkg.build("HDF5")`. In particular, this is required if you need parallel HDF5 support, which is not provided by the `HDF5_jll` binaries.
To use system-provided HDF5 binaries instead, set the preference `libhdf5path`, see also [Preferences.jl](https://github.com/JuliaPackaging/Preferences.jl). This has to be the top-level installation directory of HDF5, i.e. the library should be located in `${JULIA_HDF5_PATH}/lib` or `${JULIA_HDF5_PATH}/lib64`, or alternatively simply in `${JULIA_HDF5_PATH}`. In particular, this is required if you need parallel HDF5 support, which is not provided by the `HDF5_jll` binaries.

If the library is in your library search path, then `JULIA_HDF5_PATH` can be set to an empty string.
If the library is in your library search path, then `libhdf5path` can be set to an empty string.

For example, to use HDF5 (`libhdf5-mpich-dev`) with MPI using system libraries on Ubuntu 20.04, you would run:
For example, to use HDF5 (`libhdf5-mpich-dev`) with MPI using system libraries on Ubuntu 20.04, you would run

```sh
$ sudo apt install mpich libhdf5-mpich-dev
$ JULIA_HDF5_PATH=/usr/lib/x86_64-linux-gnu/hdf5/mpich/
$ JULIA_MPI_BINARY=system
```

Then in Julia, run:

```julia
pkg> build
using MPIPreferences
MPIPreferences.use_system_binary()
```

to set the MPI preferences, see the [documentation of MPI.jl](https://juliaparallel.org/MPI.jl/stable/configuration/) and then:

```julia
JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved
using Preferences, UUIDs

set_preferences!(
UUID("f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"), # UUID of HDF5.jl
"libhdf5path" => "/usr/lib/x86_64-linux-gnu/hdf5/mpich/", force = true)
```

to set the preference for the custom HDF5 library.

## Opening and closing files

"Plain" (i.e., with no extra formatting conventions) HDF5 files are created and/or opened with the `h5open` command:
Expand Down
13 changes: 10 additions & 3 deletions docs/src/mpi.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ for details.
### 2. Using parallel HDF5 libraries

As detailed in [Using custom or system provided HDF5 binaries](@ref), set the
`JULIA_HDF5_PATH` environment variable to the path where the parallel HDF5
binaries are located.
Then run `]build HDF5` from Julia.
preference `libhdf5path` to the path where the parallel HDF5 binaries are located.
This can be done by:

```julia
julia> using Preferences, UUIDs

julia> set_preferences!(
UUID("f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"), # UUID of HDF5.jl
"libhdf5path" => "/path/to/your/hdf5/binaries/", force = true)
```
JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved

### 3. Loading MPI-enabled HDF5

Expand Down
51 changes: 39 additions & 12 deletions src/api/api.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
module API

import Libdl
using Libdl
JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved
using Base: StringVector
using Preferences: @load_preference

const depsfile = joinpath(@__DIR__, "..", "..", "deps", "deps.jl")
if isfile(depsfile)
include(depsfile)
# We avoid calling Libdl.find_library to avoid possible segfault when calling
# dlclose (#929).
# The only difference with Libdl.find_library is that we allow custom dlopen
# flags via the `flags` argument.
function find_library_alt(libnames, extrapaths=String[]; flags=RTLD_LAZY)
for lib in libnames
for path in extrapaths
l = joinpath(path, lib)
p = dlopen(l, flags; throw_error=false)
if p !== nothing
dlclose(p)
return l
end
end
p = dlopen(lib, flags; throw_error=false)
if p !== nothing
dlclose(p)
return lib
end
end
return ""
end

const libpath = @load_preference("libhdf5path", nothing)
if libpath === nothing
using HDF5_JLL
JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved
else
@error(
"HDF5 is not properly installed. Please run Pkg.build(\"HDF5\") ",
"and restart Julia."
)
libpaths = [libpath, joinpath(libpath, "lib"), joinpath(libpath, "lib64")]
flags = RTLD_LAZY | RTLD_NODELETE # RTLD_NODELETE may be needed to avoid segfault (#929)

libhdf5 = find_library_alt(["libhdf5", "libhdf5_openmpi", "libhdf5_mpich"], libpaths; flags=flags)
libhdf5_hl = find_library_alt(["libhdf5_hl", "libhdf5_openmpi_hl", "libhdf5_mpich_hl"], libpaths; flags=flags)

isempty(libhdf5) && error("libhdf5 could not be found")
isempty(libhdf5_hl) && error("libhdf5_hl could not be found")
JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved

libhdf5_size = filesize(dlpath(libhdf5))
end

include("lock.jl")
Expand All @@ -22,11 +52,8 @@ include("helpers.jl")
function __init__()
# HDF5.API.__init__() is run before HDF5.__init__()

# From deps.jl
check_deps()

# Ensure this is reinitialized on using
libhdf5handle[] = Libdl.dlopen(libhdf5)
libhdf5handle[] = dlopen(libhdf5)

JoshuaLampert marked this conversation as resolved.
Show resolved Hide resolved
# Disable file locking as that can cause problems with mmap'ing.
# File locking is disabled in HDF5.init!(::FileAccessPropertyList)
Expand Down