sup*_*mum 1 fortran compiler-errors compilation mpi gfortran
我正在使用 gfortran 运行 .F90 代码,但出现两个错误,
\n\nprogram fhello_world_mpi.F90\n 1\nError: Invalid form of PROGRAM statement at (1)\nfhello_world_mpi.F90:2:6:\n\n use mpi\n 1\n Fatal Error: Can\'t open module file \xe2\x80\x98mpi.mod\xe2\x80\x99 for reading at (1): \n No such file or directory\n compilation terminated.\nRun Code Online (Sandbox Code Playgroud)\n\n我检查了mpi安装库(系统中存在mpich、openmpi库)。
\n\n程序如下:
\n\nprogram fhello_world_mpi.F90\n use mpi\n implicit none\n integer ( kind = 4 ) error\n integer ( kind = 4 ) id\n integer p\n character(len=MPI_MAX_PROCESSOR_NAME) :: name\n integer clen\n integer, allocatable :: mype(:)\n real ( kind = 8 ) wtime\n\n call MPI_Init ( error )\n call MPI_Comm_size ( MPI_COMM_WORLD, p, error )\n call MPI_Comm_rank ( MPI_COMM_WORLD, id, error )\n if ( id == 0 ) then\n wtime = MPI_Wtime ( )\n\n write ( *, \'(a)\' ) \' \'\n write ( *, \'(a)\' ) \'HELLO_MPI - Master process:\'\n write ( *, \'(a)\' ) \' FORTRAN90/MPI version\'\n write ( *, \'(a)\' ) \' \'\n write ( *, \'(a)\' ) \' An MPI test program.\'\n write ( *, \'(a)\' ) \' \'\n write ( *, \'(a,i8)\' ) \' The number of processes is \', p\n write ( *, \'(a)\' ) \' \'\n end if\n call MPI_GET_PROCESSOR_NAME(NAME, CLEN, ERROR)\n write ( *, \'(a)\' ) \' \'\n write ( *, \'(a,i8,a,a)\' ) \' Process \', id, \' says "Hello, world!" \',name(1:clen)\n\n call MPI_Finalize ( error )\nend program\nRun Code Online (Sandbox Code Playgroud)\n\n更新1
\n\n删除句点解决了第一个问题。\n我使用了以下命令:
\n\nmpif90 fhello_world_mpi.F90和
mpirun -np 2 ./fhello_world_mpi
它给出了以下错误:
\n\nmpirun was unable to launch the specified application as it could not \naccess or execute an executable:\n\nExecutable: ./fhello_world_mpi\nNode: user\n\n while attempting to start process rank 0.\nRun Code Online (Sandbox Code Playgroud)\n\n 2 total processes failed to start``\nRun Code Online (Sandbox Code Playgroud)\n\n更新 2 \n它有效。\n运行命令:
\n\nmpif90 -o fhello_world_mpi fhello_world_mpi.F90
mpirun -np 2 ./fhello_world_mpi
输出
\n\nHELLO_MPI - Master process:\n FORTRAN90/MPI version\n\n An MPI test program.\n\n The number of processes is 2\n\n\n\n Process 1 says "Hello, world!" user\n Process 0 says "Hello, world!" user\nRun Code Online (Sandbox Code Playgroud)\n
更改程序的第一行以删除句点。
program fhello_world_mpi
Run Code Online (Sandbox Code Playgroud)
Fortran 实体(例如程序、变量、常量、类型等.)的名称中不允许使用句点 ( ) 。
尝试 mpif90 文件名.F90。MPI功能通常作为“库”实现,对于要编译的代码,您需要提供额外的信息:编译时文件的位置以及链接时文件的位置。这是通过编译器包装器 mpif90 实现的(通常,名称可能会有所不同):.modlib*.so
mpif90 -o fhello_world_mpi fhello_world_mpi.F90
Run Code Online (Sandbox Code Playgroud)
同样,要执行代码,您需要一个包装器:
mpirun -np 2 ./fhello_world_mpi
Run Code Online (Sandbox Code Playgroud)
我假设文件名是 fhello_world_mpi.F90,根据需要进行正确设置。
一般来说,您不应尝试手动使用这些标志,但如果您希望查看它们,可以使用mpif90 -show. mpirun无论如何都是需要的,因为它初始化了并行环境。