2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! Copyright (C) 2001 PWSCF group
|
|
|
|
! This file is distributed under the terms of the
|
|
|
|
! GNU General Public License. See the file `License'
|
|
|
|
! in the root directory of the present distribution,
|
|
|
|
! or http://www.gnu.org/copyleft/gpl.txt .
|
|
|
|
!
|
|
|
|
!
|
|
|
|
module mytime
|
2003-02-08 00:04:36 +08:00
|
|
|
integer :: maxclock
|
|
|
|
real (8) :: notrunning
|
|
|
|
parameter (maxclock = 100, notrunning = - 1.d0)
|
|
|
|
real (8) :: myclock (maxclock), t0 (maxclock)!, scnds
|
|
|
|
character (len=12) :: clock_label
|
|
|
|
dimension clock_label (maxclock)
|
|
|
|
integer :: called (maxclock), nclock
|
2003-01-20 05:58:50 +08:00
|
|
|
logical :: no
|
|
|
|
end module mytime
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
subroutine init_clocks (go)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! flag=.true. : clocks will run
|
|
|
|
! flag=.false. : only clock #1 will run
|
|
|
|
!
|
|
|
|
|
|
|
|
use parameters, only : DP
|
|
|
|
use mytime
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
real(kind=8) :: scnds
|
2003-01-20 05:58:50 +08:00
|
|
|
logical :: go
|
2003-02-08 00:04:36 +08:00
|
|
|
integer :: n
|
|
|
|
no = .not.go
|
|
|
|
do n = 1, maxclock
|
|
|
|
called (n) = 0
|
|
|
|
myclock (n) = 0.0
|
|
|
|
t0 (n) = notrunning
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
end subroutine init_clocks
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
subroutine start_clock (label)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
use mytime
|
|
|
|
implicit none
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
real(kind=8) :: scnds
|
|
|
|
character (len=*) :: label
|
|
|
|
integer :: n
|
|
|
|
if (no.and.nclock.eq.1) return
|
|
|
|
do n = 1, nclock
|
|
|
|
if (label.eq.clock_label (n) ) then
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! found previously defined clock: check if not already started,
|
|
|
|
! store in t0 the starting time
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
if (t0 (n) .ne.notrunning) then
|
2003-01-20 05:58:50 +08:00
|
|
|
write (6, '("start_clock: clock # ",i2," for ",a12, &
|
|
|
|
& " already started")') n, label
|
2003-02-08 00:04:36 +08:00
|
|
|
else
|
|
|
|
t0 (n) = scnds ()
|
2003-01-20 05:58:50 +08:00
|
|
|
endif
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
!
|
|
|
|
! clock not found : add new clock for given label
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
if (nclock.eq.maxclock) then
|
|
|
|
write (6, '("start_clock: Too many clocks! call ignored")')
|
|
|
|
else
|
|
|
|
nclock = nclock + 1
|
|
|
|
clock_label (nclock) = label
|
|
|
|
t0 (nclock) = scnds ()
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
endif
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
end subroutine start_clock
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
subroutine stop_clock (label)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
use mytime
|
|
|
|
implicit none
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
real(kind=8) :: scnds
|
|
|
|
character (len=*) :: label
|
|
|
|
integer :: n
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
if (no) return
|
|
|
|
do n = 1, nclock
|
|
|
|
if (label.eq.clock_label (n) ) then
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! found previously defined clock : check if properly initialised,
|
|
|
|
! add elapsed time, increase the counter of calls
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
if (t0 (n) .eq.notrunning) then
|
2003-01-20 05:58:50 +08:00
|
|
|
write (6, '("stop_clock: clock # ",i2," for ",a12, &
|
|
|
|
& " not running")') n, label
|
2003-02-08 00:04:36 +08:00
|
|
|
else
|
|
|
|
myclock (n) = myclock (n) + scnds () - t0 (n)
|
|
|
|
t0 (n) = notrunning
|
|
|
|
called (n) = called (n) + 1
|
2003-01-20 05:58:50 +08:00
|
|
|
endif
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
!
|
|
|
|
! clock not found
|
|
|
|
!
|
|
|
|
|
|
|
|
write (6, '("stop_clock: no clock for ",a12," found !")') label
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
end subroutine stop_clock
|
|
|
|
!
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
subroutine print_clock (label)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
use mytime
|
|
|
|
implicit none
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
real(kind=8) :: scnds
|
|
|
|
character (len=*) :: label
|
|
|
|
integer :: n
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
if (label.eq.' ') then
|
|
|
|
write (6, * )
|
|
|
|
do n = 1, nclock
|
|
|
|
call print_this_clock (n)
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
else
|
|
|
|
do n = 1, nclock
|
|
|
|
if (label.eq.clock_label (n) ) then
|
|
|
|
call print_this_clock (n)
|
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
enddo
|
|
|
|
!
|
|
|
|
! clock not found
|
|
|
|
! if (.not.no) write(6,'("print_clock: no clock for ",
|
|
|
|
! + a12," found !")') label
|
|
|
|
|
|
|
|
endif
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
end subroutine print_clock
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
subroutine print_this_clock (n)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
use parameters
|
2003-02-08 00:04:36 +08:00
|
|
|
use mytime
|
2003-01-20 05:58:50 +08:00
|
|
|
implicit none
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
real(kind=8) :: scnds
|
|
|
|
integer :: n
|
|
|
|
real(kind=DP) :: elapsed_cpu_time, nsec
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
integer :: nhour, nmin
|
|
|
|
if (t0 (n) .eq.notrunning) then
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! clock stopped, print the stored value for the cpu time
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
elapsed_cpu_time = myclock (n)
|
|
|
|
else
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! clock not stopped, print the current value of the cpu time
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
elapsed_cpu_time = myclock (n) + scnds () - t0 (n)
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
endif
|
|
|
|
#ifdef PARA
|
|
|
|
!
|
|
|
|
! In the parallel case it is far from clear which value to print
|
|
|
|
! The following is the maximum over all nodes and pools. NOTA BENE:
|
|
|
|
! some trouble could arise if a clock is not started on all nodes
|
|
|
|
!
|
|
|
|
! by uncommenting the following line the extreme operation is removed
|
|
|
|
! may be useful for testing purpouses
|
|
|
|
! /* #define DEBUG */
|
|
|
|
!
|
|
|
|
#ifndef DEBUG
|
2003-02-08 00:04:36 +08:00
|
|
|
call extreme (elapsed_cpu_time, + 1)
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
call poolextreme (elapsed_cpu_time, + 1)
|
2003-01-20 05:58:50 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
2003-02-08 00:04:36 +08:00
|
|
|
if (n.eq.1) then
|
2003-01-20 05:58:50 +08:00
|
|
|
! The first clock is written as hour/min/sec
|
2003-02-08 00:04:36 +08:00
|
|
|
nhour = elapsed_cpu_time / 3600
|
|
|
|
nmin = (elapsed_cpu_time-3600 * nhour) / 60
|
|
|
|
nsec = (elapsed_cpu_time-3600 * nhour) - 60 * nmin
|
|
|
|
if (nhour.gt.0) then
|
2003-01-20 05:58:50 +08:00
|
|
|
write (6, '(5x,a12," : ",3x,i2,"h",i2,"m CPU time"/)') &
|
|
|
|
clock_label (n) , nhour, nmin
|
2003-02-08 00:04:36 +08:00
|
|
|
elseif (nmin.gt.0) then
|
2003-01-20 05:58:50 +08:00
|
|
|
write (6, '(5x,a12," : ",i2,"m",f5.2,"s CPU time"/)') &
|
|
|
|
clock_label (n) , nmin, nsec
|
2003-02-08 00:04:36 +08:00
|
|
|
else
|
2003-01-20 05:58:50 +08:00
|
|
|
write (6, '(5x,a12," : ",3x,f5.2,"s CPU time"/)') &
|
|
|
|
clock_label (n) , nsec
|
|
|
|
endif
|
2003-02-08 00:04:36 +08:00
|
|
|
elseif (called (n) .eq.1.or.t0 (n) .ne.notrunning) then
|
2003-01-20 05:58:50 +08:00
|
|
|
! For clocks that have been called only once
|
|
|
|
write (6, '(5x,a12," :",f9.2,"s CPU")') clock_label (n) , &
|
|
|
|
elapsed_cpu_time
|
2003-02-08 00:04:36 +08:00
|
|
|
elseif (called (n) .eq.0) then
|
2003-01-20 05:58:50 +08:00
|
|
|
! For clocks that have never been called
|
|
|
|
write (6, '("print_this: clock # ",i2," for ",a12, &
|
|
|
|
& " never called !")') n, clock_label(n)
|
2003-02-08 00:04:36 +08:00
|
|
|
else
|
2003-01-20 05:58:50 +08:00
|
|
|
! For all other clocks
|
|
|
|
write (6, '(5x,a12," :",f9.2,"s CPU (", &
|
|
|
|
& i8," calls,",f8.3," s avg)")') clock_label (n) , &
|
|
|
|
elapsed_cpu_time, called (n) , elapsed_cpu_time / called (n)
|
|
|
|
|
|
|
|
endif
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
end subroutine print_this_clock
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
real(kind=8) function get_clock (label)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
use parameters
|
2003-02-08 00:04:36 +08:00
|
|
|
use mytime
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
real(kind=8) :: scnds
|
|
|
|
character (len=*) :: label
|
|
|
|
integer :: n
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
if (no) then
|
|
|
|
if (label.eq.clock_label (1) ) then
|
|
|
|
get_clock = scnds ()
|
|
|
|
else
|
|
|
|
get_clock = notrunning
|
2003-01-20 05:58:50 +08:00
|
|
|
endif
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
endif
|
2003-02-08 00:04:36 +08:00
|
|
|
do n = 1, nclock
|
|
|
|
if (label.eq.clock_label (n) ) then
|
|
|
|
if (t0 (n) .eq.notrunning) then
|
|
|
|
get_clock = myclock (n)
|
|
|
|
else
|
|
|
|
get_clock = myclock (n) + scnds () - t0 (n)
|
2003-01-20 05:58:50 +08:00
|
|
|
endif
|
|
|
|
#ifdef PARA
|
|
|
|
!
|
|
|
|
! In the parallel case, use the maximum over all nodes and pools
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
call extreme (get_clock, + 1)
|
|
|
|
call poolextreme (get_clock, + 1)
|
2003-01-20 05:58:50 +08:00
|
|
|
#endif
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
!
|
|
|
|
! clock not found
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
get_clock = notrunning
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
write (6, '("get_clock: no clock for ",a12," found !")') label
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
end function get_clock
|
|
|
|
|