问题描述
我有以下用Fortran 90编写的基本MPI程序:
I have the following basic MPI program written in Fortran 90:
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中接收并显示它,但是无论我如何尝试,我都无法使它正常工作.
The purpose is just to send an integer from process 0 and receive and display it in process 1, but whatever i seem to try, i cannot get it to work.
我正在使用以下程序编译并运行该程序:
I am compiling and running this program with:
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
我环顾四周,但我无法发现我的错误.任何帮助都会很棒,谢谢!
I have looked around but i just cant spot my error.Any help would be great, thanks!
推荐答案
MPI_INT
对应于C和C ++的int
类型. Fortran INTEGER
类型由预定义的MPI数据类型MPI_INTEGER
表示.
MPI_INT
corresponds to the int
type of C and C++. The Fortran INTEGER
type is represented by the predefined MPI datatype MPI_INTEGER
.
此外,您的代码中还有另一个错误.您传递MPI_STATUS_SIZE
,而必须传递相同大小的整数数组,例如:
Besides there is another error in your code. You pass MPI_STATUS_SIZE
whereas you have to pass an integer array of the same size, e.g.:
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,仍未得到广泛实现.
mpif.h
is an obsoleted Fortran 77 interface and it should not be used in modern programs. The mpi
module interface itself is also obsoleted by the mpi_f08
module interface, but that comes from MPI-3.0 and is still not widely implemented.
这篇关于MPI_Send/Recv通信器数据类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!