Skip to content

Commit bfc2f20

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 918fe01 commit bfc2f20

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
@@ -421,10 +421,7 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[
421421
# module
422422
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
423423
test $OMPI_FORTRAN_HAVE_IGNORE_TKR -eq 1],
424-
[OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPIF08_BINDINGS
425-
OMPI_FORTRAN_F08_PREDECL=$OMPI_FORTRAN_IGNORE_TKR_PREDECL
426-
OMPI_FORTRAN_F08_TYPE=$OMPI_FORTRAN_IGNORE_TKR_TYPE
427-
])
424+
[OMPI_BUILD_FORTRAN_BINDINGS=$OMPI_FORTRAN_USEMPIF08_BINDINGS])
428425

429426
# The overall "_BIND_C" variable will be set to 1 if we have all
430427
# the necessary forms of BIND(C)
@@ -558,17 +555,13 @@ end type test_mpi_handle],
558555
])
559556

560557
OMPI_FORTRAN_NEED_WRAPPER_ROUTINES=1
561-
OMPI_FORTRAN_F08_PREDECL='!'
562-
OMPI_FORTRAN_F08_TYPE=real
563558
OMPI_FORTRAN_HAVE_F08_ASSUMED_RANK=0
564559
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
565560
test $OMPI_BUILD_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
566561
[ # Look for Fortran 2008 assumed rank syntax
567562
OMPI_FORTRAN_CHECK_F08_ASSUMED_RANK(
568563
[ # If we have assumed rank, we can build the use
569564
# mpi_f08 module "better"
570-
OMPI_FORTRAN_F08_PREDECL='!'
571-
OMPI_FORTRAN_F08_TYPE='type(*), dimension(..)'
572565
OMPI_FORTRAN_HAVE_F08_ASSUMED_RANK=1])
573566

574567
# Which mpi_f08 implementation are we using?
@@ -598,6 +591,12 @@ end type test_mpi_handle],
598591
[OMPI_FORTRAN_ELEMENTAL_TYPE=])])
599592
AC_SUBST(OMPI_FORTRAN_ELEMENTAL_TYPE)
600593

594+
OMPI_FORTRAN_HAVE_C_ISO_FORTRAN=0
595+
AS_IF([test $OMPI_TRY_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS && \
596+
test $OMPI_BUILD_FORTRAN_BINDINGS -ge $OMPI_FORTRAN_USEMPIF08_BINDINGS],
597+
[OMPI_FORTRAN_CHECK_TS([OMPI_FORTRAN_HAVE_TS=1],
598+
[OMPI_FORTRAN_HAVE_TS=0])])
599+
601600
# Note: the current implementation *only* has wrappers;
602601
# there is no optimized implementation for a "good"
603602
# compiler. I'm leaving the above logic in place for
@@ -620,6 +619,8 @@ end type test_mpi_handle],
620619
AS_IF([test $OMPI_MIN_REQUIRED_FORTRAN_BINDINGS -gt $OMPI_BUILD_FORTRAN_BINDINGS],
621620
[AC_MSG_ERROR([Cannot build requested Fortran bindings, aborting])])
622621

622+
AC_CONFIG_FILES([ompi/mpi/fortran/use-mpi-f08/bindings/mpi-f-interfaces-bind.h])
623+
623624
# -------------------
624625
# mpif.h final setup
625626
# -------------------
@@ -760,10 +761,9 @@ end type test_mpi_handle],
760761
# This goes into mpifort-wrapper-data.txt
761762
AC_SUBST(OMPI_FORTRAN_USEMPIF08_LIB)
762763

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

768768
AC_SUBST(OMPI_MPI_PREFIX)
769769
AC_SUBST(OMPI_MPI_BIND_PREFIX)
@@ -845,6 +845,22 @@ end type test_mpi_handle],
845845
# For configure-fortran-output.h
846846
AC_SUBST(OMPI_FORTRAN_HAVE_BIND_C)
847847

