Skip to content

Fix Fortran preprocessor issue with CPPFLAGS #9899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2022

Conversation

jjhursey
Copy link
Member

@jjhursey jjhursey commented Jan 20, 2022

  • Some C and Fortran compilers use different preprocessors. If one preprocessor
    accepts -iquote and the other does not then a compiler error will occur
    when Open MPI tries to use it.
    • Nvidia/PGI v22.1-0 is one such. The C compiler supports -iquote
      while the Fortran compiler does not.
  • Similar to PR Fortran fixes #7265 we need to clear the CPPFLAGS and AM_CPPFLAGS

Signed-off-by: Joshua Hursey [email protected]

@jjhursey jjhursey linked an issue Jan 20, 2022 that may be closed by this pull request
@jjhursey
Copy link
Member Author

bot:aws:retest

@jjhursey
Copy link
Member Author

jjhursey commented Jan 20, 2022

Example output with Nvidia/PGI compiler v22.1-0:

checking for pgcc option to add a directory only to the search path for the quote form of include... "-iquote"
checking for pgfortran option to see if it also supports -iquote form of include... No. "-I" will be used instead

Example with gcc10:

checking for gcc-10 option to add a directory only to the search path for the quote form of include... "-iquote"
checking for gfortran-10 option to see if it also supports -iquote form of include... Yes. "-iquote" accepted

This will need to be cherry-picked to the v5.0.x branch.
The v4.0.x and v4.1.x branches do not have this logic. Additionally, PRTE and OpenPMIx do not need this fix even though they have the -iquote logic they do contain any Fortran code so are not impacted.

@hjelmn
Copy link
Member

hjelmn commented Jan 20, 2022

Does this skip the check for the --disable-mpi-fortran case? Sometimes I have a fortran compiler on the system but will never use it.

@jjhursey
Copy link
Member Author

It looks like if you pass --disable-mpi-fortran it still runs the check with the fortran compiler. I'll work on adding an exception.

@jjhursey
Copy link
Member Author

I just pushed a fix for the --disable-mpi-fortran case where it will skip the check against the Fortran preprocessor.

 ./configure --prefix=/workspace/exports/ompi CC=pgcc CXX=pgc++ FC=pgfortran --disable-cuda --disable-nvml --with-cuda=no --disable-mpi-fortran
...
checking for pgcc option to add a directory only to the search path for the quote form of include... "-iquote"
checking for the C compiler vendor... portland group
...
Open MPI configuration:
-----------------------
Version: 5.1.0a1
Build MPI C bindings: yes
Build MPI Fortran bindings: no
Build MPI Java bindings (experimental): no
Build Open SHMEM support: false (no spml)
Debug build: no
Platform file: (none)
...

@jjhursey
Copy link
Member Author

Note that once this fix gets into master and v5 I can update the IBM CI build boxes to the latest Nvidia/PGI compilers. Without this fix they fail to build per PR #9716

@jsquyres
Copy link
Member

This looks tangentially related to #9890 in that it's an issue about the C and Fortran compiler flags.

@jsquyres
Copy link
Member

jsquyres commented Jan 23, 2022

@jjhursey This feels very much like #7253 (issue) and #7265 (PR to fix it). E.g., in the commit message for ab398f4, I stated:

Automake's Fortran compilation rules inexplicably use CPPFLAGS and AM_CPPFLAGS.

Did we miss adding something like https://github.com/open-mpi/ompi/blob/master/ompi/mpi/fortran/use-mpi-f08/Makefile.am#L29-L34 somewhere? Can you cite the specific problem that you're solving -- e.g., are you seeing CPPFLAGS being used somewhere in the code base to compile Fortran code?

@jjhursey
Copy link
Member Author

The error is:

make[2]: Entering directory '/opt/mpi_src/ompi/mpiext/ftmpi/use-mpi-f08'
  PPFC     comm_revoke_f08.lo
pgfortran-Error-Unknown switch: -iquote../../../..
make[2]: *** [Makefile:1464: comm_revoke_f08.lo] Error 1
make[2]: Leaving directory '/opt/mpi_src/ompi/mpiext/ftmpi/use-mpi-f08'
make[1]: *** [Makefile:2711: all-recursive] Error 1
make[1]: Leaving directory '/opt/mpi_src/ompi'
make: *** [Makefile:1477: all-recursive] Error 1

A bit more detail:

shell$ make V=1
/bin/sh ../../../../libtool  --tag=FC   --mode=compile pgfortran -DHAVE_CONFIG_H -I. -I../../../../opal/include -I../../../../ompi/include -I../../../../oshmem/include -I../../../../ompi/mpiext/cuda/c   -iquote../../../..  -I/opt/mpi_src/3rd-party/libevent-2.1.12-stable -I/opt/mpi_src/3rd-party/libevent-2.1.12-stable/include -I/opt/mpi_src/3rd-party/hwloc-2.7.0/include -I/opt/mpi_src/3rd-party/hwloc-2.7.0/include -I/opt/mpi_src/3rd-party/openpmix/include -I/opt/mpi_src/3rd-party/openpmix/include -I../../../../ompi/mpi/fortran/use-mpi -I../../../../ompi/mpi/fortran/use-mpi-f08/mod -I../../../.. -I../../../..   -c -o comm_revoke_f08.lo comm_revoke_f08.F90
libtool: compile:  pgfortran -DHAVE_CONFIG_H -I. -I../../../../opal/include -I../../../../ompi/include -I../../../../oshmem/include -I../../../../ompi/mpiext/cuda/c -iquote../../../.. -I/opt/mpi_src/3rd-party/libevent-2.1.12-stable -I/opt/mpi_src/3rd-party/libevent-2.1.12-stable/include -I/opt/mpi_src/3rd-party/hwloc-2.7.0/include -I/opt/mpi_src/3rd-party/hwloc-2.7.0/include -I/opt/mpi_src/3rd-party/openpmix/include -I/opt/mpi_src/3rd-party/openpmix/include -I../../../../ompi/mpi/fortran/use-mpi -I../../../../ompi/mpi/fortran/use-mpi-f08/mod -I../../../.. -I../../../.. -c comm_revoke_f08.F90  -fpic -o .libs/comm_revoke_f08.o
pgfortran-Error-Unknown switch: -iquote../../../..
make: *** [Makefile:1464: comm_revoke_f08.lo] Error 1

Is the solution roughly this to clear the CPPFLAGS and AM_CPPFLAGS flags before building this section of code? Is that preferred over the configure check in this PR?

@jjhursey
Copy link
Member Author

I tried the alternative approach and it worked fine.

diff --git a/ompi/mpiext/ftmpi/use-mpi-f08/Makefile.am b/ompi/mpiext/ftmpi/use-mpi-f08/Makefile.am
index d06c0aa6..85d1b778 100644
--- a/ompi/mpiext/ftmpi/use-mpi-f08/Makefile.am
+++ b/ompi/mpiext/ftmpi/use-mpi-f08/Makefile.am
@@ -13,6 +13,14 @@
 # $HEADER$
 #
 
+# Note that Automake's Fortran-buidling rules uses CPPFLAGS and
+# AM_CPPFLAGS.  This can cause weirdness (e.g.,
+# https://github.com/open-mpi/ompi/issues/7253 and
+# https://github.com/open-mpi/ompi/issues/9716).  Let's just zero
+# those out and rely on AM_FCFLAGS.
+CPPFLAGS =
+AM_CPPFLAGS =
+
 # This file builds the use_mpi_f08-based bindings for MPI extensions.  It
 # is optional in MPI extensions.

I went ahead and added the change above to this PR as a second commit. That'll make it easier to pick the one the community wants.

I'm happy with either or both. I'm just looking for some guidance from the community on their preference. Let me know and I'll update the PR.

@bwbarrett
Copy link
Member

I'd prefer the second approach (mucking with CPPFLAGS) for two reasons: 1) we already do it elsewhere and 2) I'm worried about the corner cases that led to -iquote in the first place biting us in the butt again.

@jsquyres
Copy link
Member

@jjhursey While you have the hood up, could you also add the same fix to ompi/mpiext/example/use-mpi-f08/Makefile.am? I'm guessing that we ended up in this situation because the good ftmpi folks copied from the example, and we didn't fix the example back in #7265.

@jjhursey
Copy link
Member Author

Sure. I'll make that adjustment and update this PR in a bit.

 * Some C and Fortran compilers use different preprocessors. If one preprocessor
   accepts `-iquote` and the other does not then a compiler error will occur
   when Open MPI tries to use it.
   - Nvidia/PGI v22.1-0 is one such. The C compiler supports `-iquote`
     while the Fortran compiler does not.
 * Similar to PR open-mpi#7265 we need to clear the `CPPFLAGS` and `AM_CPPFLAGS`

Signed-off-by: Joshua Hursey <[email protected]>
@jjhursey jjhursey changed the title Fix iquote check for different C and Fotran preprocessors Fix Fortran preprocessor issue with CPPFLAGS Jan 24, 2022
@jjhursey
Copy link
Member Author

@jsquyres @bwbarrett I made those changes. This is ready for re-review. Thanks!

@jjhursey jjhursey merged commit fcc41d7 into open-mpi:master Jan 24, 2022
@jjhursey jjhursey deleted the fix-iquote-check branch January 24, 2022 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nvfortran-Error-Unknown switch: -iquote../../../../../..
4 participants