Skip to content

Commit 2a81c9f

Browse files
committed
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 <[email protected]>
1 parent 42b17ae commit 2a81c9f

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

config/ompi_configure_options.m4

+4
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,9 @@ else
253253
fi
254254
AM_CONDITIONAL(OMPI_OMPIO_SUPPORT, test "$ompi_want_ompio" = "1")
255255

256+
AC_ARG_ENABLE([deprecate-mpif-h],
257+
[AS_HELP_STRING([--enable-deprecate-mpif-h],
258+
[Mark the mpif.h bindings as deprecated (default: enabled)])])
259+
256260
])dnl
257261

config/ompi_fortran_check_warning.m4

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
dnl -*- shell-script -*-
2+
dnl
3+
dnl Copyright (c) 2025 Stony Brook University. All rights reserved.
4+
dnl $COPYRIGHT$
5+
dnl
6+
dnl Additional copyrights may follow
7+
dnl
8+
dnl $HEADER$
9+
dnl
10+
11+
# Check whether the fortran compiler produces a warning when
12+
# it encounters a #warning directive
13+
14+
# OMPI_FORTRAN_CHECK_WARNING([action if found],
15+
# [action if not found])
16+
# ----------------------------------------------------
17+
AC_DEFUN([OMPI_FORTRAN_CHECK_WARNING],[
18+
AS_VAR_PUSHDEF([warning_var], [ompi_cv_fortran_warning])
19+
20+
AC_CACHE_CHECK([if Fortran compiler supports preprocessor warnings], warning_var,
21+
[
22+
# check if the compiler provides a proper #warning
23+
# some compilers (gfortran) do not show the warning if the file is found
24+
# through an include path, so create a temporary directory and include file
25+
OAC_VAR_SCOPE_PUSH(msg, dir)
26+
dir="tmp_includedir_$$"
27+
msg="This is a deprecated file"
28+
AS_MKDIR_P($dir)
29+
echo "#warning $msg" > $dir/deprecated.h
30+
31+
echo "! -*- fortran -*-
32+
program main
33+
implicit none
34+
include 'deprecated.h'
35+
end program main
36+
" > conftest.f
37+
AS_IF([${FC} ${FCFLAGS} -c -I$dir conftest.f 2>conftest.err >conftest.out],
38+
[ # compilation succeeded, check the produced output for the warning
39+
AS_IF([grep "$msg" conftest.err conftest.out >/dev/null 2>/dev/null],
40+
[AS_VAR_SET(warning_var, "yes")],
41+
[AS_VAR_SET(warning_var, "no (missing warning)")],)],
42+
[AS_VAR_SET(warning_var, "no (compilation failed)")])
43+
OPAL_VAR_SCOPE_POP
44+
rm -rf conftest.f conftest.err conftest.out $dir 2>/dev/null >/dev/null
45+
])
46+
AS_VAR_IF(warning_var, [yes], [$1], [$2])
47+
AS_VAR_POPDEF([warning_var])dnl
48+
])
49+

config/ompi_setup_fc.m4

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dnl Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
1616
dnl Copyright (c) 2009-2020 Cisco Systems, Inc. All rights reserved.
1717
dnl Copyright (c) 2015-2020 Research Organization for Information Science
1818
dnl and Technology (RIST). All rights reserved.
19+
dnl Copyright (c) 2025 Stony Brook University. All rights reserved.
1920
dnl $COPYRIGHT$
2021
dnl
2122
dnl Additional copyrights may follow
@@ -43,7 +44,7 @@ AC_DEFUN_ONCE([_OMPI_SETUP_FC_COMPILER],[
4344
# Fortran compilers (excluding the f77 compiler names) from AC's
4445
# default list of compilers and use it here. This is the main
4546
# reason we have an OMPI-ized version of the PROG_FC macro.
46-
AC_PROG_FC([gfortran f95 fort xlf95 ifort ifc efc pgfortran pgf95 lf95 f90 xlf90 pgf90 epcf90 nagfor nvfortran])
47+
AC_PROG_FC([gfortran flang-new flang f95 fort xlf95 ifort ifc efc pgfortran pgf95 lf95 f90 xlf90 pgf90 epcf90 nagfor nvfortran])
4748
FCFLAGS="$ompi_fcflags_save"
4849
OPAL_VAR_SCOPE_POP
4950
])

config/ompi_setup_mpi_fortran.m4

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dnl Copyright (c) 2016-2022 IBM Corporation. All rights reserved.
2121
dnl Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
2222
dnl Copyright (c) 2022 Triad National Security, LLC. All rights
2323
dnl reserved.
24+
dnl Copyright (c) 2025 Stony Brook University. All rights reserved.
2425
dnl $COPYRIGHT$
2526
dnl
2627
dnl Additional copyrights may follow
@@ -376,6 +377,20 @@ end program]])],
376377
[OMPI_FORTRAN_BUILD_SIZEOF=0])
377378
AC_SUBST(OMPI_FORTRAN_BUILD_SIZEOF)
378379

380+
OMPI_FORTRAN_SUPPORTS_WARNING="no"
381+
AS_IF([! test x"$enable_deprecate_mpif_h" = "xno"],
382+
[OMPI_FORTRAN_CHECK_WARNING([OMPI_FORTRAN_SUPPORTS_WARNING="yes"],
383+
[OMPI_FORTRAN_SUPPORTS_WARNING="no"])])
384+
AC_MSG_CHECKING([if we mark mpif.h bindings as deprecated])
385+
AS_IF([test "x$enable_deprecate_mpif_h" = "xyes" && test "$OMPI_FORTRAN_SUPPORTS_WARNING" = "no"],
386+
[AC_MSG_ERROR([Request to mark mpif.h as deprecated but Fortran compiler does not support warning preprocessor directive.])])
387+
AS_IF([test "x$enable_deprecate_mpif_h" != "xno" && test "$OMPI_FORTRAN_SUPPORTS_WARNING" = "yes"],
388+
[OMPI_FORTRAN_DEPRECATE_MPIF_H="#warning mpif.h has been deprecated since MPI 4.1. See MPI-4.1:19.1.4 for details."
389+
AC_MSG_RESULT([yes])],
390+
[OMPI_FORTRAN_DEPRECATE_MPIF_H=""
391+
AC_MSG_RESULT([no])])
392+
AC_SUBST(OMPI_FORTRAN_DEPRECATE_MPIF_H)
393+
379394
#--------------------------------------------
380395
# Fortran use mpi or use mpi_f08 MPI bindings
381396
#--------------------------------------------

ompi/include/mpif.h.in

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
! WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
5454
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5555
56+
@OMPI_FORTRAN_DEPRECATE_MPIF_H@
57+
5658
include 'mpif-config.h'
5759
include 'mpif-constants.h'
5860
include 'mpif-handles.h'

0 commit comments

Comments
 (0)