Why does 'use mpi' fail with mpif90
Asked Answered
O

2

5

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
Orion answered 12/5, 2014 at 4:21 Comment(6)
In what way does it "fail"?Recurvate
Add more information and I will be happy to revert the downvote.Tautomer
Did you build MPICH2 from source or install from an OS package?Cabinetwork
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.Orion
No, you should have included the full error message. "It failed to compile." tells nothing. Please edit the question to include that information.Tautomer
MPICH2 was installed using Synaptic which provides a standard Ubuntu selected version of MPICH2.Orion
C
8

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.

Charmainecharmane answered 12/5, 2014 at 13:40 Comment(3)
It appears that several of you would recommend building the MPI library from source using my Gfortran. I'll give that a try.'Orion
That does actually help. Or make sure you are using the gfortran version that was used for the build of the MPI library. Your cluster sysadmin will help you with that.Tautomer
Ha ha! I'm the cluster admin! Actually just an old retired engineer with a couple of pc's trying to learn something new. Thanks to all for improving my question!Orion
E
2

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.

Embouchure answered 12/5, 2014 at 12:0 Comment(1)
Fortran bindings are enabled by default when you build MPICH from source, as long as a Fortran compiler is detected.Cabinetwork

© 2022 - 2024 — McMap. All rights reserved.