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

Allow using P4est for preferences not set correctly #93

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions dev/prologue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ using P4est_jll: P4est_jll
export P4est_jll

using ..P4est: _PREFERENCE_LIBP4EST, _PREFERENCE_LIBSC
using MPIPreferences: MPIPreferences

@static if _PREFERENCE_LIBP4EST == "P4est_jll"
@static if _PREFERENCE_LIBP4EST == "P4est_jll" && MPIPreferences.binary == "system"
@warn "System MPI version detected, but not a system p4est version. To make P4est.jl work, you need to set the preferences, see https://trixi-framework.github.io/P4est.jl/stable/#Using-a-custom-version-of-MPI-and/or-p4est."
elseif _PREFERENCE_LIBP4EST == "P4est_jll"
const libp4est = P4est_jll.libp4est
else
const libp4est = _PREFERENCE_LIBP4EST
end

@static if _PREFERENCE_LIBSC == "P4est_jll"
@static if _PREFERENCE_LIBSC == "P4est_jll" && MPIPreferences.binary == "system"
@warn "System MPI version detected, but not a system p4est version. To make P4est.jl work, you need to set the preferences, see https://trixi-framework.github.io/P4est.jl/stable/#Using-a-custom-version-of-MPI-and/or-p4est."
elseif _PREFERENCE_LIBSC == "P4est_jll"
const libsc = P4est_jll.libsc
else
const libsc = _PREFERENCE_LIBSC
Expand Down
9 changes: 7 additions & 2 deletions src/LibP4est.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ using P4est_jll: P4est_jll
export P4est_jll

using ..P4est: _PREFERENCE_LIBP4EST, _PREFERENCE_LIBSC
using MPIPreferences: MPIPreferences

@static if _PREFERENCE_LIBP4EST == "P4est_jll"
@static if _PREFERENCE_LIBP4EST == "P4est_jll" && MPIPreferences.binary == "system"
@warn "System MPI version detected, but not a system p4est version. To make P4est.jl work, you need to set the preferences, see https://trixi-framework.github.io/P4est.jl/stable/#Using-a-custom-version-of-MPI-and/or-p4est."
elseif _PREFERENCE_LIBP4EST == "P4est_jll"
const libp4est = P4est_jll.libp4est
else
const libp4est = _PREFERENCE_LIBP4EST
end

@static if _PREFERENCE_LIBSC == "P4est_jll"
@static if _PREFERENCE_LIBSC == "P4est_jll" && MPIPreferences.binary == "system"
@warn "System MPI version detected, but not a system p4est version. To make P4est.jl work, you need to set the preferences, see https://trixi-framework.github.io/P4est.jl/stable/#Using-a-custom-version-of-MPI-and/or-p4est."
elseif _PREFERENCE_LIBSC == "P4est_jll"
const libsc = P4est_jll.libsc
else
const libsc = _PREFERENCE_LIBSC
Expand Down
42 changes: 37 additions & 5 deletions src/P4est.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module P4est

using Reexport: @reexport


using MPIPreferences: MPIPreferences
# We need to load the preference setting from here and not from `LibP4est.jl`
# since `@load_preference` looks into the module it is running from. Thus, we
# load all preferences here and access them from the `module LibP4est`.
Expand Down Expand Up @@ -66,6 +66,15 @@ function set_library_p4est!(path = nothing; force = true)
@info "Please restart Julia and reload P4est.jl for the library changes to take effect"
end

"""
P4est.path_p4est_library()

Return the path of the `p4est` library that is used, when a system-provided library
is configured via the preferences. Otherwise `P4est_jll` is returned, which means
that the default p4est version from P4est_jll.jl is used.
"""
path_p4est_library() = _PREFERENCE_LIBP4EST

"""
P4est.set_library_sc!(path; force = true)

Expand All @@ -85,6 +94,23 @@ function set_library_sc!(path = nothing; force = true)
@info "Please restart Julia and reload P4est.jl for the library changes to take effect"
end

"""
P4est.path_sc_library()

Return the path of the `sc` library that is used, when a system-provided library
is configured via the preferences. Otherwise `P4est_jll` is returned, which means
that the default sc version from P4est_jll.jl is used.
"""
path_sc_library() = _PREFERENCE_LIBSC

"""
P4est.preferences_set_correctly()

Returns `false` if a system-provided MPI installation is set via the MPIPreferences, but
not a system-provided `p4est` installation. In this case, P4est.jl is not usable.
"""
preferences_set_correctly() = !(_PREFERENCE_LIBP4EST == "P4est_jll" && MPIPreferences.binary == "system")

"""
P4est.init(log_handler, log_threshold)

Expand All @@ -110,10 +136,16 @@ end


function __init__()
version = P4est.version()

if !(v"2.3" <= version < v"3-")
@warn "Detected version $(version) of `p4est`. Currently, we only support versions v2.x.y from v2.3.0 on. Not everything may work correctly."
# If a system-provided MPI installation with default p4est version is used, we cannot execute `P4est.version()`
# because the p4est functions are not available
if preferences_set_correctly()
version = P4est.version()

if !(v"2.3" <= version < v"3-")
@warn "Detected version $(version) of `p4est`. Currently, we only support versions v2.x.y from v2.3.0 on. Not everything may work correctly."
end
else
@warn "System MPI version detected, but not a system p4est version. To make P4est.jl work, you need to set the preferences, see https://trixi-framework.github.io/P4est.jl/stable/#Using-a-custom-version-of-MPI-and/or-p4est."
end

return nothing
Expand Down
Loading