0
我附上了一個我正在編寫的MPI程序的示例。當我使用「mpirun -np 4 a.out」運行此程序時,我的輸出爲:MPI發送recv混淆
Sender: 1
Data received from 1
Sender: 2
Data received from 1
Sender: 2
然後運行掛起。我不明白爲什麼sender變量在MPI_recv後更改它的值?有任何想法嗎?
謝謝 普拉迪普
`程序MPI_TEST
include 'mpif.h'
!----------------(Initialize variables)--------------------
integer, dimension(3) :: recv, send
integer :: sender, np, rank, ierror
call mpi_init(ierror)
call mpi_comm_rank(mpi_comm_world, rank, ierror)
call mpi_comm_size(mpi_comm_world, np, ierror)
!----------------(Main program)--------------------
! receive the data from the other processors
if (rank.eq.0) then
do sender = 1, np-1
print *, "Sender: ", sender
call mpi_recv(recv, 3, mpi_int, sender, 1,
& mpi_comm_world, status, ierror)
print *, "Data received from ",sender
end do
end if
! send the data to the main processor
if (rank.ne.0) then
send(1) = 3
send(2) = 4
send(3) = 4
call mpi_send(send, 3, mpi_int, 0, 1, mpi_comm_world, ierr)
end if
!----------------(clean up)--------------------
call mpi_finalize(ierror)
return
end program mpi_test`
謝謝!解決了這個問題。 – jhaprade 2013-02-19 01:30:34