Skip to content
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

fortran/use-mpi-f08: add support for Fortran 2018 ISO_Fortran_binding.h try number two #10302

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions config/ompi_config_files.m4
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ AC_DEFUN([OMPI_CONFIG_FILES],[
ompi/mpi/fortran/use-mpi-f08/base/Makefile
ompi/mpi/fortran/use-mpi-f08/profile/Makefile
ompi/mpi/fortran/use-mpi-f08/bindings/Makefile
ompi/mpi/fortran/use-mpi-f08/ts/Makefile
ompi/mpi/fortran/use-mpi-f08/mod/Makefile
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-subarrays-config.h
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-interfaces.h
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-rename.h
ompi/mpi/fortran/mpiext-use-mpi/Makefile
ompi/mpi/fortran/mpiext-use-mpi-f08/Makefile
ompi/mpi/tool/Makefile
Expand Down
69 changes: 69 additions & 0 deletions config/ompi_fortran_check_ts.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_TS([action if found], [action if not found])
# ----------------------------------------------------
AC_DEFUN([OMPI_FORTRAN_CHECK_TS],[
AS_VAR_PUSHDEF([fortran_ts], [ompi_cv_fortran_have_ts])

AC_CHECK_HEADERS([ISO_Fortran_binding.h],
[AC_CACHE_CHECK([if Fortran and C compilers support ISO_Fortran_binding.h], fortran_ts,
[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(fortran_ts, yes)],
[AS_VAR_SET(fortran_ts, no)])],
[AS_VAR_SET(fortran_ts, no)])
cd ..
rm -rf conftest.$$])],
[AS_VAR_SET(fortran_ts, no)])

AS_VAR_IF(fortran_ts, [yes], [$1], [$2])
AS_VAR_POPDEF([fortran_ts])dnl
])
62 changes: 47 additions & 15 deletions config/ompi_setup_mpi_fortran.m4
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,27 @@ end program]])],
# If we got all the stuff from above, then also look for the new
# F08 syntax that we can use for the use_mpif08 module.

# We need to have ignore TKR functionality to build the mpi_f08
OMPI_FORTRAN_HAVE_TS=0
OMPI_MPI_SUBARRAYS_SUPPORTED=.false.
OMPI_MPI_ASYNC_PROTECTS_NONBLOCKING=.false.
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
[OMPI_FORTRAN_CHECK_TS([OMPI_FORTRAN_HAVE_TS=1])])

AC_SUBST(OMPI_MPI_SUBARRAYS_SUPPORTED)
AC_SUBST(OMPI_MPI_ASYNC_PROTECTS_NONBLOCKING)

# We need to have ignore TKR or the ISO Fortran bindings functionality to build the mpi_f08
# module
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
test $OMPI_FORTRAN_HAVE_IGNORE_TKR -eq 1],
[OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPIF08_BINDINGS
OMPI_FORTRAN_F08_PREDECL=$OMPI_FORTRAN_IGNORE_TKR_PREDECL
OMPI_FORTRAN_F08_TYPE=$OMPI_FORTRAN_IGNORE_TKR_TYPE
])
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
[AS_IF([test $OMPI_FORTRAN_HAVE_IGNORE_TKR -eq 1],
[OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPIF08_BINDINGS
OMPI_FORTRAN_F08_PREDECL=$OMPI_FORTRAN_IGNORE_TKR_PREDECL
OMPI_FORTRAN_F08_TYPE=$OMPI_FORTRAN_IGNORE_TKR_TYPE
])
AS_IF([test $OMPI_FORTRAN_HAVE_TS -eq 1],
[OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPIF08_BINDINGS
OMPI_MPI_SUBARRAYS_SUPPORTED=.true.
OMPI_MPI_ASYNC_PROTECTS_NONBLOCKING=.true.])])

# The overall "_BIND_C" variable will be set to 1 if we have all
# the necessary forms of BIND(C)
Expand Down Expand Up @@ -590,17 +603,13 @@ end type test_mpi_handle],
])

