【发布时间】:2014-02-24 12:29:26
【问题描述】:
我正在编写一个非常小的程序来理解 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 output 编译它,当我用mpirun -np 2 output 执行它时,我收到以下错误:
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.
--------------------------------------------------------------------------
感谢大家的帮助!
【问题讨论】:
-
您的程序在我的电脑上运行良好。你能运行
which mpirun和which mpif90看看这些程序是在哪里找到的吗? -
我认为一些 MPI 库将标准输入连接到 /dev/null,因此您无法从进程中的标准输入读取。