无法用gfortran打开模块文件。

问题描述 投票:-1回答:1

我使用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

Update1

去掉句号就解决了第一个问题.我用这些命令。

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个回答
3
投票
  1. 修改程序的第一行,删除句号。

    program fhello_world_mpi
    

    句号 (.)不允许出现在Fortran实体的名称中(如程序、变量、常量、类型。).

  2. 试试mpif90文件名.F90。试试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 反正是需要的,因为它初始化了并行环境。

© www.soinside.com 2019 - 2024. All rights reserved.