Skip to content

fortran/use-mpi-f08: add support for Fortran 2018 ISO_Fortran_binding.h #6569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions config/ompi_config_files.m4
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- shell-script -*-
#
# Copyright (c) 2009-2017 Cisco Systems, Inc. All rights reserved
# Copyright (c) 2017-2018 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2017-2019 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2018 Los Alamos National Security, LLC. All rights
# reserved.
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
Expand Down Expand Up @@ -39,6 +39,7 @@ AC_DEFUN([OMPI_CONFIG_FILES],[
ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr-removed-interfaces.h
ompi/mpi/fortran/use-mpi-f08/Makefile
ompi/mpi/fortran/use-mpi-f08/bindings/Makefile
ompi/mpi/fortran/use-mpi-f08/cdesc/Makefile
ompi/mpi/fortran/use-mpi-f08/mod/Makefile
ompi/mpi/fortran/mpiext-use-mpi/Makefile
ompi/mpi/fortran/mpiext-use-mpi-f08/Makefile
Expand Down
69 changes: 69 additions & 0 deletions config/ompi_fortran_check_bind_fortran.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
dnl -*- shell-script -*-
dnl
dnl Copyright (c) 2019 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 C compiler supports ISO_Fortran_binding.h
# Also check whether C and Fortran compiler interoperate.
#
# OMPI_FORTRAN_CHECK_ISO_FORTRAN_BINDING([action if found], [action if not found])
# ----------------------------------------------------
AC_DEFUN([OMPI_FORTRAN_CHECK_ISO_FORTRAN_BINDING],[
AS_VAR_PUSHDEF([iso_fortran_binding_var], [ompi_cv_fortran_have_iso_fortran_binding])

AC_CHECK_HEADERS([ISO_Fortran_binding.h],
[AC_CACHE_CHECK([if Fortran and C compilers support ISO_Fortran_binding.h], iso_fortran_binding_var,
[mkdir conftest.$$
cd conftest.$$

# Try to compile the C bindings
cat > conftest_c.c << EOF
#include <ISO_Fortran_binding.h>

int is_contiguous_c(CFI_cdesc_t* x) {
return CFI_is_contiguous(x);
}
EOF
OPAL_LOG_COMMAND([$CC $CCFLAGS -c conftest_c.c],
[cat > conftest.f90 << EOF
module MOD_IS_CONTIGUOUS

interface

function is_contiguous(buf) BIND(C, name="is_contiguous_c")
implicit none
type(*), dimension(..) :: buf
integer :: is_contiguous
end function is_contiguous

end interface

end module

program test_is_contiguous
use MOD_IS_CONTIGUOUS
implicit none
integer :: a0, a1(2), a2(2,2), a3(2,2,2)
write (*,*) is_contiguous(a0)
write (*,*) is_contiguous(a1)
write (*,*) is_contiguous(a2)
write (*,*) is_contiguous(a3)
end program
EOF
OPAL_LOG_COMMAND([$FC $FCFLAGS $FCFLAGS_f90 -o conftest conftest.f90 conftest_c.o $LDFLAGS $LIBS],
[AS_VAR_SET(iso_fortran_binding_var, yes)],
[AS_VAR_SET(iso_fortran_binding_var, no)])],
[AS_VAR_SET(iso_fortran_binding_var, no)])
cd ..
rm -rf conftest.$$])],
[AS_VAR_SET(iso_fortran_binding_var, no)])

AS_VAR_IF(iso_fortran_binding_var, [yes], [$1], [$2])
AS_VAR_POPDEF([iso_fortran_binding_var])dnl
])
26 changes: 24 additions & 2 deletions config/ompi_setup_mpi_fortran.m4
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ dnl Copyright (c) 2006-2008 Sun Microsystems, Inc. All rights reserved.
dnl Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights
dnl reserved.
dnl Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
dnl Copyright (c) 2014-2017 Research Organization for Information Science
dnl and Technology (RIST). All rights reserved.
dnl Copyright (c) 2014-2019 Research Organization for Information Science
dnl and Technology (RIST). All rights reserved.
dnl Copyright (c) 2016 IBM Corporation. All rights reserved.
dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
dnl $COPYRIGHT$
Expand Down Expand Up @@ -558,6 +558,12 @@ end type test_mpi_handle],
])
])

