Skip to content

Commit dbecd49

Browse files
authored
simplify msmpi stdcall logic (#366)
1 parent 9d06df0 commit dbecd49

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

src/environment.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,11 @@ function Finalized()
254254
end
255255

256256
function Wtick()
257-
@static if MPI_LIBRARY == MicrosoftMPI
258-
ccall((:MPI_Wtick, libmpi), stdcall, Cdouble, ())
259-
else
260-
ccall((:MPI_Wtick, libmpi), Cdouble, ())
261-
end
257+
@mpicall ccall((:MPI_Wtick, libmpi), Cdouble, ())
262258
end
263259

264260
function Wtime()
265-
@static if MPI_LIBRARY == MicrosoftMPI
266-
ccall((:MPI_Wtime, libmpi), stdcall, Cdouble, ())
267-
else
268-
ccall((:MPI_Wtime, libmpi), Cdouble, ())
269-
end
261+
@mpicall ccall((:MPI_Wtime, libmpi), Cdouble, ())
270262
end
271263

272264

src/error.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ struct MPIError <: Exception
33
end
44

55
macro mpichk(expr)
6-
@assert expr isa Expr && expr.head == :call && expr.args[1] == :ccall
7-
if MPI_LIBRARY == MicrosoftMPI
8-
insert!(expr.args, 3, :stdcall)
9-
end
6+
expr = macroexpand(@__MODULE__, :(@mpicall($expr)))
107
:((errcode = $(esc(expr))) == MPI_SUCCESS || throw(MPIError(errcode)))
118
end
129

src/implementations.jl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ function Get_library_version()
77
buf = Array{UInt8}(undef, 8192)
88
buflen = Ref{Cint}()
99

10-
# Microsoft MPI uses stdcall calling convention
1110
libfilename, = split(basename(libmpi),'.')
12-
if libfilename == "msmpi"
13-
ccall((:MPI_Get_library_version, libmpi), stdcall, Cint, (Ptr{UInt8}, Ref{Cint}), buf, buflen)
14-
else
15-
ccall((:MPI_Get_library_version, libmpi), Cint, (Ptr{UInt8}, Ref{Cint}), buf, buflen)
16-
end
11+
@mpicall ccall((:MPI_Get_library_version, libmpi), Cint, (Ptr{UInt8}, Ref{Cint}), buf, buflen)
1712
resize!(buf, buflen[])
1813
return String(buf)
1914
end
@@ -190,13 +185,8 @@ MPI_LIBRARY_ABI
190185
function Get_version()
191186
major = Ref{Cint}()
192187
minor = Ref{Cint}()
193-
if MPI_LIBRARY == MicrosoftMPI
194-
ccall((:MPI_Get_version, libmpi), stdcall, Cint,
195-
(Ptr{Cint}, Ptr{Cint}), major, minor)
196-
else
197-
ccall((:MPI_Get_version, libmpi), Cint,
198-
(Ptr{Cint}, Ptr{Cint}), major, minor)
199-
end
188+
@mpicall ccall((:MPI_Get_version, libmpi), Cint,
189+
(Ptr{Cint}, Ptr{Cint}), major, minor)
200190
VersionNumber(major[], minor[])
201191
end
202192

src/paths.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,18 @@ function mpiexec(fn)
6565
mpiexec_args = Base.shell_split(get(ENV, "JULIA_MPIEXEC_ARGS", ""))
6666
fn(`$mpiexec_path $mpiexec_args`)
6767
end
68+
69+
70+
const use_stdcall = startswith(basename(libmpi), "msmpi")
71+
72+
macro mpicall(expr)
73+
@assert expr isa Expr && expr.head == :call && expr.args[1] == :ccall
74+
# Microsoft MPI uses stdcall calling convention
75+
# this only affects 32-bit Windows
76+
# unfortunately we need to use ccall to call Get_library_version
77+
# so check using library name instead
78+
if use_stdcall
79+
insert!(expr.args, 3, :stdcall)
80+
end
81+
return esc(expr)
82+
end

0 commit comments

Comments
 (0)