848+
AM_CONDITIONAL(OMPI_FORTRAN_HAVE_TS,
849+
[test $OMPI_FORTRAN_HAVE_TS -eq 1])
850+
AC_SUBST(OMPI_FORTRAN_HAVE_TS)
851+
852+
AS_IF([test $OMPI_FORTRAN_HAVE_TS -eq 1],
853+
[OMPI_F08_IGNORE_TKR_TYPE="type(*), dimension(..)"
854+
OMPI_F08_IGNORE_TKR_PREDECL="! no attribute required for"
855+
OMPI_F08_BINDINGS_EXTENSION="ts"
856+
OMPI_F08_BINDINGS_TS_SUFFIX="ts"],
857+
[OMPI_F08_IGNORE_TKR_TYPE=$OMPI_FORTRAN_IGNORE_TKR_TYPE
858+
OMPI_F08_IGNORE_TKR_PREDECL=$OMPI_FORTRAN_IGNORE_TKR_PREDECL
859+
OMPI_F08_BINDINGS_EXTENSION="f"
860+
OMPI_F08_BINDINGS_TS_SUFFIX=""])
861+
AC_SUBST(OMPI_F08_BINDINGS_EXTENSION)
862+
AC_SUBST(OMPI_F08_BINDINGS_TS_SUFFIX)
863+
848864
# Somewhat redundant because ompi/Makefile.am won't traverse into
849865
# ompi/mpi/fortran/use-mpi-f08 if it's not to be built, but we
850866
# 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
@@ -37,14 +37,14 @@ AM_CPPFLAGS =
3737
# MPI bindings.
3838
if OMPI_BUILD_FORTRAN_USEMPIF08_BINDINGS
3939

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

5050
MOSTLYCLEANFILES = *.mod
@@ -540,6 +540,14 @@ lib@OMPI_LIBMPI_NAME@_usempif08_la_LIBADD = \
540540
lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES = $(module_sentinel_files)
541541
lib@OMPI_LIBMPI_NAME@_usempif08_la_LDFLAGS = -version-info $(libmpi_usempif08_so_version)
542542

543+
if OMPI_FORTRAN_HAVE_TS
544+
lib@OMPI_LIBMPI_NAME@_usempif08_la_LIBADD += \
545+
ts/libusempif08_ts.la
546+
547+
lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES += \
548+
ts/libusempif08_ts.la
549+
endif
550+
543551
#
544552
# Automake doesn't do Fortran dependency analysis, so must list them
545553
# 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
@@ -790,4 +790,6 @@
790790
#define MPI_Neighbor_alltoallw_init PMPI_Neighbor_alltoallw_init
791791
#define MPI_Neighbor_alltoallw_init_f08 PMPI_Neighbor_alltoallw_init_f08
792792

793+
#elif @OMPI_FORTRAN_HAVE_TS@
794+
793795
#endif

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

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

42-
AM_FCFLAGS = -I$(top_srcdir)/ompi/mpi/fortran/use-mpi-f08/mod \
43-
-I$(top_builddir)/ompi/include \
42+
AM_FCFLAGS = -I$(top_builddir)/ompi/include \
4443
-I$(top_srcdir)/ompi/include \
4544
$(OMPI_FC_MODULE_FLAG)$(top_builddir)/ompi/mpi/fortran/use-mpi \
4645
$(OMPI_FC_MODULE_FLAG)$(top_builddir)/ompi/$(OMPI_FORTRAN_USEMPI_DIR) \
4746
$(OMPI_FC_MODULE_FLAG)../mod \
4847
$(OMPI_FC_MODULE_FLAG)../bindings \
49-
-I$(top_srcdir) -I$(top_builddir) $(FCFLAGS_f90) \
48+
$(OMPI_FC_MODULE_FLAG)../ts \
49+
-I$(top_srcdir) $(FCFLAGS_f90) \
5050
-DOMPI_BUILD_MPI_PROFILING=1
5151

5252
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)