Skip to content

Commit dd2c466

Browse files
ggouaillardethppritcha
authored andcommitted
fortran/use-mpi-f08: add support for Fortran 2018 ISO_Fortran_binding.h
Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp> Conflicts: config/ompi_setup_mpi_fortran.m4
1 parent df72a69 commit dd2c466

File tree

13 files changed

+330
-18
lines changed

13 files changed

+330
-18
lines changed

config/ompi_config_files.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ AC_DEFUN([OMPI_CONFIG_FILES],[
4343
ompi/mpi/fortran/use-mpi-f08/base/Makefile
4444
ompi/mpi/fortran/use-mpi-f08/profile/Makefile
4545
ompi/mpi/fortran/use-mpi-f08/bindings/Makefile
46+
ompi/mpi/fortran/use-mpi-f08/ts/Makefile
4647
ompi/mpi/fortran/use-mpi-f08/mod/Makefile
4748
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-interfaces.h
49+
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-rename.h
4850
ompi/mpi/fortran/mpiext-use-mpi/Makefile
4951
ompi/mpi/fortran/mpiext-use-mpi-f08/Makefile
5052
ompi/mpi/tool/Makefile

config/ompi_fortran_check_ts.m4

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
dnl -*- shell-script -*-
2+
dnl
3+
dnl Copyright (c) 2019 Research Organization for Information Science
4+
dnl and Technology (RIST). All rights reserved.
5+
dnl $COPYRIGHT$
6+
dnl
7+
dnl Additional copyrights may follow
8+
dnl
9+
dnl $HEADER$
10+
dnl
11+
12+
# Check whether or not the C compiler supports ISO_Fortran_binding.h
13+
# Also check whether C and Fortran compiler interoperate.
14+
#
15+
# OMPI_FORTRAN_CHECK_TS([action if found], [action if not found])
16+
# ----------------------------------------------------
17+
AC_DEFUN([OMPI_FORTRAN_CHECK_TS],[
18+
AS_VAR_PUSHDEF([fortran_ts], [ompi_cv_fortran_have_ts])
19+
20+
AC_CHECK_HEADERS([ISO_Fortran_binding.h],
21+
[AC_CACHE_CHECK([if Fortran and C compilers support ISO_Fortran_binding.h], fortran_ts,
22+
[mkdir conftest.$$
23+
cd conftest.$$
24+
25+
# Try to compile the C bindings
26+
cat > conftest_c.c << EOF
27+
#include <ISO_Fortran_binding.h>
28+
29+
int is_contiguous_c(CFI_cdesc_t* x) {
30+
return CFI_is_contiguous(x);
31+
}
32+
EOF
33+
OPAL_LOG_COMMAND([$CC $CCFLAGS -c conftest_c.c],
34+
[cat > conftest.f90 << EOF
35+
module MOD_IS_CONTIGUOUS
36+
37+
interface
38+
39+
function is_contiguous(buf) BIND(C, name="is_contiguous_c")
40+
implicit none
41+
type(*), dimension(..) :: buf
42+
integer :: is_contiguous
43+
end function is_contiguous
44+
45+
end interface
46+
47+
end module
48+
49+
program test_is_contiguous
50+
use MOD_IS_CONTIGUOUS
51+
implicit none
52+
integer :: a0, a1(2), a2(2,2), a3(2,2,2)
53+
write (*,*) is_contiguous(a0)
54+
write (*,*) is_contiguous(a1)
55+
write (*,*) is_contiguous(a2)
56+
write (*,*) is_contiguous(a3)
57+
end program
58+
EOF
59+
OPAL_LOG_COMMAND([$FC $FCFLAGS $FCFLAGS_f90 -o conftest conftest.f90 conftest_c.o $LDFLAGS $LIBS],
60+
[AS_VAR_SET(fortran_ts, yes)],
61+
[AS_VAR_SET(fortran_ts, no)])],
62+
[AS_VAR_SET(fortran_ts, no)])
63+
cd ..
64+
rm -rf conftest.$$])],
65+
[AS_VAR_SET(fortran_ts, no)])
66+
67+
AS_VAR_IF(fortran_ts, [yes], [$1], [$2])
68+
AS_VAR_POPDEF([fortran_ts])dnl
69+
])

config/ompi_setup_mpi_fortran.m4

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,7 @@ end program]])],
453453
# module
454454
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
455455
test $OMPI_FORTRAN_HAVE_IGNORE_TKR -eq 1],
456-
[OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPIF08_BINDINGS
457-
OMPI_FORTRAN_F08_PREDECL=$OMPI_FORTRAN_IGNORE_TKR_PREDECL
458-
OMPI_FORTRAN_F08_TYPE=$OMPI_FORTRAN_IGNORE_TKR_TYPE
459-
])
456+
[OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPIF08_BINDINGS])
460457

