From 07f20caf9ced7d90a72c54c4a2c17dcae6ff11b8 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Wed, 5 Mar 2025 11:08:05 +0100 Subject: [PATCH] Mark mpif.h as deprecated MPI 4.1 has deprecated mpif.h. We add a `#warning` directive that may be interpreted correctly if the Fortran compiler uses a C-style preprocessor or generate a warning about a illegal directive, showing the warning anyway: ``` 1 | #warning mpif.h is deprecated since MPI 4.1. Refer to MPI Sec. 19.1.4. | 1 Error: Illegal preprocessor directive [-Werror] ``` Also adds flang and flang-new to the list of known Fortran compilers. Signed-off-by: Joseph Schuchart --- config/ompi_configure_options.m4 | 4 ++ config/ompi_fortran_check_warning.m4 | 49 +++++++++++++++++++++++++ config/ompi_setup_fc.m4 | 3 +- config/ompi_setup_mpi_fortran.m4 | 15 ++++++++ docs/release-notes/changelog/v6.0.x.rst | 3 ++ ompi/include/mpif.h.in | 2 + 6 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 config/ompi_fortran_check_warning.m4 diff --git a/config/ompi_configure_options.m4 b/config/ompi_configure_options.m4 index 1ebf01f0dc4..b2ecd40002f 100644 --- a/config/ompi_configure_options.m4 +++ b/config/ompi_configure_options.m4 @@ -253,5 +253,9 @@ else fi AM_CONDITIONAL(OMPI_OMPIO_SUPPORT, test "$ompi_want_ompio" = "1") +AC_ARG_ENABLE([deprecate-mpif-h], + [AS_HELP_STRING([--enable-deprecate-mpif-h], + [Mark the mpif.h bindings as deprecated (default: enabled)])]) + ])dnl diff --git a/config/ompi_fortran_check_warning.m4 b/config/ompi_fortran_check_warning.m4 new file mode 100644 index 00000000000..a121d97636d --- /dev/null +++ b/config/ompi_fortran_check_warning.m4 @@ -0,0 +1,49 @@ +dnl -*- shell-script -*- +dnl +dnl Copyright (c) 2025 Stony Brook University. All rights reserved. +dnl $COPYRIGHT$ +dnl +dnl Additional copyrights may follow +dnl +dnl $HEADER$ +dnl + +# Check whether the fortran compiler produces a warning when +# it encounters a #warning directive + +# OMPI_FORTRAN_CHECK_WARNING([action if found], +# [action if not found]) +# ---------------------------------------------------- +AC_DEFUN([OMPI_FORTRAN_CHECK_WARNING],[ + AS_VAR_PUSHDEF([warning_var], [ompi_cv_fortran_warning]) + + AC_CACHE_CHECK([if Fortran compiler supports preprocessor warnings], warning_var, + [ + # check if the compiler provides a proper #warning + # some compilers (gfortran) do not show the warning if the file is found + # through an include path, so create a temporary directory and include file + OAC_VAR_SCOPE_PUSH(msg, dir) + dir="tmp_includedir_$$" + msg="This is a deprecated file" + AS_MKDIR_P($dir) + echo "#warning $msg" > $dir/deprecated.h + + echo "! -*- fortran -*- + program main + implicit none + include 'deprecated.h' + end program main + " > conftest.f + AS_IF([${FC} ${FCFLAGS} -c -I$dir conftest.f 2>conftest.err >conftest.out], + [ # compilation succeeded, check the produced output for the warning + AS_IF([grep "$msg" conftest.err conftest.out >/dev/null 2>/dev/null], + [AS_VAR_SET(warning_var, "yes")], + [AS_VAR_SET(warning_var, "no (missing warning)")],)], + [AS_VAR_SET(warning_var, "no (compilation failed)")]) + OPAL_VAR_SCOPE_POP + rm -rf conftest.f conftest.err conftest.out $dir 2>/dev/null >/dev/null + ]) + AS_VAR_IF(warning_var, [yes], [$1], [$2]) + AS_VAR_POPDEF([warning_var])dnl +]) + diff --git a/config/ompi_setup_fc.m4 b/config/ompi_setup_fc.m4 index 157f5a6301d..d63434a27e9 100644 --- a/config/ompi_setup_fc.m4 +++ b/config/ompi_setup_fc.m4 @@ -16,6 +16,7 @@ dnl Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. dnl Copyright (c) 2009-2020 Cisco Systems, Inc. All rights reserved. dnl Copyright (c) 2015-2020 Research Organization for Information Science dnl and Technology (RIST). All rights reserved. +dnl Copyright (c) 2025 Stony Brook University. All rights reserved. dnl $COPYRIGHT$ dnl dnl Additional copyrights may follow @@ -43,7 +44,7 @@ AC_DEFUN_ONCE([_OMPI_SETUP_FC_COMPILER],[ # Fortran compilers (excluding the f77 compiler names) from AC's # default list of compilers and use it here. This is the main # reason we have an OMPI-ized version of the PROG_FC macro. - AC_PROG_FC([gfortran f95 fort xlf95 ifort ifc efc pgfortran pgf95 lf95 f90 xlf90 pgf90 epcf90 nagfor nvfortran]) + AC_PROG_FC([gfortran flang-new flang f95 fort xlf95 ifort ifc efc pgfortran pgf95 lf95 f90 xlf90 pgf90 epcf90 nagfor nvfortran]) FCFLAGS="$ompi_fcflags_save" OPAL_VAR_SCOPE_POP ]) diff --git a/config/ompi_setup_mpi_fortran.m4 b/config/ompi_setup_mpi_fortran.m4 index cf3e3329c42..0a6a1406041 100644 --- a/config/ompi_setup_mpi_fortran.m4 +++ b/config/ompi_setup_mpi_fortran.m4 @@ -21,6 +21,7 @@ dnl Copyright (c) 2016-2022 IBM Corporation. All rights reserved. dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. dnl Copyright (c) 2022 Triad National Security, LLC. All rights dnl reserved. +dnl Copyright (c) 2025 Stony Brook University. All rights reserved. dnl $COPYRIGHT$ dnl dnl Additional copyrights may follow @@ -376,6 +377,20 @@ end program]])], [OMPI_FORTRAN_BUILD_SIZEOF=0]) AC_SUBST(OMPI_FORTRAN_BUILD_SIZEOF) + OMPI_FORTRAN_SUPPORTS_WARNING="no" + AS_IF([! test x"$enable_deprecate_mpif_h" = "xno"], + [OMPI_FORTRAN_CHECK_WARNING([OMPI_FORTRAN_SUPPORTS_WARNING="yes"], + [OMPI_FORTRAN_SUPPORTS_WARNING="no"])]) + AC_MSG_CHECKING([if we mark mpif.h bindings as deprecated]) + AS_IF([test "x$enable_deprecate_mpif_h" = "xyes" && test "$OMPI_FORTRAN_SUPPORTS_WARNING" = "no"], + [AC_MSG_ERROR([Request to mark mpif.h as deprecated but Fortran compiler does not support warning preprocessor directive.])]) + AS_IF([test "x$enable_deprecate_mpif_h" != "xno" && test "$OMPI_FORTRAN_SUPPORTS_WARNING" = "yes"], + [OMPI_FORTRAN_DEPRECATE_MPIF_H="#warning mpif.h has been deprecated since MPI 4.1. See MPI-4.1:19.1.4 for details." + AC_MSG_RESULT([yes])], + [OMPI_FORTRAN_DEPRECATE_MPIF_H="" + AC_MSG_RESULT([no])]) + AC_SUBST(OMPI_FORTRAN_DEPRECATE_MPIF_H) + #-------------------------------------------- # Fortran use mpi or use mpi_f08 MPI bindings #-------------------------------------------- diff --git a/docs/release-notes/changelog/v6.0.x.rst b/docs/release-notes/changelog/v6.0.x.rst index 99bd994c09b..77e12b4effe 100644 --- a/docs/release-notes/changelog/v6.0.x.rst +++ b/docs/release-notes/changelog/v6.0.x.rst @@ -9,3 +9,6 @@ Open MPI version v6.0.0 :Date: ...fill me in... - Open MPI now requires a C11-compliant compiler to build. +- MPI 4.1 has deprecated the use of the Fortran mpif.h include file. + Open MPI will now issue a warning when the file is included and the + Fortran compiler supports the #warning directive. diff --git a/ompi/include/mpif.h.in b/ompi/include/mpif.h.in index d4cbd138325..bc406156b0d 100644 --- a/ompi/include/mpif.h.in +++ b/ompi/include/mpif.h.in @@ -53,6 +53,8 @@ ! WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +@OMPI_FORTRAN_DEPRECATE_MPIF_H@ + include 'mpif-config.h' include 'mpif-constants.h' include 'mpif-handles.h'