0

是否可以在子程序而不是主程序中调用 MPI_send 和 MPI_recv 命令?我已经为我正在尝试做的事情编写了一个最小的程序。它编译得很好,但它不工作。该程序只是挂在“sendrecv”子程序中。有什么想法我该怎么做?

主文件

  program   main

  implicit none 

  include  'mpif.h'

  integer me, np, ierror

  call  MPI_init( ierror )
  call  MPI_comm_rank( mpi_comm_world, me, ierror )
  call  MPI_comm_size( mpi_comm_world, np, ierror )

  call sendrecv(me, np)

  call mpi_finalize( ierror )

  stop
  end

发送接收文件

  subroutine sendrecv(me, np)

  include 'mpif.h'

  integer np, me, sender, tag
  integer, dimension(mpi_status_size) :: status

  integer, dimension(1) :: recv, send

  if (me.eq.0) then

     do sender = 1, np-1
        call mpi_recv(recv, 1, mpi_integer, sender, tag,
 &           mpi_comm_world, status, ierror)

     end do
  end if

  if ((me.ge.1).and.(me.lt.np)) then
     send(1) = me*12

     call mpi_send(send, 1, mpi_integer, 0, tag,
 &        mpi_comm_world, ierror)
  end if

  return
  end
4

0 回答 0