461458
# The overall "_BIND_C" variable will be set to 1 if we have all
462459
# the necessary forms of BIND(C)
@@ -590,17 +587,13 @@ end type test_mpi_handle],
590587
])
591588

592589
OMPI_FORTRAN_NEED_WRAPPER_ROUTINES=1
593-
OMPI_FORTRAN_F08_PREDECL='!'
594-
OMPI_FORTRAN_F08_TYPE=real
595590
OMPI_FORTRAN_HAVE_F08_ASSUMED_RANK=0
596591
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
597592
test $OMPI_BUILD_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
598593
[ # Look for Fortran 2008 assumed rank syntax
599594
OMPI_FORTRAN_CHECK_F08_ASSUMED_RANK(
600595
[ # If we have assumed rank, we can build the use
601596
# mpi_f08 module "better"
602-
OMPI_FORTRAN_F08_PREDECL='!'
603-
OMPI_FORTRAN_F08_TYPE='type(*), dimension(..)'
604597
OMPI_FORTRAN_HAVE_F08_ASSUMED_RANK=1])
605598

606599
# Which mpi_f08 implementation are we using?
@@ -630,6 +623,12 @@ end type test_mpi_handle],
630623
[OMPI_FORTRAN_ELEMENTAL_TYPE=])])
631624
AC_SUBST(OMPI_FORTRAN_ELEMENTAL_TYPE)
632625

626+
OMPI_FORTRAN_HAVE_C_ISO_FORTRAN=0
627+
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
628+
test $OMPI_BUILD_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
629+
[OMPI_FORTRAN_CHECK_TS([OMPI_FORTRAN_HAVE_TS=1],
630+
[OMPI_FORTRAN_HAVE_TS=0])])
631+
633632
# Note: the current implementation *only* has wrappers;
634633
# there is no optimized implementation for a "good"
635634
# compiler. I'm leaving the above logic in place for
@@ -652,6 +651,8 @@ end type test_mpi_handle],
652651
AS_IF([test $OMPI_MIN_REQUIRED_FORTRAN_BINDINGS -gt $OMPI_BUILD_FORTRAN_BINDINGS],
653652
[AC_MSG_ERROR([Cannot build requested Fortran bindings, aborting])])
654653

654+
AC_CONFIG_FILES([ompi/mpi/fortran/use-mpi-f08/bindings/mpi-f-interfaces-bind.h])
655+
655656
# -------------------
656657
# mpif.h final setup
657658
# -------------------
@@ -792,10 +793,9 @@ end type test_mpi_handle],
792793
# This goes into mpifort-wrapper-data.txt
793794
AC_SUBST(OMPI_FORTRAN_USEMPIF08_LIB)
794795

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

800800
AC_SUBST(OMPI_MPI_PREFIX)
801801
AC_SUBST(OMPI_MPI_BIND_PREFIX)
@@ -877,6 +877,22 @@ end type test_mpi_handle],
877877
# For configure-fortran-output.h
878878
AC_SUBST(OMPI_FORTRAN_HAVE_BIND_C)
879879

880+
AM_CONDITIONAL(OMPI_FORTRAN_HAVE_TS,
881+
[test $OMPI_FORTRAN_HAVE_TS -eq 1])
882+
AC_SUBST(OMPI_FORTRAN_HAVE_TS)
883+
884+
AS_IF([test $OMPI_FORTRAN_HAVE_TS -eq 1],
885+
[OMPI_F08_IGNORE_TKR_TYPE="type(*), dimension(..)"
886+
OMPI_F08_IGNORE_TKR_PREDECL="! no attribute required for"
887+
OMPI_F08_BINDINGS_EXTENSION="ts"
888+
OMPI_F08_BINDINGS_TS_SUFFIX="ts"],
889+
[OMPI_F08_IGNORE_TKR_TYPE=$OMPI_FORTRAN_IGNORE_TKR_TYPE
890+
OMPI_F08_IGNORE_TKR_PREDECL=$OMPI_FORTRAN_IGNORE_TKR_PREDECL
891+
OMPI_F08_BINDINGS_EXTENSION="f"
892+
OMPI_F08_BINDINGS_TS_SUFFIX=""])
893+
AC_SUBST(OMPI_F08_BINDINGS_EXTENSION)
894+
AC_SUBST(OMPI_F08_BINDINGS_TS_SUFFIX)
895+
880896
# Somewhat redundant because ompi/Makefile.am won't traverse into
881897
# ompi/mpi/fortran/use-mpi-f08 if it's not to be built, but we
882898
# might as well have ompi/mpi/fortran/use-mpi-f08/Makefile.am be

