从fortran子例程调用MPI_send MPI_recv

时间:2013-02-28 14:56:39

标签: fortran mpi

是否可以在子程序中调用MPI_send和MPI_recv命令而不是主程序?我已经为我想要做的事写了一个最小程序。它编译正常但它不起作用。该程序只挂在“sendrecv”子程序中。任何想法我该怎么做?

main.f

  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

sendrecv.f

  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

0 个答案:

没有答案