Fortran 90和MPI错误

Fortran 90和MPI错误,mpi,fortran90,mpich,Mpi,Fortran90,Mpich,我正在编写一个非常小的程序来理解MPI(MPICH实现)和Fortran 90。不幸的是,当使用“-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_si

我正在编写一个非常小的程序来理解MPI(MPICH实现)和Fortran 90。不幸的是,当使用“-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输出编译它,当我使用
mpirun-np 2输出执行它时,我得到以下错误:

At line 14 of file mpi_2.f90 (unit = 5, file = 'stdin')
Fortran runtime error: End of file
shell仍在等待输入,如果我插入一个数字(例如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\u COMM\u WORLD
通信器,并在其中变为秩
0
。因此,条件的第一个分支在两个进程中都执行。在另一端,
mpirun
仅在所有其他进程关闭标准输入或连接到
/dev/null
时,才执行到第一个进程的输入重定向
MPI\u SEND
由于同样的原因失败-在每个MPI进程的单例世界中没有秩
1

此类行为最常见的原因是
mpirun
mpif90
来自不同的MPI库。在您的例子中,您将MPICH与openmpi混合使用。事实上,以下错误消息:

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.
--------------------------------------------------------------------------
是MPICH的错误格式。因此,
mpif90
来自MPICH

但下一个错误消息是:

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.
--------------------------------------------------------------------------
是OpenMPI的OpenRTE框架使用的错误格式。因此,
mpirun
来自openmpi,而不是来自MPICH


如果您已经为MPICH安装了一个开发包,因此它提供了
mpicc
mpif90
,等等,但是您已经为Open MPI安装了一个运行时包,则可能会发生这种情况。确保只安装了一种MPI的包。如果您从源代码处编译了MPICH,请确保其二进制文件的路径是
$path

的第一个元素。您的程序在我的计算机上运行良好。您可以运行
哪个mpirun
哪个mpif90
来查看这些程序在哪里找到吗?我想有些MPI库将stdin连接到/dev/null,因此您无法从进程上的stdin读取。哦,天哪,我希望我能吻你!我是一个完全不懂Fortran和MPI的人,因此我使用以下链接开始:。问题是我同时安装了它们。我移除了MPICH,一切正常!想想如果没有你的提示,我会遇到多少错误!