1 | module times |
---|
2 | integer,PRIVATE,save :: Last_Count=0 |
---|
3 | real, PRIVATE,save :: Last_cpuCount=0 |
---|
4 | logical, PRIVATE,save :: AllTimer_IsActive=.FALSE. |
---|
5 | |
---|
6 | integer, parameter :: nb_timer = 4 |
---|
7 | integer, parameter :: timer_caldyn = 1 |
---|
8 | integer, parameter :: timer_vanleer = 2 |
---|
9 | integer, parameter :: timer_dissip = 3 |
---|
10 | integer, parameter :: timer_physic = 4 |
---|
11 | integer, parameter :: stopped = 1 |
---|
12 | integer, parameter :: running = 2 |
---|
13 | integer, parameter :: suspended = 3 |
---|
14 | |
---|
15 | integer :: max_size |
---|
16 | real, allocatable, dimension(:,:,:) :: timer_table |
---|
17 | real, allocatable, dimension(:,:,:) :: timer_table_sqr |
---|
18 | integer, allocatable, dimension(:,:,:) :: timer_iteration |
---|
19 | real, allocatable, dimension(:,:,:) :: timer_average |
---|
20 | real, allocatable, dimension(:,:,:) :: timer_delta |
---|
21 | real, allocatable,dimension(:) :: timer_running, last_time |
---|
22 | integer, allocatable,dimension(:) :: timer_state |
---|
23 | |
---|
24 | contains |
---|
25 | |
---|
26 | SUBROUTINE init_timer |
---|
27 | USE parallel_lmdz |
---|
28 | IMPLICIT NONE |
---|
29 | INCLUDE "dimensions.h" |
---|
30 | INCLUDE "paramet.h" |
---|
31 | |
---|
32 | max_size=jjm+1 |
---|
33 | allocate(timer_table(max_size,nb_timer,0:mpi_size-1)) |
---|
34 | allocate(timer_table_sqr(max_size,nb_timer,0:mpi_size-1)) |
---|
35 | allocate(timer_iteration(max_size,nb_timer,0:mpi_size-1)) |
---|
36 | allocate(timer_average(max_size,nb_timer,0:mpi_size-1)) |
---|
37 | allocate(timer_delta(max_size,nb_timer,0:mpi_size-1)) |
---|
38 | allocate(timer_running(nb_timer)) |
---|
39 | allocate(timer_state(nb_timer)) |
---|
40 | allocate(last_time(nb_timer)) |
---|
41 | |
---|
42 | timer_table(:,:,:)=0 |
---|
43 | timer_table_sqr(:,:,:)=0 |
---|
44 | timer_iteration(:,:,:)=0 |
---|
45 | timer_average(:,:,:)=0 |
---|
46 | timer_delta(:,:,:)=0 |
---|
47 | timer_state(:)=stopped |
---|
48 | END SUBROUTINE init_timer |
---|
49 | |
---|
50 | SUBROUTINE start_timer(no_timer) |
---|
51 | IMPLICIT NONE |
---|
52 | integer :: no_timer |
---|
53 | |
---|
54 | if (AllTimer_IsActive) then |
---|
55 | |
---|
56 | if (timer_state(no_timer)/=stopped) then |
---|
57 | CALL abort_gcm("times","start_timer :: timer is already running or suspended",1) |
---|
58 | else |
---|
59 | timer_state(no_timer)=running |
---|
60 | endif |
---|
61 | |
---|
62 | timer_running(no_timer)=0 |
---|
63 | CALL cpu_time(last_time(no_timer)) |
---|
64 | |
---|
65 | endif |
---|
66 | |
---|
67 | END SUBROUTINE start_timer |
---|
68 | |
---|
69 | SUBROUTINE suspend_timer(no_timer) |
---|
70 | IMPLICIT NONE |
---|
71 | integer :: no_timer |
---|
72 | |
---|
73 | if (AllTimer_IsActive) then |
---|
74 | if (timer_state(no_timer)/=running) then |
---|
75 | CALL abort_gcm("times","suspend_timer :: timer is not running",1) |
---|
76 | else |
---|
77 | timer_state(no_timer)=suspended |
---|
78 | endif |
---|
79 | |
---|
80 | timer_running(no_timer)=timer_running(no_timer)-last_time(no_timer) |
---|
81 | CALL cpu_time(last_time(no_timer)) |
---|
82 | timer_running(no_timer)=timer_running(no_timer)+last_time(no_timer) |
---|
83 | endif |
---|
84 | END SUBROUTINE suspend_timer |
---|
85 | |
---|
86 | SUBROUTINE resume_timer(no_timer) |
---|
87 | IMPLICIT NONE |
---|
88 | integer :: no_timer |
---|
89 | |
---|
90 | if (AllTimer_IsActive) then |
---|
91 | if (timer_state(no_timer)/=suspended) then |
---|
92 | CALL abort_gcm("times","resume_timer :: timer is not suspended",1) |
---|
93 | else |
---|
94 | timer_state(no_timer)=running |
---|
95 | endif |
---|
96 | |
---|
97 | CALL cpu_time(last_time(no_timer)) |
---|
98 | endif |
---|
99 | |
---|
100 | END SUBROUTINE resume_timer |
---|
101 | |
---|
102 | SUBROUTINE stop_timer(no_timer) |
---|
103 | USE parallel_lmdz |
---|
104 | IMPLICIT NONE |
---|
105 | integer :: no_timer |
---|
106 | integer :: N |
---|
107 | real :: V,V2 |
---|
108 | |
---|
109 | if (AllTimer_IsActive) then |
---|
110 | |
---|
111 | if (timer_state(no_timer)/=running) then |
---|
112 | CALL abort_gcm("times","stop_timer :: timer is not running",1) |
---|
113 | else |
---|
114 | timer_state(no_timer)=stopped |
---|
115 | endif |
---|
116 | |
---|
117 | timer_running(no_timer)=timer_running(no_timer)-last_time(no_timer) |
---|
118 | CALL cpu_time(last_time(no_timer)) |
---|
119 | timer_running(no_timer)=timer_running(no_timer)+last_time(no_timer) |
---|
120 | |
---|
121 | timer_table(jj_nb,no_timer,mpi_rank)=timer_table(jj_nb,no_timer,mpi_rank)+timer_running(no_timer) |
---|
122 | timer_table_sqr(jj_nb,no_timer,mpi_rank)=timer_table_sqr(jj_nb,no_timer,mpi_rank)+timer_running(no_timer)**2 |
---|
123 | timer_iteration(jj_nb,no_timer,mpi_rank)=timer_iteration(jj_nb,no_timer,mpi_rank)+1 |
---|
124 | timer_average(jj_nb,no_timer,mpi_rank)=timer_table(jj_nb,no_timer,mpi_rank)/timer_iteration(jj_nb,no_timer,mpi_rank) |
---|
125 | if (timer_iteration(jj_nb,no_timer,mpi_rank)>=2) then |
---|
126 | N=timer_iteration(jj_nb,no_timer,mpi_rank) |
---|
127 | V2=timer_table_sqr(jj_nb,no_timer,mpi_rank) |
---|
128 | V=timer_table(jj_nb,no_timer,mpi_rank) |
---|
129 | timer_delta(jj_nb,no_timer,mpi_rank)=sqrt(ABS(V2-V*V/N)/(N-1)) |
---|
130 | else |
---|
131 | timer_delta(jj_nb,no_timer,mpi_rank)=0 |
---|
132 | endif |
---|
133 | endif |
---|
134 | |
---|
135 | END SUBROUTINE stop_timer |
---|
136 | |
---|
137 | SUBROUTINE allgather_timer |
---|
138 | USE parallel_lmdz |
---|
139 | USE lmdz_mpi |
---|
140 | IMPLICIT NONE |
---|
141 | |
---|
142 | integer :: ierr |
---|
143 | integer :: data_size |
---|
144 | real, allocatable,dimension(:,:) :: tmp_table |
---|
145 | |
---|
146 | IF (using_mpi) THEN |
---|
147 | |
---|
148 | if (AllTimer_IsActive) then |
---|
149 | |
---|
150 | |
---|
151 | allocate(tmp_table(max_size,nb_timer)) |
---|
152 | |
---|
153 | data_size=max_size*nb_timer |
---|
154 | |
---|
155 | tmp_table(:,:)=timer_table(:,:,mpi_rank) |
---|
156 | CALL mpi_allgather(tmp_table(1,1),data_size,MPI_REAL_LMDZ,timer_table(1,1,0),data_size,MPI_REAL_LMDZ,COMM_LMDZ,ierr) |
---|
157 | tmp_table(:,:)=timer_table_sqr(:,:,mpi_rank) |
---|
158 | CALL mpi_allgather(tmp_table(1,1),data_size,MPI_REAL_LMDZ,timer_table_sqr(1,1,0),data_size,MPI_REAL_LMDZ,COMM_LMDZ,ierr) |
---|
159 | deallocate(tmp_table) |
---|
160 | |
---|
161 | endif |
---|
162 | |
---|
163 | ENDIF ! using_mpi |
---|
164 | |
---|
165 | END SUBROUTINE allgather_timer |
---|
166 | |
---|
167 | SUBROUTINE allgather_timer_average |
---|
168 | USE parallel_lmdz |
---|
169 | USE lmdz_mpi |
---|
170 | IMPLICIT NONE |
---|
171 | integer :: ierr |
---|
172 | integer :: data_size |
---|
173 | real, allocatable,dimension(:,:),target :: tmp_table |
---|
174 | integer, allocatable,dimension(:,:),target :: tmp_iter |
---|
175 | integer :: istats |
---|
176 | |
---|
177 | IF (using_mpi) THEN |
---|
178 | |
---|
179 | if (AllTimer_IsActive) then |
---|
180 | |
---|
181 | allocate(tmp_table(max_size,nb_timer)) |
---|
182 | allocate(tmp_iter(max_size,nb_timer)) |
---|
183 | |
---|
184 | data_size=max_size*nb_timer |
---|
185 | |
---|
186 | tmp_table(:,:)=timer_average(:,:,mpi_rank) |
---|
187 | CALL mpi_allgather(tmp_table(1,1),data_size,MPI_REAL_LMDZ,timer_average(1,1,0),data_size,MPI_REAL_LMDZ,COMM_LMDZ,ierr) |
---|
188 | tmp_table(:,:)=timer_delta(:,:,mpi_rank) |
---|
189 | CALL mpi_allgather(tmp_table(1,1),data_size,MPI_REAL_LMDZ,timer_delta(1,1,0),data_size,MPI_REAL_LMDZ,COMM_LMDZ,ierr) |
---|
190 | tmp_iter(:,:)=timer_iteration(:,:,mpi_rank) |
---|
191 | CALL mpi_allgather(tmp_iter(1,1),data_size,MPI_INTEGER,timer_iteration(1,1,0),data_size,MPI_INTEGER,COMM_LMDZ,ierr) |
---|
192 | deallocate(tmp_table) |
---|
193 | |
---|
194 | endif |
---|
195 | |
---|
196 | ENDIF ! using_mpi |
---|
197 | END SUBROUTINE allgather_timer_average |
---|
198 | |
---|
199 | SUBROUTINE InitTime |
---|
200 | IMPLICIT NONE |
---|
201 | integer :: count,count_rate,count_max |
---|
202 | |
---|
203 | AllTimer_IsActive=.TRUE. |
---|
204 | if (AllTimer_IsActive) then |
---|
205 | CALL system_clock(count,count_rate,count_max) |
---|
206 | CALL cpu_time(Last_cpuCount) |
---|
207 | Last_Count=count |
---|
208 | endif |
---|
209 | END SUBROUTINE InitTime |
---|
210 | |
---|
211 | function DiffTime() |
---|
212 | IMPLICIT NONE |
---|
213 | double precision :: DiffTime |
---|
214 | integer :: count,count_rate,count_max |
---|
215 | |
---|
216 | CALL system_clock(count,count_rate,count_max) |
---|
217 | if (Count>=Last_Count) then |
---|
218 | DiffTime=(1.*(Count-last_Count))/count_rate |
---|
219 | else |
---|
220 | DiffTime=(1.*(Count-last_Count+Count_max))/count_rate |
---|
221 | endif |
---|
222 | Last_Count=Count |
---|
223 | end function DiffTime |
---|
224 | |
---|
225 | function DiffCpuTime() |
---|
226 | IMPLICIT NONE |
---|
227 | real :: DiffCpuTime |
---|
228 | real :: Count |
---|
229 | |
---|
230 | CALL cpu_time(Count) |
---|
231 | DiffCpuTime=Count-Last_cpuCount |
---|
232 | Last_cpuCount=Count |
---|
233 | end function DiffCpuTime |
---|
234 | |
---|
235 | end module times |
---|