Skip to content

Commit b3b83cd

Browse files
authored
add c2f/f2c handle conversions (#798)
1 parent 23a03e5 commit b3b83cd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/api/api.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,35 @@ end
135135

136136
include("generated_api.jl")
137137

138+
for handle in [
139+
:MPI_Comm,
140+
:MPI_Datatype,
141+
:MPI_Errhandler,
142+
:MPI_File,
143+
:MPI_Group,
144+
:MPI_Info,
145+
:MPI_Message,
146+
:MPI_Op,
147+
:MPI_Request,
148+
:MPI_Win,
149+
]
150+
handle_f2c = Symbol(handle,:_f2c)
151+
handle_c2f = Symbol(handle,:_c2f)
152+
@eval begin
153+
if $handle == Cint
154+
$handle_f2c(fcomm::Cint) = fcomm
155+
$handle_c2f(comm::Cint) = comm
156+
else
157+
function $handle_f2c(fcomm::Cint)
158+
ccall(($(Meta.quot(handle_f2c)), libmpi), $handle, (Cint,), fcomm)
159+
end
160+
function $handle_c2f(comm::$handle)
161+
ccall(($(Meta.quot(handle_c2f)), libmpi), Cint, ($handle,), comm)
162+
end
163+
end
164+
end
165+
end
166+
138167
# since this is called by invokelatest, it isn't automatically precompiled
139168
precompile(init_consts, ())
140169

test/test_comm.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@ else
4242
@test splitcomm3 == MPI.COMM_NULL
4343
end
4444

45+
# Fortran conversion
46+
@test MPI.API.MPI_Comm_f2c(MPI.API.MPI_Comm_c2f(MPI.COMM_SELF.val)) == MPI.COMM_SELF.val
47+
4548
MPI.Finalize()
4649
@test MPI.Finalized()

0 commit comments

Comments
 (0)