Skip to content

Commit 7e831e8

Browse files
authored
Call constant init via invokelatest (#592)
* Call constant init via invokelatest Yet another potential solution to #587. This appears to avoid early dlopen-ing of the library. * add precompile
1 parent a505393 commit 7e831e8

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/MPI.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,23 @@ include("mpiexec_wrapper.jl")
9999
include("deprecated.jl")
100100

101101
function __init__()
102-
103102
@static if Sys.isunix()
104103
# dlopen the MPI library before any ccall:
105104
# - RTLD_GLOBAL is required for Open MPI
106-
# <https://www.open-mpi.org/community/lists/users/2010/04/12803.php>
107-
# - also allows us to ccall global symbols, which enables
108-
# profilers which use LD_PRELOAD
109-
# - don't use RTLD_DEEPBIND; this leads to segfaults at least
110-
# on Ubuntu 15.10
111-
# <https://github.com/JuliaParallel/MPI.jl/pull/109>
105+
# https://www.open-mpi.org/community/lists/users/2010/04/12803.php
106+
# - also allows us to ccall global symbols, which enables profilers
107+
# which use LD_PRELOAD
108+
# - don't use RTLD_DEEPBIND; this leads to issues with multiple MPI
109+
# libraries:
110+
# https://github.com/JuliaParallel/MPI.jl/pull/109
111+
# https://github.com/JuliaParallel/MPI.jl/issues/587
112112
Libdl.dlopen(libmpi, Libdl.RTLD_LAZY | Libdl.RTLD_GLOBAL)
113113
end
114114

115+
# Needs to be called after `dlopen`. Use `invokelatest` so that `cglobal`
116+
# calls don't trigger early `dlopen`-ing of the library.
117+
Base.invokelatest(Consts.init_consts)
118+
115119
# disable UCX memory cache, since it doesn't work correctly
116120
# https://github.com/openucx/ucx/issues/5061
117121
if !haskey(ENV, "UCX_MEMTYPE_CACHE")

src/consts/consts.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ else
3939
error("Unknown MPI ABI $(MPIPreferences.abi)")
4040
end
4141

42-
@eval function __init__()
42+
# Initialize the ref constants from the library.
43+
# This is not `Consts.__init__`, as it should be called _after_
44+
# `dlopen` to ensure the library is opened correctly.
45+
@eval function init_consts()
4346
$(Expr(:block, initexprs...))
4447
end
4548

49+
# since this is called by invokelatest, it isn't automatically precompiled
50+
precompile(init_consts, ())
51+
4652
end

0 commit comments

Comments
 (0)