[MPIWG Fortran] BIND(C) attribute of MPI callback functions

Junchao Zhang jczhang at mcs.anl.gov
Tue Jul 1 14:00:54 CDT 2014

  Errata for MPI-3.0 removed the BIND(C) attribute of MPI callback
functions. But in an implementation, to pass the Fortran procedure to the
backend C, I need to get its C function pointer with c_funloc, as the
following code shows. When I compile it with IBM XLF 15.1, it complains
with such an error "1516-203 (S) The argument to the intrinsic procedure
C_FUNLOC must be a procedure with the BIND(C) attribute." In my
experiments, gcc and Cray ftn are fine with it.  Looking at
https://gcc.gnu.org/onlinedocs/gfortran/C_005fFUNLOC.html, I find c_funloc
indeed requires an interoperable function argument. Any comments?

subroutine MPI_Comm_create_errhandler_f08(comm_errhandler_fn, errhandler,
    use, intrinsic :: iso_c_binding, only : c_funloc, c_int, c_funptr
    use :: mpi_f08, only : MPI_Errhandler, MPI_Comm_errhandler_function
    use :: mpi_c_interface, only : c_Errhandler,

    implicit none

    procedure(MPI_Comm_errhandler_function) :: comm_errhandler_fn
    type(MPI_Errhandler), intent(out) :: errhandler
    integer, optional, intent(out) :: ierror

    type(c_funptr) :: comm_errhandler_fn_c

    comm_errhandler_fn_c = c_funloc(comm_errhandler_fn) !! xlf issues an
    ierror_c = MPIR_Comm_create_errhandler_c(comm_errhandler_fn_c,
end subroutine MPI_Comm_create_errhandler_f08

--Junchao Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpi-forum.org/pipermail/mpiwg-fortran/attachments/20140701/74829ee4/attachment.html>

More information about the mpiwg-fortran mailing list