forked from KuangLab-Harvard/SAM_SRCv6.11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer_util.f90
98 lines (91 loc) · 2.25 KB
/
timer_util.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
subroutine t_setoptionf (i, j)
integer i,j
end
subroutine t_initializef()
use timer
if(initialized) call t_error("t_initialize should be called only once")
call cpu_time(time0)
initialized = .true.
ntimers = 1
name(1) = "_total"
active(1) = .true.
current_active = 1
current_parent = 0
end
subroutine t_startf(str)
use timer
use grid, only: masterproc
implicit none
character(*), intent(in) :: str
integer id
logical:: found
real ttt
call task_barrier()
!if(masterproc) print*,'>>>start ',trim(str)
found = .false.
call cpu_time(ttt)
if(.not.initialized) call t_error("t_initialize should be called first")
do id=1,ntimers
if(trim(str).eq.trim(name(id)).and.parent(id).eq.current_active) then
found = .true.
exit
end if
end do
if(.not.found) then
ntimers = ntimers+1
id = ntimers
name(id) = trim(str)
end if
if(active(id)) call t_error('timer '//str//' is already active.')
parent(id) = current_active
current_parent = parent(id)
active(id) = .true.
current_active = id
time_start(id) = ttt
end
subroutine t_stopf(str)
use timer
implicit none
character(*), intent(in) :: str
integer id
real ttt
logical:: found
call task_barrier()
found = .false.
do id=1,ntimers
if(trim(name(id)).eq.trim(str).and.parent(id).eq.current_parent) then
if(.not.active(id)) &
call t_error('t_stopf for time '//str//' is called without t_startf first')
found = .true.
active(id) = .false.
current_active = parent(id)
current_parent = parent(current_active)
call cpu_time(ttt)
time(id) = time(id) + ttt-time_start(id)
ncalls(id) = ncalls(id)+1
exit
end if
end do
if(.not.found) &
call t_error('timer '//str//' cannot be stopped as it was not started')
end
subroutine t_prf(rank)
use timer
use grid, only: masterproc
implicit none
integer, intent(in) :: rank
real ttt
integer i, iparents
call cpu_time(ttt)
time(1) = ttt-time0
if(.not.masterproc) return
print*,'------------------------------------------------------'
print*,'ntimers=',ntimers
print*,'------------ timer ----------Ncalls--------time(s)-------- % of total----'
call print_children(1,'a,T30,i9,T40,g15.7,T60,f6.2')
ttt = 0.
do i=1,ntimers
if(parent(i).eq.1) ttt = ttt+time(i)
end do
write(*,'(a,T40,g15.7,T60,f6.2)') 'TOTAL:',ttt,ttt/time(1)*100.
end