-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtiming.f90
152 lines (117 loc) · 3.32 KB
/
timing.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
subroutine start_timing(cTimingNameIn)
use ModTimingGITM
use ModMpi
implicit none
character (LEN=*), intent(in) :: cTimingNameIn
integer :: i, iTiming, iLevel
logical :: IsFirstTime = .true.
if (IsFirstTime) then
IsFirstTime = .false.
Timings = 0.0
iTimingLevel = 0
IsTiming = .false.
endif
iLevel = 0
iTiming = -1
do i=1,nTiming
if (IsTiming(i)) iLevel = iLevel + 1
if (index(cTimingNames(i),cTimingNameIn) > 0) then
iTiming = i
endif
enddo
if (iTiming < 0) then
nTiming = nTiming + 1
cTimingNames(nTiming) = cTimingNameIn
iTiming = nTiming
endif
IsTiming(iTiming) = .true.
if (iTimingLevel(iTiming) < iLevel) iTimingLevel(iTiming) = iLevel
Timings(iTiming,1) = mpi_wtime()
end subroutine start_timing
!---------------------------------------------------------------------
!
!---------------------------------------------------------------------
subroutine end_timing(cTimingNameIn)
use ModTimingGITM
use ModMpi
implicit none
character (LEN=*), intent(in) :: cTimingNameIn
integer :: i, iTiming
iTiming = -1
do i=1,nTiming
if (index(cTimingNames(i),cTimingNameIn) > 0) then
iTiming = i
endif
enddo
if (iTiming < 0) then
write(*,*) "Unknown timing : ",cTimingNameIn
return
endif
IsTiming(iTiming) = .false.
Timings(iTiming,2) = Timings(iTiming,2) + &
(mpi_wtime() - Timings(iTiming,1))
end subroutine end_timing
!---------------------------------------------------------------------
!
!---------------------------------------------------------------------
real function get_timing(cTimingNameIn)
use ModTimingGITM
use ModMpi
implicit none
character (LEN=*), intent(in) :: cTimingNameIn
integer :: i, iTiming
iTiming = -1
do i=1,nTiming
if (index(cTimingNames(i),cTimingNameIn) > 0) then
iTiming = i
endif
enddo
if (iTiming < 0) then
write(*,*) "Error!!"
write(*,*) "Unknown timing : ",cTimingNameIn
get_timing = 0.0
else
if (IsTiming(iTiming)) then
get_timing = mpi_wtime() - Timings(iTiming,1)
else
get_timing = Timings(iTiming,2)
endif
endif
end function get_timing
!---------------------------------------------------------------------
!
!---------------------------------------------------------------------
subroutine report_timing(cTimingNameIn)
use ModTimingGITM
use ModMpi
implicit none
character (LEN=*), intent(in) :: cTimingNameIn
character (len=10) :: cLevel, clevelSpace
integer :: i, iTiming
cLevel = "----------"
cLevelSpace = " "
if (index(cTimingNameIn,'all') > 0) then
do iTiming=1,nTiming
write(*,"(a,a,a,a,a,f7.1,a)") &
clevel(1:iTimingLevel(iTiming)+1),"> ",&
cTimingNames(iTiming),&
clevelSpace(1:5-iTimingLevel(iTiming)),&
" took ",Timings(iTiming,2),&
" seconds to complete"
enddo
return
endif
iTiming = -1
do i=1,nTiming
if (index(cTimingNames(i),cTimingNameIn) > 0) then
iTiming = i
endif
enddo
if (iTiming < 0) then
write(*,*) "Unknown timing : ",cTimingNameIn
return
endif
write(*,"(a,a,f7.1,a)") &
cTimingNames(iTiming)," took ",Timings(iTiming,2),&
" seconds to complete", iTimingLevel(iTiming)
end subroutine report_timing