OMPI_FORTRAN_NEED_WRAPPER_ROUTINES=1
OMPI_FORTRAN_F08_PREDECL='!'
OMPI_FORTRAN_F08_TYPE=real
OMPI_FORTRAN_HAVE_F08_ASSUMED_RANK=0
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
test $OMPI_BUILD_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
[ # Look for Fortran 2008 assumed rank syntax
OMPI_FORTRAN_CHECK_F08_ASSUMED_RANK(
[ # If we have assumed rank, we can build the use
# mpi_f08 module "better"
OMPI_FORTRAN_F08_PREDECL='!'
OMPI_FORTRAN_F08_TYPE='type(*), dimension(..)'
OMPI_FORTRAN_HAVE_F08_ASSUMED_RANK=1])

# Which mpi_f08 implementation are we using?
Expand Down Expand Up @@ -630,6 +639,12 @@ end type test_mpi_handle],
[OMPI_FORTRAN_ELEMENTAL_TYPE=])])
AC_SUBST(OMPI_FORTRAN_ELEMENTAL_TYPE)

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_TS([OMPI_FORTRAN_HAVE_TS=1],
[OMPI_FORTRAN_HAVE_TS=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 @@ -652,6 +667,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 @@ -792,10 +809,9 @@ end type test_mpi_handle],
# This goes into mpifort-wrapper-data.txt
AC_SUBST(OMPI_FORTRAN_USEMPIF08_LIB)

# These go into interfaces/mpi-f08-interfaces-[no]bind.h (and
# mpi-f*-interfaces*.h files)
AC_SUBST(OMPI_FORTRAN_F08_PREDECL)
AC_SUBST(OMPI_FORTRAN_F08_TYPE)
# These go into mod/mpi-f08-interfaces.h
AC_SUBST(OMPI_F08_IGNORE_TKR_PREDECL)
AC_SUBST(OMPI_F08_IGNORE_TKR_TYPE)

AC_SUBST(OMPI_MPI_PREFIX)
AC_SUBST(OMPI_MPI_BIND_PREFIX)
Expand Down Expand Up @@ -877,6 +893,22 @@ end type test_mpi_handle],
# For configure-fortran-output.h
AC_SUBST(OMPI_FORTRAN_HAVE_BIND_C)

AM_CONDITIONAL(OMPI_FORTRAN_HAVE_TS,
[test $OMPI_FORTRAN_HAVE_TS -eq 1])
AC_SUBST(OMPI_FORTRAN_HAVE_TS)

AS_IF([test $OMPI_FORTRAN_HAVE_TS -eq 1],
[OMPI_F08_IGNORE_TKR_TYPE="type(*), dimension(..)"
OMPI_F08_IGNORE_TKR_PREDECL="! no attribute required for"
OMPI_F08_BINDINGS_EXTENSION="ts"
OMPI_F08_BINDINGS_TS_SUFFIX="ts"],
[OMPI_F08_IGNORE_TKR_TYPE=$OMPI_FORTRAN_IGNORE_TKR_TYPE
OMPI_F08_IGNORE_TKR_PREDECL=$OMPI_FORTRAN_IGNORE_TKR_PREDECL
OMPI_F08_BINDINGS_EXTENSION="f"
OMPI_F08_BINDINGS_TS_SUFFIX=""])
AC_SUBST(OMPI_F08_BINDINGS_EXTENSION)
AC_SUBST(OMPI_F08_BINDINGS_TS_SUFFIX)

# 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
2 changes: 2 additions & 0 deletions ompi/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ SUBDIRS = \
mpi/fortran/use-mpi-f08/base \
mpi/fortran/use-mpi-f08/mod \
mpi/fortran/use-mpi-f08/bindings \
mpi/fortran/use-mpi-f08/ts \
$(OMPI_MPIEXT_USEMPIF08_DIRS) \
mpi/fortran/use-mpi-f08 \
mpi/fortran/mpiext-use-mpi-f08 \
Expand Down Expand Up @@ -120,6 +121,7 @@ DIST_SUBDIRS = \
mpi/fortran/use-mpi-f08/base \
mpi/fortran/use-mpi-f08/mod \
mpi/fortran/use-mpi-f08/bindings \
mpi/fortran/use-mpi-f08/ts \
mpi/fortran/mpiext-use-mpi-f08 \
mpi/java \
$(OMPI_MPIEXT_ALL_SUBDIRS) \
Expand Down
3 changes: 2 additions & 1 deletion ompi/include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ include_HEADERS += \
mpif-handles.h \
mpif-io-constants.h \
mpif-io-handles.h \
mpif-sentinels.h
mpif-sentinels.h \
mpif-subarrays-config.h

