5
votes

In order to compile MPI code in gfortran I have to use the syntax

include mpif.h

in my code instead of

use mpi

Several websites indicate that this syntax is for Fortran 77 however, I am using gfortran gcc version 4.7.2 (Debian 4.7.2-5) and mpfi90 for MPICH2 version 1.4.1p1.

The command line

mpif90 test1.f90 -o test1.exe

produces the following error

test1.f90:4.8: use mpi 1 Fatal Error: Parse error when checking module version for file 'mpi.mod' opened at (1)

test1.f90 (from Coursera course on HPC)

program test1

use mpi !(fails to compile)
implicit none

include 'mpif.h' !(this works)

integer :: ierr, numprocs, proc_num

call mpi_init(ierr)
call mpi_comm_size(MPI_COMM_WORLD, numprocs, ierr)
call mpi_comm_rank(MPI_COMM_WORLD, proc_num, ierr)

print *, 'Hello from Process number', proc_num, &
         ' of ', numprocs, ' processes'

call mpi_finalize(ierr)

end program test1
2
In what way does it "fail"?francescalus
Add more information and I will be happy to revert the downvote.Vladimir F
Did you build MPICH2 from source or install from an OS package?kraffenetti
The command line mpif90 test1.f90 -o test1.exe produces the following error test1.f90:4.8: use mpi 1 Fatal Error: Parse error when checking module version for file 'mpi.mod' opened at (1) This is what I mean by failing, should have said failed to compile.Ron
No, you should have included the full error message. "It failed to compile." tells nothing. Please edit the question to include that information.Vladimir F

2 Answers

8
votes

Another option I often encounter is when the Fortran compiler used to build the MPI library is not compatible with your current Fortran compiler. Then the problem is the incompatibility of the .mod files. Gfortran is more susceptible to this, than say Intel Fortran, because it changes the module format more often.

2
votes

Depending on how MPICH2 was compiled, perhaps the F90 interface wasn't built. That tends to happen depressingly often when using packages built by C-heads.