Timers counting the execution times added.

A new module called 'timer' has been added. The purpose of this module
is to handle the execution timers of the program or its subtasks, like
initialization, data writing, evolution, etc.

The final summary of the times spent on different task has been added
as well.
This commit is contained in:
Grzegorz Kowal 2008-12-07 14:06:04 -06:00
parent e75cc33c1f
commit ee3cb39fdc
3 changed files with 197 additions and 3 deletions

View File

@ -31,11 +31,15 @@ program godunov
use config, only : read_config
use io , only : write_data
use mesh , only : init_mesh, clear_mesh
use timer , only : init_timers, start_timer, stop_timer, get_timer &
, get_timer_total
!
!----------------------------------------------------------------------
!
! local variables
!
character(len=60) :: fmt
real :: tall
!
!----------------------------------------------------------------------
!
@ -51,14 +55,22 @@ program godunov
!
call read_config
! initialize timers
!
call init_timers
! initialize our adaptive mesh, refine that mesh to the desired level
! according to the initialized problem
!
call start_timer(1)
call init_mesh
call stop_timer(1)
! write down the initial state
!
call start_timer(2)
call write_data('r', 0, 0)
call stop_timer(2)
! TODO: main loop, perform one step evolution of the system, do refinement/derefinement
! TODO: get new time step, dump data, print info about the progress
@ -67,6 +79,19 @@ program godunov
!
call clear_mesh
! get total time
!
tall = get_timer_total()
! print info about execution times
!
write(fmt,"(a,i2,a)") "(a27,1f", max(1, nint(alog10(tall))) + 6, ".4,' secs = ',f7.3,' %')"
write (*,*)
write (*,fmt) "Time for initialization : ", get_timer(1), 100.0*get_timer(1)/tall
write (*,fmt) "Time for data output : ", get_timer(2), 100.0*get_timer(2)/tall
write (*,fmt) "EXECUTION TIME : ", tall, 100.0
!----------------------------------------------------------------------
!
end program

View File

@ -299,8 +299,10 @@ name = godunov-amr
default: $(name).x
sources = blocks.F90 config.F90 driver.F90 error.F90 io.F90 mesh.F90 problem.F90
objects = blocks.o config.o driver.o error.o io.o mesh.o problem.o
sources = blocks.F90 config.F90 driver.F90 error.F90 io.F90 mesh.F90 \
problem.F90 timer.F90
objects = blocks.o config.o driver.o error.o io.o mesh.o \
problem.o timer.o
files = $(sources) makefile make.default config.in license.txt hosts
$(name).x: $(objects)
@ -319,10 +321,11 @@ clean-all:
blocks.o : blocks.F90 config.o
config.o : config.F90 error.o
driver.o : driver.F90 config.o io.o mesh.o
driver.o : driver.F90 config.o io.o mesh.o timer.o
error.o : error.F90
io.o : io.F90 blocks.o error.o
mesh.o : mesh.F90 blocks.o config.o error.o problem.o
problem.o : problem.F90 blocks.o
timer.o : timer.F90
#-------------------------------------------------------------------------------

166
src/timer.F90 Normal file
View File

@ -0,0 +1,166 @@
!!*****************************************************************************
!!
!! module: timer - handling the timings of program execution
!!
!! Copyright (C) 2008 Grzegorz Kowal <kowal@astro.wisc.edu>
!!
!!*****************************************************************************
!!
!! This file is part of Godunov-AMR.
!!
!! Godunov-AMR 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.
!!
!! Godunov-AMR 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, see <http://www.gnu.org/licenses/>.
!!
!!*****************************************************************************
!!
!
module timer
implicit none
integer , parameter :: ntimers = 32
integer(kind=8), dimension(ntimers), save :: timers, tstart, tstop
integer(kind=8) , save :: ticks, tbegin
contains
!
!======================================================================
!
! init_timers: subroutine initializes timers by creating an array of
! timers and resetting it
!
!======================================================================
!
subroutine init_timers
implicit none
!
!----------------------------------------------------------------------
!
! 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
!----------------------------------------------------------------------
!
end subroutine init_timers
!
!======================================================================
!
! start_timer: subroutine starts timing for a specified timer
!
!======================================================================
!
subroutine start_timer(timer)
implicit none
! input arguments
!
integer, intent(in) :: timer
!
!----------------------------------------------------------------------
!
call system_clock(tstart(timer))
!----------------------------------------------------------------------
!
end subroutine start_timer
!
!======================================================================
!
! stop_timer: subroutine stops timing for a specified timer
!
!======================================================================
!
subroutine stop_timer(timer)
implicit none
! input arguments
!
integer, intent(in) :: timer
!
!----------------------------------------------------------------------
!
call system_clock(tstop(timer))
timers(timer) = timers(timer) + tstop(timer) - tstart(timer)
!----------------------------------------------------------------------
!
end subroutine stop_timer
!
!======================================================================
!
! get_timer: function returns the value of specified timer
!
!======================================================================
!
function get_timer(timer)
implicit none
! input arguments
!
integer, intent(in) :: timer
! output arguments
!
real :: get_timer
!
!----------------------------------------------------------------------
!
get_timer = (1.0 * timers(timer)) / ticks
!----------------------------------------------------------------------
!
end function get_timer
!
!======================================================================
!
! get_timer_total: function returns the value of total execution time
!
!======================================================================
!
function get_timer_total
implicit none
! output arguments
!
integer(kind=8) :: tend
real :: get_timer_total
!
!----------------------------------------------------------------------
!
! get current time and the number of ticks per second
!
call system_clock(count=tend)
get_timer_total = (1.0 * (tend - tbegin)) / ticks
!----------------------------------------------------------------------
!
end function get_timer_total
!======================================================================
!
end module