endif

Expand Down
13 changes: 2 additions & 11 deletions ompi/include/mpif-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
! reserved.
! Copyright (c) 2019 Triad National Security, LLC. All rights
! reserved.
! Copyright (c) 2019 Research Organization for Information Science
! and Technology (RIST). All rights reserved.
! $COPYRIGHT$
!
! Additional copyrights may follow
Expand Down Expand Up @@ -74,14 +76,3 @@
parameter (MPI_MAX_DATAREP_STRING=@OPAL_MAX_DATAREP_STRING@-1)
parameter (MPI_MAX_PSET_NAME_LEN=@OPAL_MAX_PSET_NAME_LEN@-1)
parameter (MPI_MAX_STRINGTAG_LEN=@OPAL_MAX_STRINGTAG_LEN@-1)

!
! MPI F08 conformance
!
logical MPI_SUBARRAYS_SUPPORTED
logical MPI_ASYNC_PROTECTS_NONBLOCKING
! Hard-coded for .false. for now
parameter (MPI_SUBARRAYS_SUPPORTED= .false.)
! Hard-coded for .false. for now
parameter (MPI_ASYNC_PROTECTS_NONBLOCKING = .false.)

19 changes: 19 additions & 0 deletions ompi/include/mpif-subarrays-config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
! -*- fortran -*-
!
! Copyright (c) 2019 Research Organization for Information Science
! and Technology (RIST). All rights reserved.
! $COPYRIGHT$
!
! Additional copyrights may follow
!
! $HEADER$
!

!
! MPI F08 conformance
!
logical MPI_SUBARRAYS_SUPPORTED
logical MPI_ASYNC_PROTECTS_NONBLOCKING
parameter (MPI_SUBARRAYS_SUPPORTED= .FALSE.)
parameter (MPI_ASYNC_PROTECTS_NONBLOCKING = .FALSE.)

5 changes: 3 additions & 2 deletions ompi/include/mpif.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
! Copyright (c) 2004-2005 The Regents of the University of California.
! All rights reserved.
! Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved.
! Copyright (c) 2017 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$
!
! Additional copyrights may follow
Expand Down Expand Up @@ -54,6 +54,7 @@
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

include 'mpif-config.h'
include 'mpif-subarrays-config.h'
include 'mpif-constants.h'
include 'mpif-handles.h'
include 'mpif-io-constants.h'
Expand Down
14 changes: 10 additions & 4 deletions ompi/mpi/fortran/base/fint_2_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
#define OMPI_SINGLE_FINT_2_INT(in)
#define OMPI_SINGLE_INT_2_FINT(in)
#define OMPI_ARRAY_INT_2_FINT(in, n)
#define OMPI_COND_STATEMENT(a)

#elif OMPI_SIZEOF_FORTRAN_INTEGER > SIZEOF_INT
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a = NULL
#define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2], dim2_index
#define OMPI_SINGLE_NAME_DECL(a) int c_##a
#define OMPI_ARRAY_NAME_CONVERT(a) c_##a
Expand Down Expand Up @@ -86,7 +87,8 @@

/* This is for IN parameters. Does only free */
#define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
free(OMPI_ARRAY_NAME_CONVERT(in))
if (NULL != OMPI_ARRAY_NAME_CONVERT(in)) \
free(OMPI_ARRAY_NAME_CONVERT(in))

/* This is for single IN parameter */
#define OMPI_SINGLE_FINT_2_INT(in) \
Expand All @@ -105,8 +107,10 @@
} \
free(OMPI_ARRAY_NAME_CONVERT(in)); \
} while (0)

#define OMPI_COND_STATEMENT(a) a
#else /* int > MPI_Fint */
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a = NULL
#define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2], dim2_index
#define OMPI_SINGLE_NAME_DECL(a) int c_##a
#define OMPI_ARRAY_NAME_CONVERT(a) c_##a
Expand Down Expand Up @@ -140,7 +144,8 @@
} while (0)

#define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
free(OMPI_ARRAY_NAME_CONVERT(in))
if (NULL != OMPI_ARRAY_NAME_CONVERT(in)) \
free(OMPI_ARRAY_NAME_CONVERT(in))

