gfortran: Illegal preprocessor directive & Invalid character/non-numeric character compile errors

11,448

You're definitely compiling this code in a non-standard way. The usual way to compile f77 or f90 code with mpi is to use the programs mpif77 or mpif90 which wrap around the compiler used to build that particular version of MPI.

For example, on my laptop (using OpenMPI compiled with gfortran/gcc), the command mpif77 is roughly equivalent to:

gfortran -I/usr/local/include -L/usr/local/lib -lmpi_f77 -lmpi -lopen-rte -lopen-pal -lutil

(I got this information via mpif90 -showme -- I don't know if that commandline option is part of the MPI standard so it might not work for you).

to compile your code, I would try something like this:

mpif77 -O0 -Wall -c ./TestData/common/timers.f -o timers.o

Since there are no other files to be included, it doesn't really make sense to increase you compilers include path using additional -I flags -- you just increase the liklihood that you'll accidentally find the wrong header file ;).

Perhaps there's a file 'mpif.h' in either your current directory or in /home/stephen/trunk/include which is getting picked when it shouldn't. (It looks like you might be seeing a C header since /* is the start of a C comment -- although I can't see why a c header file would be called 'mpif.h').

Share:
11,448
SteVwonder
Author by

SteVwonder

I am a Computer Science PhD Student at the University of Delaware. My research includes: Creating I/O-aware scheduling algorithms for HPC clusters Auto-tuning of the ADIOS I/O library Modeling, creation and profiling of I/O kernels based on real I/O patterns of scientific applications

Updated on June 04, 2022

Comments

  • SteVwonder
    SteVwonder almost 2 years

    So I'm trying to use the NAS benchmarks for performance testing on a particular MPI implementation. So I went to compile the fortran code and I'm hitting a barrier. Whenever I enter this command to compile:

    gfortran -O0 -Wall -I/home/stephen/trunk/include -I.  -c ./TestData/common/timers.f
    

    I get these compiler errors:

    Warning: mpif.h:2: Illegal pdreprocessor directive
    Warning: mpif.h:3: Illegal preprocessor directive
    Warning: mpif.h:4: Illegal preprocessor directive
    Warning: mpif.h:5: Illegal preprocessor directive
    Warning: mpif.h:6: Illegal preprocessor directive
    Warning: mpif.h:7: Illegal preprocessor directive
    Warning: mpif.h:8: Illegal preprocessor directive
    Warning: mpif.h:9: Illegal preprocessor directive
    Warning: mpif.h:12: Illegal preprocessor directive
    Warning: mpif.h:13: Illegal preprocessor directive
    Warning: mpif.h:14: Illegal preprocessor directive
    Warning: mpif.h:2: Illegal preprocessor directive
    Warning: mpif.h:3: Illegal preprocessor directive
    Warning: mpif.h:4: Illegal preprocessor directive
    Warning: mpif.h:5: Illegal preprocessor directive
    Warning: mpif.h:6: Illegal preprocessor directive
    Warning: mpif.h:7: Illegal preprocessor directive
    Warning: mpif.h:8: Illegal preprocessor directive
    Warning: mpif.h:9: Illegal preprocessor directive
    Warning: mpif.h:12: Illegal preprocessor directive
    Warning: mpif.h:13: Illegal preprocessor directive
    Warning: mpif.h:14: Illegal preprocessor directive
    mpif.h:1.1:
        Included at ./TestData/common/timers.f:30:
    
    /*
     1
    Error: Non-numeric character in statement label at (1)
    mpif.h:1.2:
        Included at ./TestData/common/timers.f:30:
    
    /*
      1
    Error: Invalid character in name at (1)
    mpif.h:1.1:
        Included at ./TestData/common/timers.f:50:
    
    /*
     1
    Error: Non-numeric character in statement label at (1)
    mpif.h:1.2:
        Included at ./TestData/common/timers.f:50:
    
    /*
      1
    Error: Invalid character in name at (1)
    make: *** [cg] Error 1
    

    Here is the timers.f code that is erring (lines 30 & 50 are the include lines):

    c---------------------------------------------------------------------                                                                                                                                         
    c---------------------------------------------------------------------                                                                                                                                         
          subroutine timer_start(n)
    c---------------------------------------------------------------------                                                                                                                                         
    c---------------------------------------------------------------------                                                                                                                                         
          implicit none
          integer n
          include 'mpif.h'
          double precision start(64), elapsed(64)
          common /tt/ start, elapsed
          start(n) = MPI_Wtime()
          return
          end
    c---------------------------------------------------------------------                                                                                                                                         
    c---------------------------------------------------------------------                                                                                                                                         
          subroutine timer_stop(n)
    c---------------------------------------------------------------------                                                                                                                                         
    c---------------------------------------------------------------------                                                                                                                                         
          implicit none
          integer n
          include 'mpif.h'
          double precision start(64), elapsed(64)
          common /tt/ start, elapsed
          double precision t, now
          now = MPI_Wtime()
          t = now - start(n)
          elapsed(n) = elapsed(n) + t
          return
          end
    

    Any ideas? I have tried all kinds of command line args for gfortran to try and get it to do different types of pre-processing (most of these were done blindly, I do admit). The weird thing to me is that the compiler is erring on the non-numeric characters /* which are nowhere in my code, so I'm pretty lost.

    Thanks!