我有以下用Fortran 90编写的基本MPI程序:
program sendRecv
include 'mpif.h'
!MPI Variables
integer ierr, numProcs, procID
!My variables
integer dat, datRec
!Init MPI
call MPI_INIT ( ierr )
!Get number of processes/ cores requested
call MPI_COMM_SIZE (MPI_COMM_WORLD, numProcs, ierr)
!Get rank of process
call MPI_COMM_RANK (MPI_COMM_WORLD, procID, ierr)
if (procID .eq. 0) then
dat=4
!Send num to process 1
call MPI_SEND (dat, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, ierr)
else if (procID .eq. 1) then
!Recieve num from process 0
call MPI_RECV (datRec, 1, MPI_INT, 0, MPI_ANY_SOURCE, MPI_COMM_WORLD, MPI_STATUS_SIZE, ierr)
!Display info
write(*,*) "Process 1 recieved ", datRec, " from proc 0"
else
write(*,*)"Into else"
end if
!Finilise MPI
call MPI_FINALIZE ( ierr )
end program sendRecv
目的只是从进程0发送一个整数并在进程1中接收并显示它,但无论我似乎尝试,我都无法让它工作。
我正在编译并运行此程序:
mpif90 sendRecv.f90 -o tst
mpirun -n 2 tst
我得到了这个:
[conor-Latitude-XT2:3053] *** An error occurred in MPI_Send
[conor-Latitude-XT2:3053] *** on communicator MPI_COMM_WORLD
[conor-Latitude-XT2:3053] *** MPI_ERR_TYPE: invalid datatype
[conor-Latitude-XT2:3053] *** MPI_ERRORS_ARE_FATAL (your MPI job will now abort)
--------------------------------------------------------------------------
mpirun has exited due to process rank 1 with PID 3054 on
node conor-Latitude-XT2 exiting without calling "finalize". This may
have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).
--------------------------------------------------------------------------
[conor-Latitude-XT2:03052] 1 more process has sent help message help-mpi-errors.txt / mpi_errors_are_fatal
[conor-Latitude-XT2:03052] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages
我环顾四周但我无法发现我的错误。 任何帮助都会很棒,谢谢!
答案 0 :(得分:2)
MPI_INT
对应于int
类型的C和C ++。 Fortran INTEGER
类型由预定义的MPI数据类型MPI_INTEGER
表示。
此外,您的代码中还有另一个错误。您传递MPI_STATUS_SIZE
,而您必须传递相同大小的整数数组,例如:
INTEGER status(MPI_STATUS_SIZE)
CALL MPI_SEND(..., status, ierr)
我还建议你替换
include 'mpif.h'
与
use mpi
mpif.h
是一个已废弃的Fortran 77界面,不应在现代程序中使用。 mpi
模块接口本身也被mpi_f08
模块接口废弃,但它来自MPI-3.0,但仍未广泛实现。