OMPI_FORTRAN_HAVE_C_ISO_FORTRAN=0
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
test $OMPI_BUILD_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
[OMPI_FORTRAN_CHECK_ISO_FORTRAN_BINDING([OMPI_FORTRAN_HAVE_C_ISO_FORTRAN=1],
[OMPI_FORTRAN_HAVE_C_ISO_FORTRAN=0])])

# Note: the current implementation *only* has wrappers;
# there is no optimized implementation for a "good"
# compiler. I'm leaving the above logic in place for
Expand All @@ -580,6 +586,8 @@ end type test_mpi_handle],
AS_IF([test $OMPI_MIN_REQUIRED_FORTRAN_BINDINGS -gt $OMPI_BUILD_FORTRAN_BINDINGS],
[AC_MSG_ERROR([Cannot build requested Fortran bindings, aborting])])

AC_CONFIG_FILES([ompi/mpi/fortran/use-mpi-f08/bindings/mpi-f-interfaces-bind.h])

# -------------------
# mpif.h final setup
# -------------------
Expand Down Expand Up @@ -798,6 +806,20 @@ end type test_mpi_handle],
# For configure-fortran-output.h
AC_SUBST(OMPI_FORTRAN_HAVE_BIND_C)

AM_CONDITIONAL(OMPI_FORTRAN_HAVE_C_ISO_FORTRAN,
[test $OMPI_FORTRAN_HAVE_C_ISO_FORTRAN -eq 1])

AS_IF([test $OMPI_FORTRAN_HAVE_C_ISO_FORTRAN -eq 1],
[OMPI_F08_IGNORE_TKR_TYPE="type(*), dimension(..)"
OMPI_F08_GCC_ATTRIBUTES=
OMPI_F08_BINDINGS_EXTENSION="cdesc"],
[OMPI_F08_IGNORE_TKR_TYPE=$OMPI_FORTRAN_IGNORE_TKR_TYPE
OMPI_F08_GCC_ATTRIBUTES='!GCC$ ATTRIBUTES NO_ARG_CHECK :: buf'
OMPI_F08_BINDINGS_EXTENSION="f"])
AC_SUBST(OMPI_F08_IGNORE_TKR_TYPE)
AC_SUBST(OMPI_F08_GCC_ATTRIBUTES)
AC_SUBST(OMPI_F08_BINDINGS_EXTENSION)

# 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
# might as well have ompi/mpi/fortran/use-mpi-f08/Makefile.am be
Expand Down
6 changes: 4 additions & 2 deletions ompi/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights
# reserved.
# Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
# Copyright (c) 2015-2018 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2015-2019 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2016 IBM Corporation. All rights reserved.
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
# $COPYRIGHT$
Expand Down Expand Up @@ -94,6 +94,7 @@ SUBDIRS = \
mpi/fortran/mpiext-use-mpi \
mpi/fortran/use-mpi-f08/mod \
mpi/fortran/use-mpi-f08/bindings \
mpi/fortran/use-mpi-f08/cdesc \
$(OMPI_MPIEXT_USEMPIF08_DIRS) \
mpi/fortran/use-mpi-f08 \
mpi/fortran/mpiext-use-mpi-f08 \
Expand Down Expand Up @@ -126,6 +127,7 @@ DIST_SUBDIRS = \
mpi/fortran/use-mpi-f08 \
mpi/fortran/use-mpi-f08/mod \
mpi/fortran/use-mpi-f08/bindings \
mpi/fortran/use-mpi-f08/cdesc \
mpi/fortran/mpiext-use-mpi-f08 \
mpi/java \
$(OMPI_MPIEXT_ALL_SUBDIRS) \
Expand Down
15 changes: 13 additions & 2 deletions ompi/mpi/fortran/configure-fortran-output.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +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) 2017-2018 Research Organization for Information Science
! and Technology (RIST). All rights reserved.
! Copyright (c) 2017-2019 Research Organization for Information Science
! and Technology (RIST). All rights reserved.
!
! $COPYRIGHT$
!
Expand Down Expand Up @@ -46,6 +46,17 @@
! Line 2 of the ignore TKR syntax
#define OMPI_FORTRAN_IGNORE_TKR_TYPE @OMPI_FORTRAN_IGNORE_TKR_TYPE@

