amun-code/src/timer.F90

168 lines
4.7 KiB
Fortran
Raw Normal View History

!!******************************************************************************
!!
!! module: TIMER - handling the timing of the program execution
!!
!! Copyright (C) 2008-2011 Grzegorz Kowal <grzegorz@amuncode.org>
!!
!!******************************************************************************
!!
!! This file is part of the AMUN code.
!!
!! This program 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 2
!! of the License, or (at your option) any later version.
!!
!! This program 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 this program; if not, write to the Free Software Foundation,
!! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
!!
!!******************************************************************************
!!
!
module timer
implicit none
integer , parameter :: ntimers = 32
integer(kind=8), dimension(ntimers), save :: timers, tstart, tstop
integer(kind=8) , save :: ticks, tbegin
contains
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
! init_timers: subroutine initializes timers by creating an array of
! timers and resetting it
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
subroutine init_timers
implicit none
!
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
! get current time and the number of ticks per second
!
call system_clock(count=tbegin, count_rate=ticks)
! reset timers
!
timers(:) = 0
tstart(:) = 0
tstop(:) = 0
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
end subroutine init_timers
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
! start_timer: subroutine starts timing for a specified timer
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
subroutine start_timer(timer)
implicit none
! input arguments
!
integer, intent(in) :: timer
!
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
call system_clock(tstart(timer))
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
end subroutine start_timer
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
! stop_timer: subroutine stops timing for a specified timer
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
subroutine stop_timer(timer)
implicit none
! input arguments
!
integer, intent(in) :: timer
!
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
call system_clock(tstop(timer))
timers(timer) = timers(timer) + tstop(timer) - tstart(timer)
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
end subroutine stop_timer
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
! get_timer: function returns the value of specified timer
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
function get_timer(timer)
implicit none
! input arguments
!
integer, intent(in) :: timer
! output arguments
!
real :: get_timer
!
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
get_timer = (1.0 * timers(timer)) / ticks
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
end function get_timer
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
! get_timer_total: function returns the value of total execution time
!
2008-12-08 21:09:48 -06:00
!===============================================================================
!
function get_timer_total()
implicit none
! output arguments
!
integer(kind=8) :: tend
real :: get_timer_total
!
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
2008-12-08 21:09:48 -06:00
! get the current time and the number of ticks per second
!
call system_clock(count=tend)
get_timer_total = (1.0 * (tend - tbegin)) / ticks
2008-12-08 21:09:48 -06:00
!-------------------------------------------------------------------------------
!
end function get_timer_total
2008-12-08 21:09:48 -06:00
!===============================================================================
!
end module