This is an amendment to the odd_evn_rbufs src.alt by Mark Debbage, QLogic,
Inc.

The amendment takes the odd_evn_rbufs patch (by Hakon Bugge, Scali, Inc.) and
adds some code on top to limit the number of pre-posted irecvs to 2 per
direction so that there is at most 1 outstanding irecv per buffer.

For details see hpgmail-11347, 11349, 11351-11352, and 11372.

This srcalt was approved for usage at the SPEC annual meeting
HPG sessions 1/28-29/2008.

diff TF_AD_SPLITTING.f90 ../..
68,73c68,70
<                                          , Buf_send_dn
<    real(r8), allocatable, dimension( :), target :: &
<                                            Buf_recv_up_evn &
<                                          , Buf_recv_up_odd &
<                                          , Buf_recv_dn_evn &
<                                          , Buf_recv_dn_odd
---
>                                          , Buf_send_dn &
>                                          , Buf_recv_up &
>                                          , Buf_recv_dn
100d96
< integer(int) :: prepost_irecv, prepost_first_plane, prepost_last_plane
215,218c211,212
<    ALLOCATE( Buf_recv_up_evn( buf_size) )
<    ALLOCATE( Buf_recv_up_odd( buf_size) )
<    ALLOCATE( Buf_recv_dn_evn( buf_size) )
<    ALLOCATE( Buf_recv_dn_odd( buf_size) )
---
>    ALLOCATE( Buf_recv_up( buf_size) )
>    ALLOCATE( Buf_recv_dn( buf_size) )
238,239c232
< ! On commence par poster deux receptions
< prepost_irecv = 0
---
> ! On commence par poster toutes les receptions
242,247c235,237
<       if ( prepost_irecv < 2 ) then
<          first_plane = sk
<          last_plane = MIN( sk + stride - 1, last_real_cell( dir_orth_2) )
<          call TF_COMMUNICATIONS_PLANE_INIT( first_plane, last_plane, nb_variables)
<          prepost_irecv = prepost_irecv + 1
<       end if
---
>       first_plane = sk
>       last_plane = MIN( sk + stride - 1, last_real_cell( dir_orth_2) )
>       call TF_COMMUNICATIONS_PLANE_INIT( first_plane, last_plane, nb_variables)
259,265d248
< 
<    prepost_first_plane = sk + (stride * 2)
<    if ( prepost_first_plane <= last_real_cell( dir_orth_2) ) then 
<       ! poster prochaine reception
<       prepost_last_plane = MIN( prepost_first_plane + stride - 1, last_real_cell( dir_orth_2) )
<       call TF_COMMUNICATIONS_PLANE_INIT( prepost_first_plane, prepost_last_plane, nb_variables)
<    end if
404,407c387,388
<    DEALLOCATE( Buf_recv_up_evn )
<    DEALLOCATE( Buf_recv_up_odd )
<    DEALLOCATE( Buf_recv_dn_evn )
<    DEALLOCATE( Buf_recv_dn_odd )
---
>    DEALLOCATE( Buf_recv_up )
>    DEALLOCATE( Buf_recv_dn )
600,601c581
< integer(int), save :: up_odd_even_init=0, dn_odd_even_init=0
< real(r8), pointer,dimension( : ) :: Rx_buf_ptr
---
> 
622,628c602
<    up_odd_even_init = up_odd_even_init + 1
<    if (mod(up_odd_even_init, 2) == 0) then
<       Rx_buf_ptr => Buf_recv_up_evn(1:size)
<    else
<       Rx_buf_ptr => Buf_recv_up_odd(1:size)
<    end if
<    call MPI_IRECV( Rx_buf_ptr, size, MPI_REAL8,   &
---
>    call MPI_IRECV( Buf_recv_up( 1:size), size, MPI_REAL8,   &
630c604
<                    Req_recv_up(first_plane), status_mpi)
---
>                    Req_recv_up(first_plane), status_mpi, error_mpi)
640,646c614
<    dn_odd_even_init = dn_odd_even_init + 1
<    if (mod(dn_odd_even_init, 2) == 0) then
<       Rx_buf_ptr => Buf_recv_dn_evn(1:size)
<    else
<       Rx_buf_ptr => Buf_recv_dn_odd(1:size)
<    end if
<    call MPI_IRECV( Rx_buf_ptr, size, MPI_REAL8,   &
---
>    call MPI_IRECV( Buf_recv_dn( 1:size), size, MPI_REAL8,   &
648c616
<                    Req_recv_dn(first_plane), status_mpi)
---
>                    Req_recv_dn(first_plane), status_mpi, error_mpi)
673,674d640
< integer(int), save :: up_odd_even=0, dn_odd_even=0
< real(r8), pointer, dimension ( : ) :: Rx_buf_ptr
752,757d717
<    up_odd_even = up_odd_even + 1
<    if (mod(up_odd_even, 2) == 0) then
<       Rx_buf_ptr => Buf_recv_up_evn(1:size)
<    else
<       Rx_buf_ptr => Buf_recv_up_odd(1:size)
<    end if
764c724
<             Hydro_vars( m, j, k)%cell_var( l) = Rx_buf_ptr( n)
---
>             Hydro_vars( m, j, k)%cell_var( l) = Buf_recv_up( n)
777,782d736
<    dn_odd_even = dn_odd_even + 1
<    if (mod(dn_odd_even, 2) == 0) then
<       Rx_buf_ptr => Buf_recv_dn_evn(1:size)
<    else
<       Rx_buf_ptr => Buf_recv_dn_odd(1:size)
<    end if
789c743
<             Hydro_vars( m, j, k)%cell_var( l) = Rx_buf_ptr( n)
---
>             Hydro_vars( m, j, k)%cell_var( l) = Buf_recv_dn( n)
894c848
<    call MPI_RECV( Buf_recv_up_evn( 1:size), size, MPI_REAL8,   &
---
>    call MPI_RECV( Buf_recv_up( 1:size), size, MPI_REAL8,   &
904c858
<          Hydro_vars( m, j, k)%cell_var( l) = Buf_recv_up_evn( n)
---
>          Hydro_vars( m, j, k)%cell_var( l) = Buf_recv_up( n)
917c871
<    call MPI_RECV( Buf_recv_dn_evn( 1:size), size, MPI_REAL8,   &
---
>    call MPI_RECV( Buf_recv_dn( 1:size), size, MPI_REAL8,   &
927c881
<          Hydro_vars( m, j, k)%cell_var( l) = Buf_recv_dn_evn( n)
---
>          Hydro_vars( m, j, k)%cell_var( l) = Buf_recv_dn( n)