! C ISO Fortran type is 'type(*), dimension(..)'
! but existing ignore_tkr type is $OMPI_FORTRAN_IGNORE_TKR_TYPE
#define OMPI_F08_IGNORE_TKR_TYPE @OMPI_F08_IGNORE_TKR_TYPE@

! C ISO Fortran bindings have the _cdesc extension
! but existing Fortran bindings have the _f C bindings
#define OMPI_F08_BINDINGS_EXTENSION @OMPI_F08_BINDINGS_EXTENSION@

! ignore_tkr require the '!GCC$ ATTRIBUTES NO_ARG_CHECK :: buf' attribute
! but the C ISO Fortran cannot have that attribute
#define OMPI_F08_GCC_ATTRIBUTES(buf) @OMPI_F08_GCC_ATTRIBUTES@

#define OMPI_FORTRAN_BUILD_SIZEOF @OMPI_FORTRAN_BUILD_SIZEOF@
! Integers
Expand Down
10 changes: 8 additions & 2 deletions ompi/mpi/fortran/use-mpi-f08/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# Copyright (c) 2012-2013 Inria. All rights reserved.
# Copyright (c) 2013-2018 Los Alamos National Security, LLC. All rights
# reserved.
# Copyright (c) 2015-2018 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2015-2019 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2016 IBM Corporation. All rights reserved.
# Copyright (c) 2017-2018 FUJITSU LIMITED. All rights reserved.
# Copyright (c) 2019 Triad National Security, LLC. All rights
Expand All @@ -32,6 +32,7 @@ AM_FCFLAGS = -I$(top_builddir)/ompi/include \
$(OMPI_FC_MODULE_FLAG)$(top_builddir)/ompi/$(OMPI_FORTRAN_USEMPI_DIR) \
$(OMPI_FC_MODULE_FLAG)mod \
$(OMPI_FC_MODULE_FLAG)bindings \
$(OMPI_FC_MODULE_FLAG)cdesc \
-I$(top_srcdir) $(FCFLAGS_f90)

MOSTLYCLEANFILES = *.mod
Expand All @@ -44,6 +45,11 @@ module_sentinel_file = \
mod/libforce_usempif08_internal_modules_to_be_built.la \
bindings/libforce_usempif08_internal_bindings_to_be_built.la

if OMPI_FORTRAN_HAVE_C_ISO_FORTRAN
module_sentinel_file += \
cdesc/libusempif08_cdesc.la
endif

mpi-f08.lo: $(module_sentinel_file)
mpi-f08.lo: mpi-f08.F90
mpi-f08.lo: sizeof_f08.h
Expand Down
6 changes: 3 additions & 3 deletions ompi/mpi/fortran/use-mpi-f08/allgather_f08.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved.
! Copyright (c) 2009-2012 Los Alamos National Security, LLC.
! All rights reserved.
! Copyright (c) 2018 Research Organization for Information Science
! Copyright (c) 2018-2019 Research Organization for Information Science
! and Technology (RIST). All rights reserved.
! $COPYRIGHT$

