Skip to content

Commit

Permalink
Merge pull request #670 from JuliaParallel/sb/check-unchanged
Browse files Browse the repository at this point in the history
[MPIPreferences] add functions to check (and error) if the MPI implementation has changed
  • Loading branch information
simonbyrne authored Oct 6, 2022
2 parents 32c55e0 + 01c7de8 commit 0965740
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 18 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/Invalidations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,32 @@ jobs:
- uses: julia-actions/setup-julia@v1
with:
version: '1'
# current branch
- uses: actions/checkout@v3
- name: add MPIPreferences
shell: julia --color=yes --project=. {0}
run: |
using Pkg
Pkg.develop(path="lib/MPIPreferences")
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_pr

# default branch
- uses: actions/checkout@v3
with:
ref: ${{ github.event.repository.default_branch }}
- name: add MPIPreferences
shell: julia --color=yes --project=. {0}
run: |
using Pkg
Pkg.develop(path="lib/MPIPreferences")
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_default


# report
- name: Report invalidation counts
run: |
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MPI"
uuid = "da04e1cc-30fd-572f-bb4f-1f8673147195"
authors = []
version = "0.20.1"
version = "0.20.2"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand All @@ -18,6 +18,6 @@ Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"

[compat]
DocStringExtensions = "0.8, 0.9"
MPIPreferences = "0.1.3"
MPIPreferences = "0.1.6"
Requires = "~0.5, 1.0"
julia = "1.6"
1 change: 1 addition & 0 deletions docs/src/reference/mpipreferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ MPIPreferences.use_jll_binary
## Utils

```@docs
MPIPreferences.check_unchanged
MPIPreferences.identify_abi
```

Expand Down
2 changes: 1 addition & 1 deletion lib/MPIPreferences/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MPIPreferences"
uuid = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267"
authors = []
version = "0.1.5"
version = "0.1.6"

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Expand Down
68 changes: 56 additions & 12 deletions lib/MPIPreferences/src/MPIPreferences.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module MPIPreferences

export use_jll_binary, use_system_binary

using Preferences, Libdl

if !(VersionNumber(@load_preference("_format", "1.0")) <= v"1.0")
error("The preferences attached to MPIPreferences are incompatible with this version of the package.")
end

const PREFS_CHANGED = Ref(false)
const DEPS_LOADED = Ref(false)

