Skip to content

Commit

Permalink
Generate interfaces for C with bigcount
Browse files Browse the repository at this point in the history
This adds scripts for generating the Fortran and C API bindings from
template files, while also generating bigcount interfaces for those
that require them. The Fortran binding code (for mpi_f08) is designed to
generate both the Fortran subroutines and wrapping C code which
calls into the MPI C api.

Python >=3.6 is required for running these scripts, which is only
necessary when the binding files have not already been generated.
Users of the distribution tarball should not need to generate these files
and thus should not require Python.

Co-authored-by: mphinney1100 <mphinney@lanl.gov>
Co-authored-by: Howard Pritchard <hppritcha@gmail.com>
Signed-off-by: Jake Tronge <jtronge@lanl.gov>
  • Loading branch information
3 people committed Jul 30, 2024
1 parent b4390af commit 8a912b0
Show file tree
Hide file tree
Showing 880 changed files with 40,006 additions and 39,433 deletions.
16 changes: 13 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-constants.h
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-interfaces.h
ompi/mpi/fortran/use-mpi-f08/sizeof_f08.f90
ompi/mpi/fortran/use-mpi-f08/sizeof_f08.h
ompi/mpi/fortran/use-mpi-f08/profile/psizeof_f08.f90
ompi/mpi/fortran/use-mpi-f08/profile/*.F90

ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr-interfaces.h
ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr-file-interfaces.h
Expand Down Expand Up @@ -534,9 +532,10 @@ docs/_static
docs/_static/css/custom.css
docs/_templates

# Common Python virtual environment directory names
# Common Python virtual environment and cache directory names
venv
py??
__pycache__/

# Copies of PRRTE RST files (i.e., not source controlled in this tree)
docs/prrte-rst-content
Expand All @@ -546,3 +545,14 @@ docs/schizo-ompi-rst-content
# tarballs)
docs/html
docs/man

# Generated binding scripts
ompi/mpi/bindings/ompi_bindings/compiler.py

# Generated C Bindings
ompi/mpi/c/generated_*.c

# Generated Fortran Bindings
ompi/mpi/fortran/use-mpi-f08/*_generated.F90
ompi/mpi/fortran/use-mpi-f08/base/*_generated.c
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-interfaces-generated.h
2 changes: 1 addition & 1 deletion config/ompi_config_files.m4
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ 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/base/Makefile
ompi/mpi/fortran/use-mpi-f08/profile/Makefile
ompi/mpi/fortran/use-mpi-f08/bindings/Makefile
ompi/mpi/fortran/use-mpi-f08/mod/Makefile
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-interfaces.h
ompi/mpi/fortran/mpiext-use-mpi/Makefile
ompi/mpi/fortran/mpiext-use-mpi-f08/Makefile
ompi/mpi/bindings/ompi_bindings/compiler.py
ompi/mpi/tool/Makefile

ompi/tools/ompi_info/Makefile
Expand Down
21 changes: 21 additions & 0 deletions config/ompi_configure_options.m4
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,26 @@ else
fi
AM_CONDITIONAL(OMPI_OMPIO_SUPPORT, test "$ompi_want_ompio" = "1")

AC_MSG_CHECKING([if want bigcount support])
AC_ARG_ENABLE([bigcount],
[AS_HELP_STRING([--enable-bigcount],
[Enable the bigcount API])])
if test "$enable_bigcount" = "yes" ; then
AC_MSG_RESULT([yes])
ompi_enable_bigcount=1
else
AC_MSG_RESULT([no])
ompi_enable_bigcount=0
fi
AC_DEFINE_UNQUOTED([OMPI_BIGCOUNT],[$ompi_enable_bigcount],
[Whether we want to compile bigcount API support])

# If the binding source files don't exist, then we need Python to generate them
AM_PATH_PYTHON([3.6],,[:])
binding_file="${srcdir}/ompi/mpi/c/ompi_send.c"
AS_IF([! test -e "$binding_file" && test "$PYTHON" = ":"],
[AC_MSG_ERROR([Open MPI requires Python >=3.6 for generating the bindings. Aborting])])
AM_CONDITIONAL(OMPI_GENERATE_BINDINGS,[test "$PYTHON" != ":"])

])dnl

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

dnl 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:1}
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
Loading

0 comments on commit 8a912b0

Please sign in to comment.