【问题标题】:Can't open module file using gfortran无法使用 gfortran 打开模块文件
【发布时间】: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


【解决方案1】:
  1. 更改程序的第一行以删除句点。

    program fhello_world_mpi
    

    Fortran 实体(例如程序、变量、常量、类型、)的名称中不允许使用句点 (.)。

  2. 试试 mpif90 文件名.F90。 MPI 功能通常作为“库”实现,对于要编译的代码,您需要提供额外信息:编译时.mod 文件的位置和链接时lib*.so 文件的位置。这是由编译器包装器 mpif90 实现的(通常,名称可能会有所不同):

    mpif90 -o fhello_world_mpi fhello_world_mpi.F90
    

    同样,要执行代码,您需要一个包装器:

    mpirun -np 2 ./fhello_world_mpi
    

    我假设文件名是 fhello_world_mpi.F90,根据需要更正。

一般来说,您不应该尝试手动使用这些标志,但如果您希望看到它们,您可以使用mpif90 -show。无论如何都需要mpirun,因为它会初始化并行环境。

【讨论】:

  • 需要第一点。对于“2”,我等待海报的更新,但你是对的,因为它不是答案。我通常从评论开始,以便在回复之前从发布者那里获得足够的信息。我会在这里等待反馈。
  • @PierredeBuyl 抱歉耽搁了。第一个错误随着句号的删除而消失了。第二个问题依然存在。我正在运行“gfortran 文件名.F90”。是否有任何其他步骤可以使 mpi 正常工作?
  • 试试mpif90 filename.F90MPI 功能通常作为“库”实现,对于要编译的代码,您需要提供额外信息:编译时.mod 文件的位置和链接时lib*.so 文件的位置。这是通过编译器包装器mpif90 实现的(通常,名称可能会有所不同)。同样,要执行代码,您需要一个包装器:mpirun -np 2 ./fhello_world_mpi
  • 您应该真正使用mpifortmpif90 包装器。除非您通过-o 选项指定可执行文件名称,否则生成的二进制文件将为a.out,因此您必须mpirun -np 2 ./a.out
  • 第一步:用mpif90 -o fhello_world_mpi fhello_world_mpi.F90编译。只有这样你才能运行mpirun -np 2 ./fhello_world_mpi。我假设文件名是fhello_world_mpi.F90,根据需要更正。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-17
  • 1970-01-01
  • 2015-06-09
  • 2019-01-06
相关资源
最近更新 更多