#define OMPI_SINGLE_FINT_2_INT(in) \
OMPI_ARRAY_NAME_CONVERT(in) = *(in)
Expand All @@ -157,6 +162,7 @@
free(OMPI_ARRAY_NAME_CONVERT(in)); \
} while (0)

#define OMPI_COND_STATEMENT(a) a
#endif

/*
Expand Down
16 changes: 16 additions & 0 deletions ompi/mpi/fortran/configure-fortran-output.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@
! Line 2 of the ignore TKR syntax
#define OMPI_FORTRAN_IGNORE_TKR_TYPE @OMPI_FORTRAN_IGNORE_TKR_TYPE@

! The Fortran ISO C type type(*), dimension(..) is not (yet) supported by all compilers.
! If it is supported, OMPI_F08_IGNORE_TKR_TYPE will be type(*), dimension(..).
! Otherwise, it will be the same value as OMPI_FORTRAN_IGNORE_TKR_TYPE.
#define OMPI_F08_IGNORE_TKR_TYPE @OMPI_F08_IGNORE_TKR_TYPE@

! If the Fortran compiler supports type(*), dimension(..), this macro will be "_desc"
! so that the F08 descriptor-enabled Open MPI Fortran back-end functions are invoked.
! Otherwise, it will be "_f" so that the non-F08-descriptor Open MPI Fortran back-end functions are invoked.
#define OMPI_F08_BINDINGS_EXTENSION @OMPI_F08_BINDINGS_EXTENSION@

! If the Fortran compiler supports type(*), dimension(..), this macro will be empty
! (i.e., we do not want to ignore the TKR of the buf parameter).
! Otherwise, it will be set to !GCC$ ATTRIBUTES NO_ARG_CHECK :: buf so that the GCC compiler
! (and related compilers, such as the Intel compiler) will ignore the TKR of the buf dummy argument.

#define OMPI_F08_GCC_ATTRIBUTES(buf) @OMPI_F08_GCC_ATTRIBUTES@

#define OMPI_FORTRAN_BUILD_SIZEOF @OMPI_FORTRAN_BUILD_SIZEOF@
! Integers
Expand Down
9 changes: 9 additions & 0 deletions ompi/mpi/fortran/use-mpi-f08/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ AM_FCFLAGS = -I$(top_srcdir)/ompi/mpi/fortran/use-mpi-f08/mod \
$(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)ts \
-I$(top_srcdir) -I$(top_builddir) $(FCFLAGS_f90) \
-DOMPI_BUILD_MPI_PROFILING=0

Expand Down Expand Up @@ -548,6 +549,14 @@ lib@OMPI_LIBMPI_NAME@_usempif08_la_LIBADD = \
lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES = $(module_sentinel_files)
lib@OMPI_LIBMPI_NAME@_usempif08_la_LDFLAGS = -version-info $(libmpi_usempif08_so_version)

if OMPI_FORTRAN_HAVE_TS
lib@OMPI_LIBMPI_NAME@_usempif08_la_LIBADD += \
ts/libusempif08_ts.la

lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES += \
ts/libusempif08_ts.la
endif

#
# Automake doesn't do Fortran dependency analysis, so must list them
# manually here. Bummer!
Expand Down
2 changes: 1 addition & 1 deletion ompi/mpi/fortran/use-mpi-f08/accumulate_f08.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ subroutine MPI_Accumulate_f08(origin_addr,origin_count,origin_datatype,&
use :: mpi_f08_types, only : MPI_Datatype, MPI_Op, MPI_Win, MPI_ADDRESS_KIND
use :: ompi_mpifh_bindings, only : ompi_accumulate_f
implicit none
OMPI_FORTRAN_IGNORE_TKR_TYPE, INTENT(IN) OMPI_ASYNCHRONOUS :: origin_addr
OMPI_F08_IGNORE_TKR_TYPE, INTENT(IN) OMPI_ASYNCHRONOUS :: origin_addr
INTEGER, INTENT(IN) :: origin_count, target_rank, target_count
TYPE(MPI_Datatype), INTENT(IN) :: origin_datatype
INTEGER(MPI_ADDRESS_KIND), INTENT(IN) :: target_disp
Expand Down
Loading
Loading