MPI_发送/接收通信器数据类型错误
我用Fortran 90编写了以下基本MPI程序:MPI_发送/接收通信器数据类型错误,mpi,fortran90,Mpi,Fortran90,我用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_WORL
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
我环顾了四周,但我就是看不出我的错误。
任何帮助都会很好,谢谢<代码> MPIIN INT/CODE >对应于C++和C++的代码> int <代码>类型。Fortran
INTEGER
类型由预定义的MPI数据类型MPI\u INTEGER
表示
此外,您的代码中还有另一个错误。您需要传递MPI\u STATUS\u SIZE
而必须传递相同大小的整数数组,例如:
INTEGER status(MPI_STATUS_SIZE)
CALL MPI_SEND(..., status, ierr)
我还建议您更换
include 'mpif.h'
与
mpif.h
是过时的Fortran 77接口,不应在现代程序中使用。mpi
模块接口本身也被mpi\u f08
模块接口淘汰,但该接口来自mpi-3.0,尚未广泛实现
use mpi