2010-10-13 03:32:10 -03:00
|
|
|
!!******************************************************************************
|
2008-12-07 14:06:04 -06:00
|
|
|
!!
|
2011-05-05 18:37:53 -03:00
|
|
|
!! module: TIMER - handling the timing of the program execution
|
2008-12-07 14:06:04 -06:00
|
|
|
!!
|
2011-05-05 18:37:53 -03:00
|
|
|
!! Copyright (C) 2008-2011 Grzegorz Kowal <grzegorz@amuncode.org>
|
2008-12-07 14:06:04 -06:00
|
|
|
!!
|
2010-10-13 03:32:10 -03:00
|
|
|
!!******************************************************************************
|
2008-12-07 14:06:04 -06:00
|
|
|
!!
|
2011-05-05 18:37:53 -03:00
|
|
|
!! This file is part of the AMUN code.
|
2008-12-07 14:06:04 -06:00
|
|
|
!!
|
2011-04-29 11:21:30 -03:00
|
|
|
!! 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.
|
2008-12-07 14:06:04 -06:00
|
|
|
!!
|
2011-04-29 11:21:30 -03:00
|
|
|
!! This program is distributed in the hope that it will be useful,
|
2008-12-07 14:06:04 -06:00
|
|
|
!! 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
|
2011-04-29 11:21:30 -03:00
|
|
|
!! along with this program; if not, write to the Free Software Foundation,
|
|
|
|
!! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-07 14:06:04 -06:00
|
|
|
!!
|
2010-10-13 03:32:10 -03:00
|
|
|
!!******************************************************************************
|
2008-12-07 14:06:04 -06:00
|
|
|
!!
|
|
|
|
!
|
|
|
|
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
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
! init_timers: subroutine initializes timers by creating an array of
|
|
|
|
! timers and resetting it
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
subroutine init_timers
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -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
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
end subroutine init_timers
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
! start_timer: subroutine starts timing for a specified timer
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
subroutine start_timer(timer)
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
|
|
|
integer, intent(in) :: timer
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
call system_clock(tstart(timer))
|
|
|
|
|
2008-12-08 21:09:48 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
end subroutine start_timer
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
! stop_timer: subroutine stops timing for a specified timer
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
subroutine stop_timer(timer)
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! input arguments
|
|
|
|
!
|
|
|
|
integer, intent(in) :: timer
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
call system_clock(tstop(timer))
|
|
|
|
|
|
|
|
timers(timer) = timers(timer) + tstop(timer) - tstart(timer)
|
|
|
|
|
2008-12-08 21:09:48 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
end subroutine stop_timer
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
! get_timer: function returns the value of specified timer
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -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
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
get_timer = (1.0 * timers(timer)) / ticks
|
|
|
|
|
2008-12-08 21:09:48 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
end function get_timer
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
! get_timer_total: function returns the value of total execution time
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
2010-09-18 11:42:09 +02:00
|
|
|
function get_timer_total()
|
2008-12-07 14:06:04 -06:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! output arguments
|
|
|
|
!
|
|
|
|
integer(kind=8) :: tend
|
|
|
|
real :: get_timer_total
|
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
2008-12-08 21:09:48 -06:00
|
|
|
! get the current time and the number of ticks per second
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
call system_clock(count=tend)
|
|
|
|
|
|
|
|
get_timer_total = (1.0 * (tend - tbegin)) / ticks
|
|
|
|
|
2008-12-08 21:09:48 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
end function get_timer_total
|
|
|
|
|
2008-12-08 21:09:48 -06:00
|
|
|
!===============================================================================
|
2008-12-07 14:06:04 -06:00
|
|
|
!
|
|
|
|
end module
|