diff --git a/config/ompi_setup_mpi_fortran.m4 b/config/ompi_setup_mpi_fortran.m4 index b06bd4823e..c38e0f6e29 100644 --- a/config/ompi_setup_mpi_fortran.m4 +++ b/config/ompi_setup_mpi_fortran.m4 @@ -284,6 +284,13 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[ OMPI_FORTRAN_USEMPI_LIB=-lmpi_usempi]) ]) + OMPI_FORTRAN_HAVE_ISO_C_BINDING=0 + AS_IF([test $OMPI_WANT_FORTRAN_USEMPI_BINDINGS -eq 1 && \ + test $ompi_fortran_happy -eq 1], + [OMPI_FORTRAN_CHECK_ISO_C_BINDING( + [OMPI_FORTRAN_HAVE_ISO_C_BINDING=1], + [OMPI_FORTRAN_HAVE_ISO_C_BINDING=0])]) + AC_MSG_CHECKING([if building Fortran 'use mpi' bindings]) AS_IF([test $OMPI_BUILD_FORTRAN_USEMPI_BINDINGS -eq 1], [AC_MSG_RESULT([yes])], @@ -309,14 +316,11 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[ # the necessary forms of BIND(C) OMPI_FORTRAN_HAVE_BIND_C=0 - OMPI_FORTRAN_HAVE_ISO_C_BINDING=0 AS_IF([test $OMPI_WANT_FORTRAN_USEMPIF08_BINDINGS -eq 1 -a \ $OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS -eq 1], [ # If we don't have ISO C bindings, we won't build mpi_f08 at all - OMPI_FORTRAN_CHECK_ISO_C_BINDING( - [OMPI_FORTRAN_HAVE_ISO_C_BINDING=1], - [OMPI_FORTRAN_HAVE_ISO_C_BINDING=0 - OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS=0])]) + AS_IF([test "$OMPI_FORTRAN_HAVE_ISO_C_BINDING" -eq 0], + [OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS=0])]) OMPI_FORTRAN_HAVE_BIND_C_SUB=0 AS_IF([test $OMPI_WANT_FORTRAN_USEMPIF08_BINDINGS -eq 1 -a \ @@ -628,6 +632,7 @@ end type test_mpi_handle], AC_DEFINE_UNQUOTED(OMPI_FORTRAN_HAVE_BIND_C, [$OMPI_FORTRAN_HAVE_BIND_C], [For ompi_info: Whether the compiler supports all forms of BIND(C) that we need]) + AC_SUBST(OMPI_FORTRAN_HAVE_ISO_C_BINDING) AC_DEFINE_UNQUOTED(OMPI_FORTRAN_HAVE_ISO_C_BINDING, [$OMPI_FORTRAN_HAVE_ISO_C_BINDING], [For ompi_info: Whether the compiler supports ISO_C_BINDING or not]) diff --git a/ompi/mpi/fortran/configure-fortran-output.h.in b/ompi/mpi/fortran/configure-fortran-output.h.in index 0cb88eb642..5ef9848cbc 100644 --- a/ompi/mpi/fortran/configure-fortran-output.h.in +++ b/ompi/mpi/fortran/configure-fortran-output.h.in @@ -35,6 +35,9 @@ ! Whether we have ASYNCHRONOUS or not #define OMPI_FORTRAN_HAVE_ASYNCHRONOUS @OMPI_FORTRAN_HAVE_ASYNCHRONOUS@ +! Whether we have ISO C binding or not +#define OMPI_FORTRAN_HAVE_ISO_C_BINDING @OMPI_FORTRAN_HAVE_ISO_C_BINDING@ + ! Whether we are building the MPI F08 bindings with subarray support or not #define OMPI_FORTRAN_SUBARRAYS_SUPPORTED @OMPI_FORTRAN_SUBARRAYS_SUPPORTED@ diff --git a/ompi/mpi/fortran/use-mpi-tkr/Makefile.am b/ompi/mpi/fortran/use-mpi-tkr/Makefile.am index dd1ca6ebf8..f36232d82e 100644 --- a/ompi/mpi/fortran/use-mpi-tkr/Makefile.am +++ b/ompi/mpi/fortran/use-mpi-tkr/Makefile.am @@ -30,8 +30,12 @@ if OMPI_BUILD_FORTRAN_USEMPI_TKR_BINDINGS ######################################################################## +# Note the "-I." in the flags below. This is because mpi.F90 includes +# mpi-f90-interfaces.h, which will be in the build tree (i.e., the +# current directory) because it is generated. + AM_FCFLAGS = -I$(top_builddir)/ompi/include -I$(top_srcdir)/ompi/include \ - $(OMPI_FC_MODULE_FLAG). -I$(srcdir) \ + $(OMPI_FC_MODULE_FLAG). -I$(srcdir) -I. \ -I$(top_builddir)/ompi/mpi/fortran/use-mpi-tkr $(FCFLAGS_f90) # Do different things if the top-level configure decided that we're @@ -48,12 +52,20 @@ lib_LTLIBRARIES += libmpi_usempi.la # list this here (i.e., "mpi-f90-interfaces.h" is included in # mpi.F90). -# Note the "-I." in the command below. This is because mpi.F90 -# includes mpi-f90-interfaces.h, which will be in the build tree -# (i.e., the current directory) because it is generated. +mpi.lo: mpi.F90 +mpi.lo: mpi-f90-interfaces.h +mpi.lo: $(top_builddir)/ompi/mpi/fortran/configure-fortran-output.h +mpi.lo: mpi-f90-cptr-interfaces.F90 -mpi.o: mpi.F90 mpi-f90-interfaces.h - $(FCCOMPILE) -c -I. -o $@ $(FCFLAGS_f90) $< +# These files must be EXTRA_DIST'ed because they are included; they +# are not compiled directly (and we *can't* list the .F90 file in +# _SOURCES, because it would be compiled -- but it *must* have a .F90 +# suffix so that the Fortran compiler will interpret the #if +# directives properly). + +EXTRA_DIST = \ + mpi-f90-interfaces.h \ + mpi-f90-cptr-interfaces.F90 endif @@ -64,7 +76,6 @@ endif libmpi_usempi_la_SOURCES = \ mpi.F90 \ - mpi-f90-interfaces.h \ mpi_comm_spawn_multiple_f90.f90 \ mpi_sizeof.f90 \ mpi_testall_f90.f90 \ diff --git a/ompi/mpi/fortran/use-mpi-tkr/mpi-f90-cptr-interfaces.F90 b/ompi/mpi/fortran/use-mpi-tkr/mpi-f90-cptr-interfaces.F90 new file mode 100644 index 0000000000..76f15fbd97 --- /dev/null +++ b/ompi/mpi/fortran/use-mpi-tkr/mpi-f90-cptr-interfaces.F90 @@ -0,0 +1,77 @@ +! -*- fortran -*- +! +! Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. +! $COPYRIGHT$ +! +! Additional copyrights may follow +! +! $HEADER$ +! +! This file contains interfaces that use the ISO_C_BINDING module and +! the TYPE(C_PTR) type, which not all Fortran compilers support (e.g., +! gfortran on RHEL 5 does not support this module/type). So we use a +! preprocessor macro to protect the problematic declarations. +! +! This file is included via a preprocessor include directorive in +! mpi.F90, which allows us to use the preprocessor "if" directive, +! below. +! + +interface MPI_Win_allocate_shared + +subroutine MPI_Win_allocate_shared(size, disp_unit, info, comm, & + baseptr, win, ierror) + include 'mpif-config.h' + integer(KIND=MPI_ADDRESS_KIND), intent(in) :: size + integer, intent(in) :: disp_unit + integer, intent(in) :: info + integer, intent(in) :: comm + integer(KIND=MPI_ADDRESS_KIND), intent(out) :: baseptr + integer, intent(out) :: win + integer, intent(out) :: ierror +end subroutine MPI_Win_allocate_shared + +! Only include the 2nd interface if we have ISO_C_BINDING / TYPE(C_PTR) +#if OMPI_FORTRAN_HAVE_ISO_C_BINDING +subroutine MPI_Win_allocate_shared_cptr(size, disp_unit, info, comm, & + baseptr, win, ierror) + use, intrinsic :: iso_c_binding, only : c_ptr + include 'mpif-config.h' + integer :: disp_unit, info, comm, win, ierror + integer(KIND=MPI_ADDRESS_KIND) :: size + type(C_PTR) :: baseptr +end subroutine MPI_Win_allocate_shared_cptr +#endif + +end interface + + +interface MPI_Win_shared_query + +subroutine MPI_Win_shared_query(win, rank, size, disp_unit, baseptr,& + ierror) + include 'mpif-config.h' + integer, intent(in) :: win + integer, intent(in) :: rank + integer(KIND=MPI_ADDRESS_KIND), intent(out) :: size + integer, intent(out) :: disp_unit + integer(KIND=MPI_ADDRESS_KIND), intent(out) :: baseptr + integer, intent(out) :: ierror +end subroutine MPI_Win_shared_query + +! Only include the 2nd interface if we have ISO_C_BINDING / TYPE(C_PTR) +#if OMPI_FORTRAN_HAVE_ISO_C_BINDING +subroutine MPI_Win_shared_query_cptr(win, rank, size, disp_unit, baseptr,& + ierror) + use, intrinsic :: iso_c_binding, only : c_ptr + include 'mpif-config.h' + integer, intent(in) :: win + integer, intent(in) :: rank + integer(KIND=MPI_ADDRESS_KIND), intent(out) :: size + integer, intent(out) :: disp_unit + type(C_PTR), intent(out) :: baseptr + integer, intent(out) :: ierror +end subroutine MPI_Win_shared_query_cptr +#endif + +end interface diff --git a/ompi/mpi/fortran/use-mpi-tkr/mpi-f90-interfaces.h b/ompi/mpi/fortran/use-mpi-tkr/mpi-f90-interfaces.h index 93b45370a3..4dccb4bf5f 100644 --- a/ompi/mpi/fortran/use-mpi-tkr/mpi-f90-interfaces.h +++ b/ompi/mpi/fortran/use-mpi-tkr/mpi-f90-interfaces.h @@ -2881,32 +2881,6 @@ end subroutine MPI_Waitsome end interface -interface MPI_Win_allocate_shared - -subroutine MPI_Win_allocate_shared(size, disp_unit, info, comm, & - baseptr, win, ierror) - include 'mpif-config.h' - integer(KIND=MPI_ADDRESS_KIND), intent(in) :: size - integer, intent(in) :: disp_unit - integer, intent(in) :: info - integer, intent(in) :: comm - integer(KIND=MPI_ADDRESS_KIND), intent(out) :: baseptr - integer, intent(out) :: win - integer, intent(out) :: ierror -end subroutine MPI_Win_allocate_shared - -subroutine MPI_Win_allocate_shared_cptr(size, disp_unit, info, comm, & - baseptr, win, ierror) - use, intrinsic :: iso_c_binding, only : c_ptr - include 'mpif-config.h' - integer :: disp_unit, info, comm, win, ierror - integer(KIND=MPI_ADDRESS_KIND) :: size - type(C_PTR) :: baseptr -end subroutine MPI_Win_allocate_shared_cptr - -end interface - - interface MPI_Win_call_errhandler subroutine MPI_Win_call_errhandler(win, errorcode, ierror) @@ -3103,34 +3077,6 @@ end subroutine MPI_Win_set_name end interface -interface MPI_Win_shared_query - -subroutine MPI_Win_shared_query(win, rank, size, disp_unit, baseptr,& - ierror) - include 'mpif-config.h' - integer, intent(in) :: win - integer, intent(in) :: rank - integer(KIND=MPI_ADDRESS_KIND), intent(out) :: size - integer, intent(out) :: disp_unit - integer(KIND=MPI_ADDRESS_KIND), intent(out) :: baseptr - integer, intent(out) :: ierror -end subroutine MPI_Win_shared_query - -subroutine MPI_Win_shared_query_cptr(win, rank, size, disp_unit, baseptr,& - ierror) - use, intrinsic :: iso_c_binding, only : c_ptr - include 'mpif-config.h' - integer, intent(in) :: win - integer, intent(in) :: rank - integer(KIND=MPI_ADDRESS_KIND), intent(out) :: size - integer, intent(out) :: disp_unit - type(C_PTR), intent(out) :: baseptr - integer, intent(out) :: ierror -end subroutine MPI_Win_shared_query_cptr - -end interface - - interface MPI_Win_start subroutine MPI_Win_start(group, assert, win, ierror) diff --git a/ompi/mpi/fortran/use-mpi-tkr/mpi.F90 b/ompi/mpi/fortran/use-mpi-tkr/mpi.F90 index b8e4b696b5..4d1feea154 100644 --- a/ompi/mpi/fortran/use-mpi-tkr/mpi.F90 +++ b/ompi/mpi/fortran/use-mpi-tkr/mpi.F90 @@ -39,6 +39,12 @@ module mpi include "ompi/mpi/fortran/base/conversion-fn-null-int-interface.h" +! Functions that have overloaded interfaces with TYPE(C_PTR) (which +! this compiler may or may not support). We use an "if" preprocessor +! macro in this file, so we need to use the preprocessor include +! directive, not the Fortran include. +#include "mpi-f90-cptr-interfaces.F90" + ! This file is generated, and is *huge*. Its size is directly related ! to the --with-f90-max-array-dim configure parameter.