ompi/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ SUBDIRS = \
8888
mpi/fortran/use-mpi-f08/base \
8989
mpi/fortran/use-mpi-f08/mod \
9090
mpi/fortran/use-mpi-f08/bindings \
91+
mpi/fortran/use-mpi-f08/ts \
9192
$(OMPI_MPIEXT_USEMPIF08_DIRS) \
9293
mpi/fortran/use-mpi-f08 \
9394
mpi/fortran/mpiext-use-mpi-f08 \
@@ -120,6 +121,7 @@ DIST_SUBDIRS = \
120121
mpi/fortran/use-mpi-f08/base \
121122
mpi/fortran/use-mpi-f08/mod \
122123
mpi/fortran/use-mpi-f08/bindings \
124+
mpi/fortran/use-mpi-f08/ts \
123125
mpi/fortran/mpiext-use-mpi-f08 \
124126
mpi/java \
125127
$(OMPI_MPIEXT_ALL_SUBDIRS) \

ompi/mpi/fortran/configure-fortran-output.h.in

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@
4343
! Line 2 of the ignore TKR syntax
4444
#define OMPI_FORTRAN_IGNORE_TKR_TYPE @OMPI_FORTRAN_IGNORE_TKR_TYPE@
4545
46+
! The Fortran ISO C type type(*), dimension(..) is not (yet) supported by all compilers.
47+
! If it is supported, OMPI_F08_IGNORE_TKR_TYPE will be type(*), dimension(..).
48+
! Otherwise, it will be the same value as OMPI_FORTRAN_IGNORE_TKR_TYPE.
49+
#define OMPI_F08_IGNORE_TKR_TYPE @OMPI_F08_IGNORE_TKR_TYPE@
50+
51+
! If the Fortran compiler supports type(*), dimension(..), this macro will be "_desc"
52+
! so that the F08 descriptor-enabled Open MPI Fortran back-end functions are invoked.
53+
! Otherwise, it will be "_f" so that the non-F08-descriptor Open MPI Fortran back-end functions are invoked.
54+
#define OMPI_F08_BINDINGS_EXTENSION @OMPI_F08_BINDINGS_EXTENSION@
55+
56+
! If the Fortran compiler supports type(*), dimension(..), this macro will be empty
57+
! (i.e., we do not want to ignore the TKR of the buf parameter).
58+
! Otherwise, it will be set to !GCC$ ATTRIBUTES NO_ARG_CHECK :: buf so that the GCC compiler
59+
! (and related compilers, such as the Intel compiler) will ignore the TKR of the buf dummy argument.
60+
61+
#define OMPI_F08_GCC_ATTRIBUTES(buf) @OMPI_F08_GCC_ATTRIBUTES@
4662
4763
#define OMPI_FORTRAN_BUILD_SIZEOF @OMPI_FORTRAN_BUILD_SIZEOF@
4864
! Integers

ompi/mpi/fortran/use-mpi-f08/Makefile.am

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ AM_CPPFLAGS =
3838
# MPI bindings.
3939
if OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS
4040

41-
AM_FCFLAGS = -I$(top_srcdir)/ompi/mpi/fortran/use-mpi-f08/mod \
42-
-I$(top_builddir)/ompi/include \
41+
AM_FCFLAGS = -I$(top_builddir)/ompi/include \
4342
-I$(top_srcdir)/ompi/include \
4443
$(OMPI_FC_MODULE_FLAG)$(top_builddir)/ompi/mpi/fortran/use-mpi \
4544
$(OMPI_FC_MODULE_FLAG)$(top_builddir)/ompi/$(OMPI_FORTRAN_USEMPI_DIR) \
4645
$(OMPI_FC_MODULE_FLAG)mod \
4746
$(OMPI_FC_MODULE_FLAG)bindings \
48-
-I$(top_srcdir) -I$(top_builddir) $(FCFLAGS_f90) \
47+
$(OMPI_FC_MODULE_FLAG)ts \
48+
-I$(top_srcdir) $(FCFLAGS_f90) \
4949
-DOMPI_BUILD_MPI_PROFILING=0
5050

