!===============================================================================
!
! sc_block.F90  -  routines for the Spin-Colour field with loop blocking
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2008 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/>.
!
!-------------------------------------------------------------------------------
# include "defs.h"

!-------------------------------------------------------------------------------
subroutine sc_axpy_block(inout, in, a, i1, i2)  ! inout = inout + a * in

  implicit none
  REAL, intent(inout) :: inout(*)
  REAL, intent(in)    :: in(*)
  REAL, intent(in)    :: a
  integer, intent(in) :: i1, i2
  integer             :: i
 
  do i = SIZE_COMPLEX * NDIRAC * NCOL * (i1 - 1) + 1, &
         SIZE_COMPLEX * NDIRAC * NCOL * i2
     inout(i) = inout(i) + a * in(i)
  enddo

end

!-------------------------------------------------------------------------------
subroutine sc_xpby_block(inout, in, b, i1, i2)  ! inout = b * inout + in

  implicit none
  REAL, intent(inout) :: inout(*)
  REAL, intent(in)    :: in(*)
  REAL, intent(in)    :: b
  integer, intent(in) :: i1, i2
  integer             :: i
 
  do i = SIZE_COMPLEX * NDIRAC * NCOL * (i1 - 1) + 1, &
         SIZE_COMPLEX * NDIRAC * NCOL * i2
     inout(i) = b * inout(i) + in(i)
  enddo

end

!-------------------------------------------------------------------------------
subroutine sc_dprod_block(dprod, x, y, i1, i2)  ! dprod = Sum_i double(x_i) * double(y_i)

  ! *** dprod has to be initialised outside         *** !
  ! *** OpenMP/MPI summation has to be done outside *** !

  implicit none
  DOUBLE,  intent(inout) :: dprod  
  REAL,    intent(in)    :: x(*), y(*)
  integer, intent(in)    :: i1, i2
  
  DOUBLE  :: dtmp1, dtmp2         
  integer :: i
 
  do i = SIZE_COMPLEX * NDIRAC * NCOL * (i1 - 1) + 1, &
         SIZE_COMPLEX * NDIRAC * NCOL * i2
     dtmp1 = x(i)
     dtmp2 = y(i)
     dprod = dprod + dtmp1 * dtmp2
  enddo

end

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