Expand All @@ -13,8 +13,8 @@ subroutine MPI_Allgather_f08(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvty
use :: mpi_f08_types, only : MPI_Datatype, MPI_Comm
use :: ompi_mpifh_bindings, only : ompi_allgather_f
implicit none
OMPI_FORTRAN_IGNORE_TKR_TYPE, INTENT(IN) :: sendbuf
OMPI_FORTRAN_IGNORE_TKR_TYPE :: recvbuf
OMPI_F08_IGNORE_TKR_TYPE, INTENT(IN) :: sendbuf
OMPI_F08_IGNORE_TKR_TYPE :: recvbuf
INTEGER, INTENT(IN) :: sendcount, recvcount
TYPE(MPI_Datatype), INTENT(IN) :: sendtype
TYPE(MPI_Datatype), INTENT(IN) :: recvtype
Expand Down
6 changes: 3 additions & 3 deletions ompi/mpi/fortran/use-mpi-f08/allgatherv_f08.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved.
! Copyright (c) 2009-2012 Los Alamos National Security, LLC.
! All rights reserved.
! Copyright (c) 2018 Research Organization for Information Science
! Copyright (c) 2018-2019 Research Organization for Information Science
! and Technology (RIST). All rights reserved.
! $COPYRIGHT$

Expand All @@ -14,8 +14,8 @@ subroutine MPI_Allgatherv_f08(sendbuf,sendcount,sendtype,recvbuf,recvcounts,&
use :: mpi_f08_types, only : MPI_Datatype, MPI_Comm
use :: ompi_mpifh_bindings, only : ompi_allgatherv_f
implicit none
OMPI_FORTRAN_IGNORE_TKR_TYPE, INTENT(IN) :: sendbuf
OMPI_FORTRAN_IGNORE_TKR_TYPE :: recvbuf
OMPI_F08_IGNORE_TKR_TYPE, INTENT(IN) :: sendbuf
OMPI_F08_IGNORE_TKR_TYPE :: recvbuf
INTEGER, INTENT(IN) :: sendcount
INTEGER, INTENT(IN) :: recvcounts(*), displs(*)
TYPE(MPI_Datatype), INTENT(IN) :: sendtype
Expand Down
6 changes: 3 additions & 3 deletions ompi/mpi/fortran/use-mpi-f08/alltoall_f08.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved.
! Copyright (c) 2009-2012 Los Alamos National Security, LLC.
! All rights reserved.
! Copyright (c) 2018 Research Organization for Information Science
! Copyright (c) 2018-2019 Research Organization for Information Science
! and Technology (RIST). All rights reserved.
! $COPYRIGHT$

Expand All @@ -14,8 +14,8 @@ subroutine MPI_Alltoall_f08(sendbuf,sendcount,sendtype,recvbuf,&
use :: mpi_f08_types, only : MPI_Datatype, MPI_Comm
use :: ompi_mpifh_bindings, only : ompi_alltoall_f
implicit none
OMPI_FORTRAN_IGNORE_TKR_TYPE, INTENT(IN) :: sendbuf
OMPI_FORTRAN_IGNORE_TKR_TYPE :: recvbuf
OMPI_F08_IGNORE_TKR_TYPE, INTENT(IN) :: sendbuf
OMPI_F08_IGNORE_TKR_TYPE :: recvbuf
INTEGER, INTENT(IN) :: sendcount, recvcount
TYPE(MPI_Datatype), INTENT(IN) :: sendtype
TYPE(MPI_Datatype), INTENT(IN) :: recvtype
Expand Down
4 changes: 2 additions & 2 deletions ompi/mpi/fortran/use-mpi-f08/bcast_f08.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved.
! Copyright (c) 2009-2012 Los Alamos National Security, LLC.
! All rights reserved.
! Copyright (c) 2018 Research Organization for Information Science
! Copyright (c) 2018-2019 Research Organization for Information Science
! and Technology (RIST). All rights reserved.
! Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
! $COPYRIGHT$
Expand All @@ -14,7 +14,7 @@ subroutine MPI_Bcast_f08(buffer,count,datatype,root,comm,ierror)
use :: mpi_f08_types, only : MPI_Datatype, MPI_Comm
use :: ompi_mpifh_bindings, only : ompi_bcast_f
implicit none
OMPI_FORTRAN_IGNORE_TKR_TYPE :: buffer
OMPI_F08_IGNORE_TKR_TYPE :: buffer
INTEGER, INTENT(IN) :: count, root
TYPE(MPI_Datatype), INTENT(IN) :: datatype
TYPE(MPI_Comm), INTENT(IN) :: comm
Expand Down
Loading