Skip to content

Commit

Permalink
Support for precompiling modules based on MPI.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
barche committed Aug 20, 2018
1 parent aea61dc commit bb656f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
17 changes: 5 additions & 12 deletions src/MPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,13 @@ include("cman.jl")
const mpitype_dict = Dict{DataType, Cint}()
const mpitype_dict_inverse = Dict{Cint, DataType}()

function __init__()
@static if Compat.Sys.isunix()
# need to open libmpi with RTLD_GLOBAL flag for Linux, before
# any ccall cannot use RTLD_DEEPBIND; this leads to segfaults
# at least on Ubuntu 15.10
@eval const libmpi_handle =
Libdl.dlopen(libmpi, Libdl.RTLD_LAZY | Libdl.RTLD_GLOBAL)

# look up all symbols ahead of time
for (jname, fname) in _mpi_functions
Core.eval(MPI, :(const $jname = Libdl.dlsym(libmpi_handle, $fname)))
end
@static if Compat.Sys.isunix()
for (jname, fname) in _mpi_functions
Core.eval(MPI, :(const $jname = ($(QuoteNode(fname)),libmpi)))
end
end

function __init__()
# Note: older versions of OpenMPI (e.g. the version on Travis) do not
# define MPI_CHAR and MPI_*INT*_T for Fortran, so we don't use them (yet).
for (T,mpiT) in (Char => MPI_INTEGER4, # => MPI_WCHAR, (note: wchar_t is 16 bits in Windows)
Expand Down
4 changes: 2 additions & 2 deletions src/mpi-base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const MPIDatatype = Union{Char,
Float32, Float64, ComplexF32, ComplexF64}
MPIBuffertype{T} = Union{Ptr{T}, Array{T}, SubArray{T}, Ref{T}}

fieldoffsets(::Type{T}) where {T} = Int[fieldoffset(T, i) for i in 1:nfields(T)]
fieldoffsets(::Type{T}) where {T} = Int[fieldoffset(T, i) for i in 1:length(fieldnames(T))]

# Define a function mpitype(T) that returns the MPI datatype code for
# a given type T. In the case the the type does not exist, it is created and
Expand Down Expand Up @@ -209,7 +209,7 @@ function finalize_atexit()
if Sys.iswindows()
error("finalize_atexit is not supported on Windows")
end
ret = ccall(:install_finalize_atexit_hook, Cint, ())
ret = ccall((:install_finalize_atexit_hook, libmpi), Cint, ())
if ret != 0
error("Failed to set finalize_atexit")
end
Expand Down

0 comments on commit bb656f8

Please sign in to comment.