【发布时间】:2019-10-31 18:51:50
【问题描述】:
我正在使用 gfortran 运行 .F90 代码,但出现两个错误,
program fhello_world_mpi.F90
1
Error: Invalid form of PROGRAM statement at (1)
fhello_world_mpi.F90:2:6:
use mpi
1
Fatal Error: Can't open module file ‘mpi.mod’ for reading at (1):
No such file or directory
compilation terminated.
我检查了mpi安装库(系统中存在mpich、openmpi库)。
程序如下:
program fhello_world_mpi.F90
use mpi
implicit none
integer ( kind = 4 ) error
integer ( kind = 4 ) id
integer p
character(len=MPI_MAX_PROCESSOR_NAME) :: name
integer clen
integer, allocatable :: mype(:)
real ( kind = 8 ) wtime
call MPI_Init ( error )
call MPI_Comm_size ( MPI_COMM_WORLD, p, error )
call MPI_Comm_rank ( MPI_COMM_WORLD, id, error )
if ( id == 0 ) then
wtime = MPI_Wtime ( )
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'HELLO_MPI - Master process:'
write ( *, '(a)' ) ' FORTRAN90/MPI version'
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' An MPI test program.'
write ( *, '(a)' ) ' '
write ( *, '(a,i8)' ) ' The number of processes is ', p
write ( *, '(a)' ) ' '
end if
call MPI_GET_PROCESSOR_NAME(NAME, CLEN, ERROR)
write ( *, '(a)' ) ' '
write ( *, '(a,i8,a,a)' ) ' Process ', id, ' says "Hello, world!" ',name(1:clen)
call MPI_Finalize ( error )
end program
更新1
删除句号解决了第一个问题。 我使用了这些命令:
mpif90 fhello_world_mpi.F90 和
mpirun -np 2 ./fhello_world_mpi
它给出了以下错误:
mpirun was unable to launch the specified application as it could not
access or execute an executable:
Executable: ./fhello_world_mpi
Node: user
while attempting to start process rank 0.
2 total processes failed to start``
更新2 有效。 跑命令:
mpif90 -o fhello_world_mpi fhello_world_mpi.F90
mpirun -np 2 ./fhello_world_mpi
输出
HELLO_MPI - Master process:
FORTRAN90/MPI version
An MPI test program.
The number of processes is 2
Process 1 says "Hello, world!" user
Process 0 says "Hello, world!" user
【问题讨论】:
-
你能编辑一下,让我们看看你用来编译代码的命令吗?
标签: compiler-errors compilation fortran mpi gfortran