Fortran preprocessing converts `_/**/PRECISION` to problematic `_ sp`

Hi all,

I am currently getting installed on a new supercomputer and I encounter issues regarding pre-compilation.

Some subroutine names have a particular syntax finishing by _/**/PRECISION (ex: SUBROUTINE lbc_nfd_/**/PRECISION).
The comment /**/ is used to make sure the compiler does recognize that PRECISION is a key work that must be replaced by sp for instance.

However, the pre-compiler output in /BLD/ppsrc/nemo/ yields _/**/sp (ex: SUBROUTINE lbc_nfd_/**/sp).
During the compilation, mpiifort proceeds to further transform this to _ sp (ex: SUBROUTINE lbc_nfd_ sp), with a very problematic space…

I have compared with the pre-compiler output on Irene and the commentaries have already been removed (ex: SUBROUTINE lbc_nfd_sp).

Does anyone has already encountered this issue before ?

For information my arch file :

%CPP                 cpp
%FC                  mpiifort -c -cpp
%FCFLAGS             -g -i4 -r8 -O3 -fp-model precise -march=native -mtune=native -qoverride-limits -fno-alias -qopt-report=4 -align array64byte -traceback
%FFLAGS              %FCFLAGS
%LD                  mpiifort
%LDFLAGS             -lstdc++
%FPPFLAGS            -P -C -traditional -std=c99
%AR                  ar
%ARFLAGS             rs
%MK                  gmake
%USER_INC            -I/home_nfs/birrmanng/spack/opt/spack/linux-rhel8-x86_64/intel-19.1.3.304/netcdf-fortran-4.5.3-zmu2yi6jniz6jiwka53h32nyrcftq4kc/include/   -I/home_nfs/birrmanng/spack/opt/spack/linux-rhel8-x86_64/intel-19.1.3.304/netcdf-c-4.7.4-4ulkxcwpofqbo2mblkfqb2ah37fuoz3e/include/
%USER_LIB            -lnetcdf-fortran   -lnetcdf   -lhdf5

%CC                  mpiicc
%CFLAGS              -O3 -march=native -mtune=native

Nevermind, I found the bug.

The -C flag tells the precompiler not to remove comments removing it in %FPPFLAGS solves the problem.
The line here under works just fine :

%FPPFLAGS            -P -traditional -std=c99

Note that many arch files still have the -C flag, I would imagine that they produce the same error…

2 Likes

Thank you for sharing this, that’s really helped me out.

Hello,

I have been trying to compile the default configuration for NEMO4.2, but without success. The compiling crashes with reaching lbcnfd.f90 (see truncated error at the end of the message; I truncated all errors related to the fact that the subroutine isn’t recognized properly).
It looks like this subroutine name isn’t right, but I cannot figure out why. I did try with Intel2018 and Intel2020, same result.
I’m using the commit

Anyone has an idea of what could be wrong? I have no problem compiling Nemo4.0.x (or Nemo3.6) with the same arch file.

mpiifort -c -cpp -o lbcnfd.o -I/home/sm_jongr/MODELS/nemo_4.2.0/cfgs/ORCA2_ICE_PISCES/BLD/inc -i4 -r8 -O3 -fp-model precise -fno-alias -I/home/sm_jongr/MODELS/xios-2.5/inc -I/home/sm_jongr/SOFTWARES/netcdf4-combined/include -c /home/sm_jongr/MODELS/nemo_4.2.0/cfgs/ORCA2_ICE_PISCES/BLD/ppsrc/nemo/lbcnfd.f90
/home/sm_jongr/MODELS/nemo_4.2.0/cfgs/ORCA2_ICE_PISCES/BLD/ppsrc/nemo/lbcnfd.f90(96): error #5082: Syntax error, found ',' when expecting one of: =
   SUBROUTINE lbc_nfd_ sp( ptab, cd_nat, psgn, khls, kfld )
---------------------------------------^
/home/sm_jongr/MODELS/nemo_4.2.0/cfgs/ORCA2_ICE_PISCES/BLD/ppsrc/nemo/lbcnfd.f90(97): error #5082: Syntax error, found IDENTIFIER 'SP' when expecting one of: ) (
      TYPE(PTR_4d_ sp),  DIMENSION(:), INTENT(inout) ::   ptab        ! pointer of arrays on which apply the b.c.
-------------------^
/home/sm_jongr/MODELS/nemo_4.2.0/cfgs/ORCA2_ICE_PISCES/BLD/ppsrc/nemo/lbcnfd.f90(484): error #5082: Syntax error, found IDENTIFIER 'SP' when expecting one of: <END-OF-STATEMENT> ; <END-OF-FILE>
   END SUBROUTINE lbc_nfd_ sp
