From b3b83cda50a24723f942fe27a18bd9aad56dac49 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Sun, 5 Nov 2023 22:12:38 -0800 Subject: [PATCH] add c2f/f2c handle conversions (#798) --- src/api/api.jl | 29 +++++++++++++++++++++++++++++ test/test_comm.jl | 3 +++ 2 files changed, 32 insertions(+) diff --git a/src/api/api.jl b/src/api/api.jl index af5822857..b46701c5b 100644 --- a/src/api/api.jl +++ b/src/api/api.jl @@ -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, ()) diff --git a/test/test_comm.jl b/test/test_comm.jl index 1d0db03ed..20e8a4a15 100644 --- a/test/test_comm.jl +++ b/test/test_comm.jl @@ -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()