"""
MPIPreferences.binary :: String
Expand Down Expand Up @@ -50,17 +55,19 @@ end
end

"""
MPIPreferences.use_jll_binary([binary]; export_prefs=false, force=true)
use_jll_binary([binary]; export_prefs=false, force=true)
Switches the underlying MPI implementation to one provided by JLL packages. A
restart of Julia is required for the changes to take effect.
Switches the underlying MPI implementation to one provided by JLL packages.
Available options are:
- `"MicrosoftMPI_jll"` (Only option and default on Winddows)
- `"MPICH_jll"` (Default on all other platform)
- `"OpenMPI_jll"`
- `"MPItrampoline_jll"`
The `export_prefs` option determines whether the preferences being set should be stored
within `LocalPreferences.toml` or `Project.toml`.
The `export_prefs` option determines whether the preferences being set should be
stored within `LocalPreferences.toml` or `Project.toml`.
"""
function use_jll_binary(binary = Sys.iswindows() ? "MicrosoftMPI_jll" : "MPICH_jll"; export_prefs=false, force=true)
binary in ["MicrosoftMPI_jll", "MPICH_jll", "OpenMPI_jll", "MPItrampoline_jll"] ||
Expand All @@ -75,8 +82,6 @@ function use_jll_binary(binary = Sys.iswindows() ? "MicrosoftMPI_jll" : "MPICH_j
force=force
)

@warn "The underlying MPI implementation has changed. You will need to restart Julia for this change to take effect" binary

if VERSION <= v"1.6.5" || VERSION == v"1.7.0"
@warn """
Due to a bug in Julia (until 1.6.5 and 1.7.1), setting preferences in transitive dependencies
Expand All @@ -85,19 +90,30 @@ function use_jll_binary(binary = Sys.iswindows() ? "MicrosoftMPI_jll" : "MPICH_j
"""
end

if binary == MPIPreferences.binary
@info "MPIPreferences unchanged" binary
else
PREFS_CHANGED[] = true
@info "MPIPreferences changed" binary

if DEPS_LOADED[]
error("You will need to restart Julia for the changes to take effect")
end
end
return nothing
end


"""
MPIPreferences.use_system_binary(;
use_system_binary(;
library_names = ["libmpi", "libmpi_ibm", "msmpi", "libmpich", "libmpi_cray", "libmpitrampoline"],
mpiexec = "mpiexec",
abi = nothing,
export_prefs = false,
force = true)
Switches the underlying MPI implementation to a system provided one.
Switches the underlying MPI implementation to a system provided one. A restart
of Julia is required for the changes to take effect.
Options:
Expand All @@ -113,9 +129,11 @@ Options:
to include specific command line options.
- `abi`: the ABI of the MPI library. By default this is determined automatically
using [`identify_abi`](@ref). See [`abi`](@ref) for currently supported values.
using [`identify_abi`](@ref). See [`abi`](@ref) for currently supported
values.
- `export_prefs`: if `true`, the preferences into the `Project.toml` instead of `LocalPreferences.toml`.
- `export_prefs`: if `true`, the preferences into the `Project.toml` instead of
`LocalPreferences.toml`.
- `force`: if `true`, the preferences are set even if they are already set.
"""
Expand Down Expand Up @@ -154,7 +172,6 @@ function use_system_binary(;
force=force
)

@warn "The underlying MPI implementation has changed. You will need to restart Julia for this change to take effect" binary libmpi abi mpiexec

if VERSION <= v"1.6.5" || VERSION == v"1.7.0"
@warn """
Expand All @@ -164,6 +181,33 @@ function use_system_binary(;
"""
end

if binary == MPIPreferences.binary && abi == MPIPreferences.abi && libmpi == System.libmpi && mpiexec == System.mpiexec_path
@info "MPIPreferences unchanged" binary libmpi abi mpiexec
else
PREFS_CHANGED[] = true
@info "MPIPreferences changed" binary libmpi abi mpiexec

if DEPS_LOADED[]
error("You will need to restart Julia for the changes to take effect")
end
end
return nothing
end

"""
MPIPreferences.check_unchanged()
Throws an error if the preferences have been modified in the current Julia
session, or if they are modified after this function is called.
This is should be called from the `__init__()` function of any package which
relies on the values of MPIPreferences.
"""
function check_unchanged()
if PREFS_CHANGED[]
error("MPIPreferences have changed, you will need to restart Julia for the changes to take effect")
end
DEPS_LOADED[] = true
return nothing
end

Expand Down Expand Up @@ -315,7 +359,7 @@ function identify_abi(libmpi)
# 2) try to identify the MPI implementation
impl, version, abi = identify_implementation_version_abi(version_string)

@info "MPI implementation" libmpi version_string impl version abi
@info "MPI implementation identified" libmpi version_string impl version abi

return abi
end
Expand Down
5 changes: 3 additions & 2 deletions src/MPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module MPI
using Libdl, Serialization
using Requires
using DocStringExtensions
import MPIPreferences

export mpiexec, UBuffer, VBuffer

Expand Down Expand Up @@ -58,7 +59,6 @@ function run_load_time_hooks()
nothing
end

using MPIPreferences
include("implementations.jl")
include("error.jl")
include("info.jl")
Expand All @@ -81,12 +81,13 @@ include("misc.jl")
include("deprecated.jl")

function __init__()
MPIPreferences.check_unchanged()

# an empty string was used to indicate "default"
# https://github.com/JuliaParallel/MPI.jl/blob/v0.19.2/deps/build.jl#L142
mpi_env_binary = get(ENV, "JULIA_MPI_BINARY", "")
if mpi_env_binary != "" && mpi_env_binary != MPIPreferences.binary
@info """
@warn """
The JULIA_MPI_BINARY environment variable is no longer used to configure the MPI binary.
Please use the MPIPreferences.jl package instead:
Expand Down

4 comments on commit 0965740

@simonbyrne
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=lib/MPIPreferences

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/69678

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a MPIPreferences-v0.1.6 -m "<description of version>" 096574032bfe6bde8ced4282f0ca458515c17dd2
git push origin MPIPreferences-v0.1.6

@simonbyrne
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/69679

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.20.2 -m "<description of version>" 096574032bfe6bde8ced4282f0ca458515c17dd2
git push origin v0.20.2

Please sign in to comment.