Fortran 90 and MPI error



我正在编写一个非常小的程序来了解MPI(MPICH实现)和Fortran90。不幸的是,使用" -np 2"执行时,代码未正确运行。

这是代码:

PROGRAM main
    USE MPI
    IMPLICIT none
    INTEGER :: ierr, npe, mynpe
    INTEGER :: istatus(MPI_STATUS_SIZE)
    REAL :: aa
    CALL MPI_INIT(ierr)
    CALL MPI_Comm_size(MPI_COMM_WORLD, npe, ierr)
    CALL MPI_Comm_rank(MPI_COMM_WORLD, mynpe, ierr)
    IF (mynpe == 0) THEN
        READ(*,*) aa
        CALL  MPI_Send(aa, 1, MPI_REAL, 1, 99, MPI_COMM_WORLD, ierr)
    ELSE IF (mynpe == 1) THEN
        CALL MPI_Recv(aa, 1, MPI_REAL, 0, 99, MPI_COMM_WORLD, istatus, ierr)
        WRITE(*,*) "Ho ricevuto il numero ", aa
    END IF
    CALL MPI_FINALIZE(ierr)
END PROGRAM

我正在用mpif90 mpi_2.f90 -o output编译它,当我使用mpirun -np 2 output执行时,我会收到以下错误:

At line 14 of file mpi_2.f90 (unit = 5, file = 'stdin')
Fortran runtime error: End of file

壳仍然等待输入,如果我插入一个数字(例如11),我会得到以下输出:

11
Fatal error in MPI_Send: Invalid rank, error stack:
MPI_Send(173): MPI_Send(buf=0xbff4783c, count=1, MPI_REAL, dest=1, tag=99, MPI_COMM_WORLD) failed
MPI_Send(98).: Invalid rank has value 1 but must be nonnegative and less than 1
--------------------------------------------------------------------------
mpirun noticed that the job aborted, but has no info as to the process
that caused that situation.
--------------------------------------------------------------------------

感谢您的所有帮助!

在您的情况下混合了两个不同的MPI实现。运行时MPI环境来自不同的实现,该实现用来编译程序,因此两个过程都以MPI单例的方式行为,即它们每个人都形成了单独的MPI_COMM_WORLD Communicator,并在其中成为级别的0。结果,条件的第一个分支在两个过程中都执行。另一方面,mpirun仅在所有其他过程都将其标准输入关闭或连接到/dev/null时,才能执行输入重定向。MPI_SEND出于相同的原因失败 - 在每个MPI过程的单例宇宙中,没有等级1

这种行为的最常见原因是mpirunmpif90来自不同的MPI库。在您的情况下,您将MPICH与开放式MPI混合。确实,以下错误消息:

MPI_Send(173): MPI_Send(buf=0xbff4783c, count=1, MPI_REAL, dest=1, tag=99, MPI_COMM_WORLD) failed
MPI_Send(98).: Invalid rank has value 1 but must be nonnegative and less than 1

是mpich的误差格式。因此mpif90来自mpich。

但是下一个错误消息:

--------------------------------------------------------------------------
mpirun noticed that the job aborted, but has no info as to the process
that caused that situation.
--------------------------------------------------------------------------

是OpenRTE MPI的OpenRTE框架使用的误差格式。因此,mpirun来自开放MPI,而不是来自MPICH。

如果您已经为MPICH安装了开发包,则可能会发生这种情况,以便它提供mpiccmpif90等,但随后您已经为Open MPI安装了一个运行时软件包。确保您只安装了一种MPI的软件包。如果您从源头编译了mpich,请确保通往其二进制文件的路径是$PATH的第一个元素。

最新更新