Skip to content

Commit

Permalink
add c2f/f2c handle conversions (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne authored Nov 6, 2023
1 parent 23a03e5 commit b3b83cd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/api/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,35 @@ end

include("generated_api.jl")

for handle in [
:MPI_Comm,
:MPI_Datatype,
:MPI_Errhandler,
:MPI_File,
:MPI_Group,
:MPI_Info,
:MPI_Message,
:MPI_Op,
:MPI_Request,
:MPI_Win,
]
handle_f2c = Symbol(handle,:_f2c)
handle_c2f = Symbol(handle,:_c2f)
@eval begin
if $handle == Cint
$handle_f2c(fcomm::Cint) = fcomm
$handle_c2f(comm::Cint) = comm
else
function $handle_f2c(fcomm::Cint)
ccall(($(Meta.quot(handle_f2c)), libmpi), $handle, (Cint,), fcomm)
end
function $handle_c2f(comm::$handle)
ccall(($(Meta.quot(handle_c2f)), libmpi), Cint, ($handle,), comm)
end
end
end
end

# since this is called by invokelatest, it isn't automatically precompiled
precompile(init_consts, ())

Expand Down
3 changes: 3 additions & 0 deletions test/test_comm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ else
@test splitcomm3 == MPI.COMM_NULL
end

# Fortran conversion
@test MPI.API.MPI_Comm_f2c(MPI.API.MPI_Comm_c2f(MPI.COMM_SELF.val)) == MPI.COMM_SELF.val

MPI.Finalize()
@test MPI.Finalized()

0 comments on commit b3b83cd

Please sign in to comment.