title: Calling MPI_send MPI_recv from a fortran subroutine
body: <p>is it possible to call the MPI_send and MPI_recv commands inside a subroutine and not the main program? I have written a minimal program for what I am trying to do. It is compiling fine but it is not working. The program just hangs in the "sendrecv" subroutine. Any ideas how can I do it?</p>
  
  <p>main.f</p>
  
  <pre><code>  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
  </code></pre>
  
  <p>sendrecv.f</p>
  
  <pre><code>  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,
   &amp;           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,
   &amp;        mpi_comm_world, ierror)
    end if
  
    return
    end
  </code></pre>