5151
MOSTLYCLEANFILES = *.mod
@@ -548,6 +548,14 @@ lib@OMPI_LIBMPI_NAME@_usempif08_la_LIBADD = \
548548
lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES = $(module_sentinel_files)
549549
lib@OMPI_LIBMPI_NAME@_usempif08_la_LDFLAGS = -version-info $(libmpi_usempif08_so_version)
550550

551+
if OMPI_FORTRAN_HAVE_TS
552+
lib@OMPI_LIBMPI_NAME@_usempif08_la_LIBADD += \
553+
ts/libusempif08_ts.la
554+
555+
lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES += \
556+
ts/libusempif08_ts.la
557+
endif
558+
551559
#
552560
# Automake doesn't do Fortran dependency analysis, so must list them
553561
# manually here. Bummer!

ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-rename.h renamed to ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-rename.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,6 @@
801801
#define MPI_Neighbor_alltoallw_init PMPI_Neighbor_alltoallw_init
802802
#define MPI_Neighbor_alltoallw_init_f08 PMPI_Neighbor_alltoallw_init_f08
803803

804+
#elif @OMPI_FORTRAN_HAVE_TS@
805+
804806
#endif

ompi/mpi/fortran/use-mpi-f08/profile/Makefile.am

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ AM_CPPFLAGS =
4141
# MPI bindings.
4242
if OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS
4343

44-
AM_FCFLAGS = -I$(top_srcdir)/ompi/mpi/fortran/use-mpi-f08/mod \
45-
-I$(top_builddir)/ompi/include \
44+
AM_FCFLAGS = -I$(top_builddir)/ompi/include \
4645
-I$(top_srcdir)/ompi/include \
4746
$(OMPI_FC_MODULE_FLAG)$(top_builddir)/ompi/mpi/fortran/use-mpi \
4847
$(OMPI_FC_MODULE_FLAG)$(top_builddir)/ompi/$(OMPI_FORTRAN_USEMPI_DIR) \
4948
$(OMPI_FC_MODULE_FLAG)../mod \
5049
$(OMPI_FC_MODULE_FLAG)../bindings \
51-
-I$(top_srcdir) -I$(top_builddir) $(FCFLAGS_f90) \
50+
$(OMPI_FC_MODULE_FLAG)../ts \
51+
-I$(top_srcdir) $(FCFLAGS_f90) \
5252
-DOMPI_BUILD_MPI_PROFILING=1
5353

5454
CLEANFILES += *.i90
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- makefile -*-
2+
#
3+
# Copyright (c) 2006-2015 Cisco Systems, Inc. All rights reserved.
4+
# Copyright (c) 2012-2013 The University of Tennessee and The University
5+
# of Tennessee Research Foundation. All rights
6+
# reserved.
7+
# Copyright (c) 2012-2013 Inria. All rights reserved.
8+
# Copyright (c) 2013 Los Alamos National Security, LLC. All rights
9+
# reserved.
10+
# Copyright (c) 2015-2019 Research Organization for Information Science
11+
# and Technology (RIST). All rights reserved.
12+
# Copyright (c) 2016 IBM Corporation. All rights reserved.
13+
#
14+
# $COPYRIGHT$
15+
#
16+
# Additional copyrights may follow
17+
#
18+
# $HEADER$
19+
#
20+
21+
include $(top_srcdir)/Makefile.ompi-rules
22+
23+
24+
if OMPI_FORTRAN_HAVE_TS
25+
26+
AM_CPPFLAGS = -DOMPI_COMPILING_FORTRAN_WRAPPERS=1
27+
28+
noinst_LTLIBRARIES = libusempif08_ts.la
29+
30+
endif
31+
32+
libusempif08_ts_la_SOURCES = \
33+
bindings.h \
34+
ts.h \
35+
ts.c

0 commit comments

Comments
 (0)