How can I pass the pointer of MPI communicator to c function?

I have a c function that requires me to pass a comm pointer to the function

I converted the function using Clang.jl showed below

function Comm(comm_handle)
    ccall((:Comm, librarypath), Cint, (Ptr{Cvoid}),  comm_handle)
end

But I am getting an error if I pass MPI.MPI_COMM_WORLD to the function
MethodError: no method matching unsafe_convert(::Type{Ptr{Cvoid}}, ::MPI.Comm)

Did I pass the wrong communicator or a wrong type of pointer is declared?

Look at some examples in the MPI.jl code: you declare the argument as a Ptr{MPI.MPI_Comm}.

I submitted a pull request to add this to the MPI.jl docs: document how to pass MPI.Comm objects to C by stevengj · Pull Request #626 · JuliaParallel/MPI.jl · GitHub

2 Likes

Thanks for the information!
I can pass the pointer right now.