---------------------------^
/home/sm_jongr/MODELS/nemo_4.2.0/cfgs/ORCA2_ICE_PISCES/BLD/ppsrc/nemo/lbcnfd.f90(97): error #6818: The statement following a CONTAINS is not a function-stmt or a subroutine-stmt.
      TYPE(PTR_4d_ sp),  DIMENSION(:), INTENT(inout) ::   ptab        ! pointer of arrays on which apply the b.c.

Hi,
I get exactly the same errors as you get.
I tried several different arch-xxx.fcm but no luck at all.

You have a problem during the precompilation phase (with CPP) : its is replacing C-comments (/* something like that */) by a blank character. You end up having a blank between the _ and the sp and as you said the subroutine name isn’t right.
The solution is to play with the CPP options in your arch file. These options are defined in the line starting with

%FPPFLAGS  

You try to add/remove things like

-P -traditional -C

Thanks! With the following it works:

%FPPFLAGS            -P -traditional

Concerning pre-processing, we had the same issue with the NEC compiler (used as pre-processor). A work-around, found by Jens-Olaf Beismann from NEC Germany, is to use a GNU based compiler as pre-processor:

  • " gfortran -E " gives “subroutine lbc_nfd_sp” (The desired result.)
  • “gfortran -E -C” gives “subroutine lbc_nfd_/**/sp” (Gaston’s issue)
  • “nfort -fpp -E” gives “subroutine lbc_nfd_ sp” (with a space between “_” and “sp”)

Jens-Olaf thinks that we are relying on the assumption that any Fortran compiler uses a preprocessor which behaves GNU-like, which isn’t true (at least for nfort, which behaves C-like and the Intel 2016 version described above)

1 Like

I tried to build the latest code from master branch by using multiple version of Intel ifort compiler (2022.3, 2021.3, 2020.4) all failed with the same error in lbcnfd.f90 file:

mpiifort -c -cpp -o storng.o -I/nfs/pdx/home/aovsyann/codes/NEMO/nemo-master/cfgs/MY_GYRE_PISCES_linux_ifort_avx2/BLD/inc -i4 -r8 -O3 -ipo -fno-alias -march=core-avx2 -fp-model fast=2 -no-prec-div -no-prec-sqrt -align array64byte -fimf-use-svml=true -I/nfs/pdx/home/aovsyann/codes/NEMO/XIOS/trunk/inc -I/nfs/pdx/home/aovsyann/codes/MPAS/MPAS-Model-7.3/mpas_dependencies_latest/include -c /nfs/pdx/home/aovsyann/codes/NEMO/nemo-master/cfgs/MY_GYRE_PISCES_linux_ifort_avx2/BLD/ppsrc/nemo/storng.f90
/nfs/pdx/home/aovsyann/codes/NEMO/nemo-master/cfgs/MY_GYRE_PISCES_linux_ifort_avx2/BLD/ppsrc/nemo/lbcnfd.f90(105): error #5082: Syntax error, found ',' when expecting one of: =
   SUBROUTINE lbc_nfd_ sp( ptab, cd_nat, psgn, khls, kfld )
---------------------------------------^
/nfs/pdx/home/aovsyann/codes/NEMO/nemo-master/cfgs/MY_GYRE_PISCES_linux_ifort_avx2/BLD/ppsrc/nemo/lbcnfd.f90(106): error #5082: Syntax error, found IDENTIFIER 'SP' when expecting one of: ) (
      TYPE(PTR_4d_ sp),  DIMENSION(:), INTENT(inout) ::   ptab        ! pointer of arrays on which apply the b.c.
-------------------^
/nfs/pdx/home/aovsyann/codes/NEMO/nemo-master/cfgs/MY_GYRE_PISCES_linux_ifort_avx2/BLD/ppsrc/nemo/lbcnfd.f90(493): error #5082: Syntax error, found IDENTIFIER 'SP' when expecting one of: <END-OF-STATEMENT> ; <END-OF-FILE>
   END SUBROUTINE lbc_nfd_ sp
---------------------------^
/nfs/pdx/home/aovsyann/codes/NEMO/nemo-master/cfgs/MY_GYRE_PISCES_linux_ifort_avx2/BLD/ppsrc/nemo/lbcnfd.f90(106): error #6818: The statement following a CONTAINS is not a function-stmt or a subroutine-stmt.
      TYPE(PTR_4d_ sp),  DIMENSION(:), INTENT(inout) ::   ptab        ! pointer of arrays on which apply the b.c.

The previous NEMO versions (4.0.1 and 4.0) didn’t have this problem and can be built with ifort. Did anyone experience the same problem? I will appreciate your suggestions before I could escalate the issue to Intel compiler team.

Thanks,
Andrey Ovsyannikov, Ph.D.,
HPC Engineer, Intel Corporation

Same problem unsing an intel compiler. I found that removing -C from %FPPFLAGS worked but only after setting %CPP = cpp (was fpp).