ompi icon indicating copy to clipboard operation
ompi copied to clipboard

MPI_Sizeof should be deprecated

Open hppritcha opened this issue 3 years ago • 6 comments

The fortran-only MPI_Sizeof function has been deprecated in the MPI 4.0 standard.

hppritcha avatar Aug 03 '21 16:08 hppritcha

@hppritcha Is there a "deprecated" pragma for Fortran compilers (like we have for C compilers / mpi.h)?

jsquyres avatar Aug 03 '21 16:08 jsquyres

don't know. need to investigate.

hppritcha avatar Aug 03 '21 18:08 hppritcha

Meant to follow-up from past chat on this item. I did quick look at GCC docs and found following link for gfortran deprecated. Looks like it is like w/ C compilers.

  • https://gcc.gnu.org/onlinedocs/gfortran/ATTRIBUTES-directive.html

This would obviously GCC specific, but maybe good enough for start. I'm not sure how these attributes get plumbed through into the mpi/fortran dir.

naughtont3 avatar Sep 09 '21 19:09 naughtont3

I tried using the DEPRECATED attribute in similar manner as used in this f90 test, contig.f90, but I'm either doing something wrong or my gfortan does not support (v5.5.0). Adding pointer here for someone who knows Fortran stuff. HTH.

naughtont3 avatar Sep 10 '21 13:09 naughtont3

Ref: https://github.com/mpi-forum/mpi-issues/issues/51

jjhursey avatar Aug 09 '22 18:08 jjhursey

I have been researching this with the intent of implementing a check for gfortran and XL Fortran, I have discovered the following:

  • There is a directive that can be used with gfortran, !gcc$ attributes deprecated :: MPI_Sizeof
  • This directive is only recognized with gfortran 11.0.0 or later. Compilng with older gfortran compilers results in a syntax error for the directive.
  • At least at the XL 16.1.0 version, I cannot find any directive or attribute that can be used to flag MPI_Sizeof as deprecated.
  • If I code the above gfortran directive and compile the test program with XL Fortran, specifying the -qdirective='gcc$' compiler option, then the compile fails, flagging the directive with a syntax error. I get the same syntax error if I specify attributes other than 'deprecated', so the compiler may not recognize attribues directives at all.
  • So I think I can implement this, but only for gfortran 11.0.0 and later.

I have been experimenting with an implementation and came up with the following approach:

  • There is a script, ompi/mpi/fortran/base/gen-mpi-sizeof.pl that is used to generate headers containing declarations of all the MPI_Sizeof variants needed to support all Fortran data types and array shapes, as well as to generate Fortran source files containing the implementation of these functions.
  • The directives can only go in the header files, not the source files.
  • Deal with this by adding a new option to the script, be used when building a header, and set that option in the Makefile.in logic that invokes the generator script. If the option is not set, then the script does nothing more than what it does today.
  • Furthermore, the script should generate the directive only when MPI_VERSION is >= 4, the compiler is gfortran, and the gfortran compiler properly recognizes the directive.
  • MPI_VERSION appears only in mpi.h and not in any configure logic. So, to check MPI version, the generator script needs to compile a small C program which compiles if MPI_VERSION is >+ 4 and fails otherwise.
  • Check for gfortran by looking at the FC environment variable.
  • If the compiler is gfortran, then compile a small Fortran program containing a valid '!gcc$ attributes deprecated' directive. If the directive is recognized, then the compile will be successful.
  • If all of the above checks are successful, then add the directives to the header snippet for each variant of the MPI_Sizeof function.
  • This approach generates a mpif-sizeof.h header and the mpi.mod and mpi_f08.mod files that all flag MPI_Sizeof function calls as deprecated.

If someone builds OpenMPI at MPI_VERSION 4 or later using gfortran as the Fortran compiler, then

  • Any Fortran MPI program compiled with gfortran must be compiled with gfortran 11.0.0 or later, or syntax errors will result. This may happen only for programs that call MPI_Sizeof. I haven't verified that.
  • Other Fortran compilers, such as XL Fortran with the -qdirective='gcc$' option may issue syntax errors.

