MPI_Rank值被MPI_RECV子程序干扰

时间:2016-09-06 09:14:31

标签: fortran mpi

我正在写一个Fortran MPI程序。

调用子程序MPI_COMM_RANK

之后
MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr)

我得到当前流程的等级my_id。调用MPI_RECV()后,我发现my_id被打扰了。

program hello_world
implicit none
include 'mpif.h'
integer ierr, num_procs, my_id,status,i
INTEGER :: send

call MPI_INIT ( ierr )
call MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr)
call MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr)

if (my_id == 0) then
  send = 1
  print *,my_id,"==M=="
  !!! send data to slave processed
  do i = 1,num_procs-1
      call MPI_SEND(send,1, MPI_INTEGER,i , &
           1020, MPI_COMM_WORLD, ierr )
  end do

else

  call MPI_RECV(send,1, MPI_INTEGER, 0, &
       1020, MPI_COMM_WORLD,status, ierr )

  print *,my_id,"==S=="

end if
   call mpi_finalize(ierr)
end program

然后,我的打印输出错误

0 ==M==
1020 ==S==
1020 ==S==

当我放置

print *,my_id,"==S=="

前面的

call MPI_RECV(

我得到了正确的打印输出

 1 ==S==
 2 ==S==
 0 ==M==

似乎MPI_RECV会干扰my_id的值。我不知道。

0 个答案:

没有答案