From 08d2a1a48d319e13771bb72131919911fbdc58d4 Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Tue, 15 Jul 2014 10:41:11 +0000 Subject: [PATCH] fortran: fix compile issue with ABSoft compilers ABSoft compilers cannot compile a fortran subroutine with the BIND(C, NAME="name") modifier *and* argument(s) with the OPTIONAL modifier This patch detects this unsupported feature and use adhoc wrappers if it is missing cmr=v1.8.2:reviewer=jsquyres This commit was SVN r32246. --- ...fortran_check_bind_c_with_optional_args.m4 | 101 ++++++++++++++++++ config/ompi_setup_mpi_fortran.m4 | 20 ++++ .../mpi/fortran/configure-fortran-output.h.in | 5 + .../use-mpi-f08/mpi-f-interfaces-bind.h | 17 +++ ompi/mpi/fortran/use-mpi-f08/mpi-f08.F90 | 66 ++++++++++++ .../use-mpi-f08/pmpi-f-interfaces-bind.h | 16 +++ 6 files changed, 225 insertions(+) create mode 100644 config/ompi_fortran_check_bind_c_with_optional_args.m4 diff --git a/config/ompi_fortran_check_bind_c_with_optional_args.m4 b/config/ompi_fortran_check_bind_c_with_optional_args.m4 new file mode 100644 index 0000000000..7b5c94ecff --- /dev/null +++ b/config/ompi_fortran_check_bind_c_with_optional_args.m4 @@ -0,0 +1,101 @@ +dnl -*- shell-script -*- +dnl +dnl Copyright (c) 2014 Research Organization for Information Science +dnl and Technology (RIST). All rights reserved. +dnl $COPYRIGHT$ +dnl +dnl Additional copyrights may follow +dnl +dnl $HEADER$ +dnl + +# Check whether or not the Fortran compiler supports subroutines with +# the BIND(C, NAME="name") parameter and optional arguments or not, +# and we (generally) don't need wrapper subroutines. + +# OMPI_FORTRAN_CHECK_BIND_C_WITH_OPTIONAL_ARGS([action if found], +# [action if not found]) +# ---------------------------------------------------- +AC_DEFUN([OMPI_FORTRAN_CHECK_BIND_C_WITH_OPTIONAL_ARGS],[ + unset happy + OPAL_VAR_SCOPE_PUSH([happy ompi_conftest_h]) + + AC_CACHE_CHECK( + [if Fortran compiler supports BIND(C, NAME="name") subroutine with optional arguments], + [ompi_cv_fortran_bind_c_with_optional_args], + [ompi_cv_fortran_bind_c_with_optional_args=no + cat > conftestf.f90 < conftest.c < +#include +$ompi_conftest_h + +#ifdef __cplusplus +extern "C" { +#endif +void check_op(int, int *); + +void check_op(int has_op, int *ierror) +{ + /* Force a segv if the conditions are wrong */ + char *bogus = 0; + if (0 == has_op) { + /* won't have optional argument */ + if (NULL != ierror) *bogus= 13; + } else { + /* will have optional argument */ + if (NULL == ierror) *bogus= 13; + *ierror = 33; + } +} +#ifdef __cplusplus +} +#endif +EOF + + OPAL_LOG_COMMAND([$CC $CFLAGS -I. -c conftest.c], + [OPAL_LOG_COMMAND([$FC $FCFLAGS conftestf.f90 conftest.o -o conftest $LDFLAGS $LIBS], + [happy="yes"], [happy="no"])], + [happy="c_fail"]) + + AS_IF([test "$happy" = "c_fail"], + [AC_MSG_RESULT([error]) + AC_MSG_ERROR([This error should not happen -- contact the Open MPI developers]) + ]) + + AS_IF([test "$cross_compiling" = "yes"], + [AC_MSG_RESULT([cross-compiling]) + AC_MSG_ERROR([Cannot determine if Fortran compiler supports optional arguments when cross-compiling])], + [OPAL_LOG_COMMAND([./conftest], + [ompi_cv_fortran_bind_c_with_optional_args=yes]) + ]) + rm -f conftest* + ])dnl + + AS_VAR_COPY([happy], [ompi_cv_fortran_bind_c_with_optional_args]) + AS_IF([test "$happy" = "yes"], [$1], [$2]) + OPAL_VAR_SCOPE_POP +]) diff --git a/config/ompi_setup_mpi_fortran.m4 b/config/ompi_setup_mpi_fortran.m4 index c38e0f6e29..0add7b45a4 100644 --- a/config/ompi_setup_mpi_fortran.m4 +++ b/config/ompi_setup_mpi_fortran.m4 @@ -15,6 +15,8 @@ # Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights # reserved. # Copyright (c) 2009 Oak Ridge National Labs. All rights reserved. +# Copyright (c) 2014 Research Organization for Information Science +# and Technology (RIST). All rights reserved. # $COPYRIGHT$ # # Additional copyrights may follow @@ -36,6 +38,7 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[ OMPI_FORTRAN_HAVE_IGNORE_TKR=0 OMPI_FORTRAN_HAVE_OPTIONAL_ARGS=0 + OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS=0 OMPI_FORTRAN_HAVE_BIND_C=0 OMPI_FORTRAN_HAVE_ISO_C_BINDING=0 OMPI_FORTRAN_HAVE_BIND_C_SUB=0 @@ -385,6 +388,16 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[ [OMPI_FORTRAN_HAVE_OPTIONAL_ARGS=0 OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS=0])]) + OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS=0 + AS_IF([test $OMPI_WANT_FORTRAN_USEMPIF08_BINDINGS -eq 1 -a \ + $OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS -eq 1 -a \ + $OMPI_FORTRAN_HAVE_BIND_C_TYPE_NAME -eq 1 -a \ + $OMPI_FORTRAN_HAVE_OPTIONAL_ARGS -eq 1], + [ # Does the compiler have optional arguments? + OMPI_FORTRAN_CHECK_BIND_C_WITH_OPTIONAL_ARGS( + [OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS=1], + [OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS=0])]) + OMPI_FORTRAN_HAVE_PRIVATE=0 AS_IF([test $OMPI_WANT_FORTRAN_USEMPIF08_BINDINGS -eq 1 -a \ $OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS -eq 1], @@ -648,6 +661,9 @@ end type test_mpi_handle], AC_DEFINE_UNQUOTED([OMPI_FORTRAN_HAVE_OPTIONAL_ARGS], [$OMPI_FORTRAN_HAVE_OPTIONAL_ARGS], [For ompi_info: whether the Fortran compiler supports optional arguments or not]) + AC_DEFINE_UNQUOTED([OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS], + [$OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS], + [For ompi_info: whether the Fortran compiler supports BIND(C, NAME="name") subroutine with optional arguments or not]) # For configure-fortran-output.h, mpi-f08-types.F90 (and ompi_info) AC_SUBST([OMPI_FORTRAN_HAVE_PRIVATE]) @@ -684,6 +700,10 @@ end type test_mpi_handle], # For configure-fortran-output.h AC_SUBST(OMPI_FORTRAN_HAVE_BIND_C) + + # For configure-fortran-output.h, various files in + # ompi/mpi/fortran/use-mpi-f08/*.F90 and *.h files (and ompi_info) + AC_SUBST(OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS) # Somewhat redundant because ompi/Makefile.am won't traverse into # ompi/mpi/fortran/use-mpi-f08 if it's not to be built, but we diff --git a/ompi/mpi/fortran/configure-fortran-output.h.in b/ompi/mpi/fortran/configure-fortran-output.h.in index 5ef9848cbc..b2e71bec4f 100644 --- a/ompi/mpi/fortran/configure-fortran-output.h.in +++ b/ompi/mpi/fortran/configure-fortran-output.h.in @@ -3,6 +3,8 @@ ! Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved. ! Copyright (c) 2009-2012 Los Alamos National Security, LLC. ! All rights reserved. +! Copyright (c) 2014 Research Organization for Information Science +! and Technology (RIST). All rights reserved. ! ! $COPYRIGHT$ ! @@ -41,6 +43,9 @@ ! Whether we are building the MPI F08 bindings with subarray support or not #define OMPI_FORTRAN_SUBARRAYS_SUPPORTED @OMPI_FORTRAN_SUBARRAYS_SUPPORTED@ +! Whether we have BIND(C, NAME="name") subroutine with optional parameters or not +#define OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS @OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS@ + ! Line 1 of the ignore TKR syntax ! ...JMS not figured out yet... diff --git a/ompi/mpi/fortran/use-mpi-f08/mpi-f-interfaces-bind.h b/ompi/mpi/fortran/use-mpi-f08/mpi-f-interfaces-bind.h index ab06fb5d61..0a461558bc 100644 --- a/ompi/mpi/fortran/use-mpi-f08/mpi-f-interfaces-bind.h +++ b/ompi/mpi/fortran/use-mpi-f08/mpi-f-interfaces-bind.h @@ -7,6 +7,8 @@ ! of Tennessee Research Foundation. All rights ! reserved. ! Copyright (c) 2012 Inria. All rights reserved. +! Copyright (c) 2014 Research Organization for Information Science +! and Technology (RIST). All rights reserved. ! $COPYRIGHT$ ! ! This file provides the interface specifications for the MPI Fortran @@ -2426,6 +2428,7 @@ subroutine ompi_win_post_f(group,assert,win,ierror) & INTEGER, INTENT(OUT) :: ierror end subroutine ompi_win_post_f +#if OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS subroutine ompi_win_shared_query_f(win, rank, size, disp_unit, baseptr,& ierror) BIND(C, name="ompi_win_shared_query_f") USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR @@ -2437,6 +2440,20 @@ subroutine ompi_win_shared_query_f(win, rank, size, disp_unit, baseptr,& TYPE(C_PTR), INTENT(OUT) :: baseptr INTEGER, OPTIONAL, INTENT(OUT) :: ierror end subroutine ompi_win_shared_query_f +#else +subroutine ompi_win_shared_query_f(win, rank, size, disp_unit, baseptr,& + ierror) + USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR + use :: mpi_f08_types, only : MPI_ADDRESS_KIND + implicit none + 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, OPTIONAL, INTENT(OUT) :: ierror +end subroutine ompi_win_shared_query_f +#endif subroutine ompi_win_start_f(group,assert,win,ierror) & BIND(C, name="ompi_win_start_f") diff --git a/ompi/mpi/fortran/use-mpi-f08/mpi-f08.F90 b/ompi/mpi/fortran/use-mpi-f08/mpi-f08.F90 index 3277d41878..17682b823c 100644 --- a/ompi/mpi/fortran/use-mpi-f08/mpi-f08.F90 +++ b/ompi/mpi/fortran/use-mpi-f08/mpi-f08.F90 @@ -13,6 +13,8 @@ ! Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved. ! Copyright (c) 2009-2012 Los Alamos National Security, LLC. ! All rights reserved. +! Copyright (c) 2014 Research Organization for Information Science +! and Technology (RIST). All rights reserved. ! $COPYRIGHT$ ! ! Additional copyrights may follow @@ -45,3 +47,67 @@ module mpi_f08 include "conversion-fn-null-f08-interface.h" end module mpi_f08 + +#if ! OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS +subroutine ompi_win_shared_query_f_with_ierror(win, rank, size, disp_unit, baseptr,& + ierror) BIND(C, name="ompi_win_shared_query_f") + USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR + use :: mpi_f08_types, only : MPI_ADDRESS_KIND + 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 ompi_win_shared_query_f_with_ierror + +subroutine ompi_win_shared_query_f(win, rank, size, disp_unit, baseptr,& + ierror) + USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR + use :: mpi_f08_types, only : MPI_ADDRESS_KIND + implicit none + 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, OPTIONAL, INTENT(OUT) :: ierror + INTEGER :: ilerror + if (PRESENT(ierror)) then + call ompi_win_shared_query_f_with_ierror(win, rank, size, disp_unit, baseptr, ierror) + else + call ompi_win_shared_query_f_with_ierror(win, rank, size, disp_unit, baseptr, ilerror) + endif +end subroutine ompi_win_shared_query_f + +subroutine pompi_win_shared_query_f_with_ierror(win, rank, size, disp_unit, baseptr,& + ierror) BIND(C, name="pompi_win_shared_query_f") + USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR + use :: mpi_f08_types, only : MPI_ADDRESS_KIND + 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 pompi_win_shared_query_f_with_ierror + +subroutine pompi_win_shared_query_f(win, rank, size, disp_unit, baseptr,& + ierror) + USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR + use :: mpi_f08_types, only : MPI_ADDRESS_KIND + implicit none + 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, OPTIONAL, INTENT(OUT) :: ierror + INTEGER :: ilerror + if (PRESENT(ierror)) then + call pompi_win_shared_query_f_with_ierror(win, rank, size, disp_unit, baseptr, ierror) + else + call pompi_win_shared_query_f_with_ierror(win, rank, size, disp_unit, baseptr, ilerror) + endif +end subroutine pompi_win_shared_query_f +#endif diff --git a/ompi/mpi/fortran/use-mpi-f08/pmpi-f-interfaces-bind.h b/ompi/mpi/fortran/use-mpi-f08/pmpi-f-interfaces-bind.h index 2dd5cbd5ff..c12c120114 100644 --- a/ompi/mpi/fortran/use-mpi-f08/pmpi-f-interfaces-bind.h +++ b/ompi/mpi/fortran/use-mpi-f08/pmpi-f-interfaces-bind.h @@ -7,6 +7,8 @@ ! of Tennessee Research Foundation. All rights ! reserved. ! Copyright (c) 2012 Inria. All rights reserved. +! Copyright (c) 2014 Research Organization for Information Science +! and Technology (RIST). All rights reserved. ! $COPYRIGHT$ ! ! This file provides the interface specifications for the MPI Fortran @@ -2263,6 +2265,7 @@ subroutine pompi_win_post_f(group,assert,win,ierror) & INTEGER, INTENT(OUT) :: ierror end subroutine pompi_win_post_f +#if OMPI_FORTRAN_HAVE_BIND_C_WITH_OPTIONAL_ARGS subroutine pompi_win_shared_query_f(win, rank, size, disp_unit, baseptr,& ierror) BIND(C, name="ompi_win_shared_query_f") USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR @@ -2274,6 +2277,19 @@ subroutine pompi_win_shared_query_f(win, rank, size, disp_unit, baseptr,& TYPE(C_PTR), INTENT(OUT) :: baseptr INTEGER, OPTIONAL, INTENT(OUT) :: ierror end subroutine pompi_win_shared_query_f +#else +subroutine pompi_win_shared_query_f(win, rank, size, disp_unit, baseptr,& + ierror) + USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR + use :: mpi_f08_types, only : MPI_ADDRESS_KIND + 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, OPTIONAL, INTENT(OUT) :: ierror +end subroutine pompi_win_shared_query_f +#endif subroutine pompi_win_start_f(group,assert,win,ierror) & BIND(C, name="pompi_win_start_f")