Maybe the checking in the generator script could be limited to check only for MPI_VERSION >= 4 and not perform the checks for gfortran. I'm not sure if that would result in problems for anyone trying to build OpenMPI with something other than gfortran.

I'm posting this to find out if anyone sees a problem with this approach, or has a reason why it shouldn't be done.

drwootton avatar Aug 10 '22 20:08 drwootton

I think that approach is decent from my understanding of the Fortran infrastructure in OMPI (which is limited). The only modification I would suggest is:

  1. Let's move the MPI_VERSION/MPI_SUBVERSION values into ${topdir}/VERSION. This will allow us to have these available in the automake environment so they will be available to the ompi/mpi/fortran/base/gen-mpi-sizeof.pl.
    • An alternative here is to grep MPI_VERSION ${topdir}/ompi/include/c/mpi.h.in inside the perl script. Which would work in the mean time.
  2. For the testing of gfortran 11.0.0 or later and qdirective we could add a configure test and then set an automake variable that the perl script can pickup. This would be slightly more inline with how we do other checks - just in case we need this information elsewhere someday.
    • In the short term, you can do as you describe and just have the check inside the perl script.

For (1) try to use the grep technique to grab the MPI_VERSION instead of a small C program.

For (2) add the check to the perl script as you describe. We can refactor it into a configure level check once you have it working.

It's too bad that the deprecated warning will only happen for gfortran, but I think a best effort is good enough for a user-level warning. If we can figure out how to do this with other compilers, then this effort will provide enough breadcrumbs for someone to add the functionality.

jjhursey avatar Aug 12 '22 14:08 jjhursey

Here are some compiler notes for reference.

  • Deprecated attribute documentation : https://gcc.gnu.org/onlinedocs/gfortran/ATTRIBUTES-directive.html
  • GCC 11 release series : https://gcc.gnu.org/gcc-11/
  • GCC 11 Changelog : https://gcc.gnu.org/gcc-11/changes.html#fortran
  • Assorted gfortran levels shipped with OS distros:
    • RHEL/UBI 8.6 ships gfortran 8.5.0
    • RHEL/UBI 9.0 ships gfortran 11.2.1
    • Fedora release 36 ships gfortran 12.1.1

Example program

program main
!GCC$ ATTRIBUTES DEPRECATED :: x
  real*4 x
  x = 123.4
  print *,x
end program

Example compile where supported

REHL 9.0

Note: Warning can be disabled by passing -Wno-deprecated-declarations to gfortran

shell$ gfortran --version
GNU Fortran (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

shell$  gfortran /testing/test-alt.f90 
/testing/test-alt.f90:4:2:

    4 |   x = 123.4
      |  1
Warning: Using variable ‘x’ at (1) is deprecated [-Wdeprecated-declarations]
/testing/test-alt.f90:5:10:

    5 |   print *,x
      |          1
Warning: Using variable ‘x’ at (1) is deprecated [-Wdeprecated-declarations]
shell$ ./a.out 
   123.400002    

Example compile where not supported

RHEL 8.6

shell$ gfortran --version
GNU Fortran (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

shell$ gfortran /testing/test-alt.f90 
/testing/test-alt.f90:2:27:

 !GCC$ ATTRIBUTES DEPRECATED :: x
                           1
Error: Unknown attribute in !GCC$ ATTRIBUTES statement at (1)

jjhursey avatar Aug 16 '22 16:08 jjhursey

@drwootton PR #10683 will give you two Makefile level variables: MPI_VERSION and MPI_SUBVERSION that can be used in places like here to adjust the Perl script based on the MPI Version

jjhursey avatar Aug 17 '22 21:08 jjhursey

PR #10704 is probably as good as we will get with a deprecation warning for this functionality. It has been merged into main

jjhursey avatar Sep 06 '22 19:09 jjhursey