Stopwatch to time parts of the code
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | tag | Which stopwatch to act upon |
||
integer, | intent(in) | :: | mode | Action 1=start 2=stop |
subroutine io_stopwatch(tag, mode)
!=====================================
!! Stopwatch to time parts of the code
!=====================================
implicit none
character(len=*), intent(in) :: tag
!! Which stopwatch to act upon
integer, intent(in) :: mode
!! Action 1=start 2=stop
integer :: i
real(kind=dp) :: t
call cpu_time(t)
select case (mode)
case (1)
do i = 1, nnames
if (clocks(i)%label .eq. tag) then
clocks(i)%ptime = t
clocks(i)%ncalls = clocks(i)%ncalls + 1
return
endif
enddo
nnames = nnames + 1
if (nnames .gt. nmax) call io_error('Maximum number of calls to io_stopwatch exceeded')
clocks(nnames)%label = tag
clocks(nnames)%ctime = 0.0_dp
clocks(nnames)%ptime = t
clocks(nnames)%ncalls = 1
case (2)
do i = 1, nnames
if (clocks(i)%label .eq. tag) then
clocks(i)%ctime = clocks(i)%ctime + t - clocks(i)%ptime
return
endif
end do
write (stdout, '(1x,3a)') 'WARNING: name = ', trim(tag), ' not found in io_stopwatch'
case default
write (stdout, *) ' Name = ', trim(tag), ' mode = ', mode
call io_error('Value of mode not recognised in io_stopwatch')
end select
return
end subroutine io_stopwatch