Ah, sorry -- I didn't read your first post carefully. I would go with Gilles' suggestion: write trivial versions of MPI_Init / MPI_Finalize in Fortran, and then have them call your back-end C function to do whatever it is you want the intercepts to do. This will keep you out of all the portability-between-different-Fortran-compiler issues.
Writing MPI_Init / MPI_Finalize in Fortran is also *necessary* for at least some implementations of the mpi module, and will likely be necessary for *all* implementations of the mpi_f08 module. E.g. subroutine MPI_Init_f08(ierror) use my_mpi_routine_module implicit none INTEGER, OPTIONAL, INTENT(OUT) :: ierror integer :: c_ierror call my_mpi_init_routine(c_ierror) if (present(ierror)) ierror = c_ierror end subroutine MPI_Init_f08 In my_mpi_routine_module, you prototype your C routines something like this: subroutine my_mpi_init_routine(ierror) & BIND(C, name="my_mpi_init_routine_in_c") implicit none INTEGER, INTENT(OUT) :: ierror end subroutine my_mpi_init_routine Which means that you have a C function somewhere named my_mpi_init_routine_in_c: void my_mpi_init_routine_in_c(int *ierror) { // Do whatever you do in C } > On Dec 12, 2016, at 10:42 AM, Clement FOYER <clement.fo...@gmail.com> wrote: > > Thank you all for your answers. > > I stayed with the C version, with the FORTRAN symbols added as it worked with > the tests I was willing to start. Nevertheless, in order to keep a more > proper/portable solution, is it possible to use the same tools as in > ompi/mpi/fortran/mpif-h/init_f.c in order to generate the mangled symbols > (i.e. using #pragma weak or OMPI_GENERATE_F77_BINDINGS ) ? > > Thank you. > > Clément FOYER > > > On 12/12/2016 04:21 PM, Jeff Squyres (jsquyres) wrote: >> If your Fortran compiler is new enough (and it *probably* is...?), you can >> use the BIND(C) notation to ease C / Fortran interoperability issues. >> >> >>> On Dec 12, 2016, at 5:37 AM, Gilles Gouaillardet >>> <gilles.gouaillar...@gmail.com> wrote: >>> >>> Clement, >>> >>> Ideally, your LD_PRELOAD'able library should be written in Fortran so you >>> do not even run into this kind of issues (name mangling + parameter types) >>> >>> If you really want to write it in C, you have to do it all manually >>> >>> SUBROUTINE MPI_INIT(ierror) >>> INTEGER IERROR >>> >>> can become >>> >>> void mpi_init_(MPI_Fint * ierror) >>> >>> Note mangling is compiler dependent. >>> For most compilers, this is the function name with all lower cases, >>> followed by one or two underscores. >>> >>> You will also have to convert all parameters >>> INTEGER comm >>> will be replaced (modulo the typos) with >>> MPI_Comm c_comm; >>> MPI_Fint *comm; >>> c_comm = MPI_Comm_f2c(*comm); >>> >>> And so on, that is why Fortran wrapper is preferred, >>> plus there might be over caveats with Fortean 2008 >>> >>> Cheers, >>> >>> Gilles >>> >>> On Monday, December 12, 2016, Clement FOYER <clement.fo...@gmail.com> wrote: >>> Hello everyone, >>> >>> I have been trying to redirect MPI_Init and MPI_Finalize calls from a >>> FORTRAN application (the CG benchmark from NAS Parallel Benchmarks). It >>> appears that in the fortran application the MPI_Init function signature is >>> "mpi_init_", whereas in my shared object it is MPI_Init. How is the f-to-c >>> binding done in Open-MPI? How can I change the Makefile.am (or add a >>> configure.m4) in order to check the way this name mapping is done by the >>> compiler, and how to add the proper symbols so that my shared object could >>> be used also with FORTRAN programs ? >>> >>> Thank you in advance, >>> >>> Clément FOYER >>> >>> _______________________________________________ >>> devel mailing list >>> devel@lists.open-mpi.org >>> https://rfd.newmexicoconsortium.org/mailman/listinfo/devel >>> _______________________________________________ >>> devel mailing list >>> devel@lists.open-mpi.org >>> https://rfd.newmexicoconsortium.org/mailman/listinfo/devel >> > > _______________________________________________ > devel mailing list > devel@lists.open-mpi.org > https://rfd.newmexicoconsortium.org/mailman/listinfo/devel -- Jeff Squyres jsquy...@cisco.com For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/ _______________________________________________ devel mailing list devel@lists.open-mpi.org https://rfd.newmexicoconsortium.org/mailman/listinfo/devel