Skip to content

Commit 50db836

Browse files
committed
Add a lightweight MPIABI sub-package that controls the MPI ABI
1 parent eb707ea commit 50db836

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

lib/MPIABI/Project.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name = "MPIABI"
2+
uuid = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267"
3+
authors = []
4+
version = "0.1.0"
5+
6+
[deps]
7+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

lib/MPIABI/UNLICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
This is free and unencumbered software released into the public
2+
domain.
3+
4+
Anyone is free to copy, modify, publish, use, compile, sell, or
5+
distribute this software, either in source code form or as a compiled
6+
binary, for any purpose, commercial or non-commercial, and by any
7+
means.
8+
9+
In jurisdictions that recognize copyright laws, the author or authors
10+
of this software dedicate any and all copyright interest in the
11+
software to the public domain. We make this dedication for the benefit
12+
of the public at large and to the detriment of our heirs and
13+
successors. We intend this dedication to be an overt act of
14+
relinquishment in perpetuity of all present and future rights to this
15+
software under copyright law.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
OTHER DEALINGS IN THE SOFTWARE.
24+
25+
For more information, please refer to <http://unlicense.org/>

lib/MPIABI/src/MPIABI.jl

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
module MPIABI
2+
3+
using Preferences
4+
5+
function known_abis()
6+
return (:MicrosoftMPI, :MPICH, :OpenMPI, :MPItrampoline)
7+
end
8+
9+
# const abi = begin
10+
# _abi = @load_preference("abi", nothing)
11+
# if isnothing(_abi)
12+
# _abi = find_abi()
13+
# @set_preference!("abi" => _abi)
14+
# end
15+
# _abi
16+
# end
17+
18+
const abi = @load_preference("abi", Sys.iswindows() ? :MicrosoftMPI : :MPICH)
19+
20+
function __init__()
21+
if Sys.iswindows()
22+
if abi != :MicrosoftMPI
23+
@error """
24+
The MPI ABI is not compatible with the current platform.
25+
Please set the MPI ABI to :MicrosoftMPI.
26+
"""
27+
end
28+
end
29+
end
30+
31+
function set_abi(abi)
32+
if abi known_abis()
33+
error("""
34+
The MPI ABI $abi is not supported.
35+
Please set the MPI ABI to one of the following:
36+
$(known_abis())
37+
""")
38+
end
39+
@set_preferences!("abi" => abi)
40+
@warn "The MPI abi has changed, you will need to restart Julia for the change to take effect" abi
41+
42+
if VERSION <= v"1.6.5" || VERSION == v"1.7.0"
43+
@warn """
44+
Due to a bug in Julia (until 1.6.5 and 1.7.1), setting preferences in transitive dependencies
45+
is broken (https://github.com/JuliaPackaging/Preferences.jl/issues/24). As a workaround, we
46+
will now add MPIABI as a direct dependency in your current project.
47+
"""
48+
49+
uuid = Preferences.get_uuid(@__MODULE__)
50+
project_toml, pkg_name = Preferences.find_first_project_with_uuid(uuid)
51+
52+
if project_toml === nothing && pkg_name === nothing
53+
# If we couldn't find one, we're going to use `active_project()`
54+
project_toml = Base.active_project()
55+
56+
# And we're going to need to add this UUID as an "extras" dependency:
57+
# We're going to assume you want to name this this dependency in the
58+
# same way as it's been loaded:
59+
pkg_uuid_matches = filter(d -> d.uuid == uuid, keys(Base.loaded_modules))
60+
if isempty(pkg_uuid_matches)
61+
error("Cannot set preferences of an unknown package that is not loaded!")
62+
end
63+
pkg_name = first(pkg_uuid_matches).name
64+
65+
# Read in the project, add the deps, write it back out!
66+
project = Base.parsed_toml(project_toml)
67+
if !haskey(project, "deps")
68+
project["deps"] = Dict{String,Any}()
69+
end
70+
project["deps"][pkg_name] = string(uuid)
71+
open(project_toml, "w") do io
72+
TOML.print(io, project; sorted=true)
73+
end
74+
end
75+
end
76+
return abi
77+
end
78+
79+
end # module

0 commit comments

Comments
 (0)