!===============================================================================
!
! reduction_bgl.F90 - interface to Thomas Streuer's reduction routines for BGL 
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2006 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"

!-------------------------------------------------------------------------------
function global_sum(local_sum)
 
  implicit none
  REAL     global_sum, local_sum
  REAL, external :: global_sum_torus

  TIMING_START(timing_bin_global_sum)

  global_sum=global_sum_torus(local_sum);

  TIMING_STOP(timing_bin_global_sum)
end

!-------------------------------------------------------------------------------
function global_min(local_min)
 
  implicit none
  REAL     global_min, local_min

  call global_sum_var(local_min, global_min, 1, 2)

end

!-------------------------------------------------------------------------------
function global_max(local_max)
 
  implicit none
  REAL     global_max, local_max

  call global_sum_var(local_max, global_max, 1, 1)
end

!-------------------------------------------------------------------------------
subroutine global_sum_vec(n, sum)
 
  implicit none
  integer, intent(in)    :: n
  REAL,    intent(inout) :: sum(n)
  REAL                   :: tmp(n)

  TIMING_START(timing_bin_global_sum_vec)



  tmp = sum
  call global_sum_var(tmp, sum, n, 0)

  TIMING_STOP(timing_bin_global_sum_vec)
end

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