!===============================================================================
!
! cg_proj_wait.F90
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2016 Hinnerk Stueben
!
! This file is part of BQCD -- Berlin Quantum ChromoDynamics program
!
! BQCD is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! BQCD is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with BQCD.  If not, see <http://www.gnu.org/licenses/>.
!
!-------------------------------------------------------------------------------
# define LANGUAGE_FORTRAN
# include "defs.h"

!-------------------------------------------------------------------------------
subroutine cg_proj_wait(mu0)

  use module_cg_proj_xbound
  use module_lattice
  implicit none
  integer, intent(in) :: mu0
  integer :: mu, mu1, mu2, ierror

  if (mu0 == 0) then
     mu1 = 2
     mu2 = DIM
     call mpi_waitall(12, xbound_request(0, 0, 2), MPI_STATUSES_IGNORE, ierror)
     TIMING_STOP(timing_bin_xbound_cg_proj)
  else
     mu1 = mu0
     mu2 = mu0
     call mpi_waitall(4, xbound_request(0, 0, mu0), MPI_STATUSES_IGNORE, ierror)
  endif

#ifdef TIMING
  do mu = mu1, mu2
     if (npe(mu) == 1) cycle

     select case (mu)
     case (1); TIMING_STOP(timing_bin_xbound_cg_proj_x)
     case (2); TIMING_STOP(timing_bin_xbound_cg_proj_y)
     case (3); TIMING_STOP(timing_bin_xbound_cg_proj_z)
     case (4); TIMING_STOP(timing_bin_xbound_cg_proj_t)
     end select
  enddo
#endif

end

!===============================================================================
