2 integer,
private,
save :: last_count=0
3 real,
private,
save :: last_cpucount=0
4 logical,
private,
save :: alltimer_isactive=.
false.
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
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
29 #include "dimensions.h"
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))
43 timer_table_sqr(:,:,:)=0
44 timer_iteration(:,:,:)=0
45 timer_average(:,:,:)=0
47 timer_state(:)=stopped
54 if (alltimer_isactive)
then
56 if (timer_state(no_timer)/=stopped)
then
57 stop
'start_timer :: timer is already running or suspended'
59 timer_state(no_timer)=running
62 timer_running(no_timer)=0
63 call cpu_time(last_time(no_timer))
73 if (alltimer_isactive)
then
74 if (timer_state(no_timer)/=running)
then
75 stop
'suspend_timer :: timer is not running'
77 timer_state(no_timer)=suspended
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)
90 if (alltimer_isactive)
then
91 if (timer_state(no_timer)/=suspended)
then
92 stop
'resume_timer :: timer is not suspended'
94 timer_state(no_timer)=running
97 call cpu_time(last_time(no_timer))
109 if (alltimer_isactive)
then
111 if (timer_state(no_timer)/=running)
then
112 stop
'stop_timer :: timer is not running'
114 timer_state(no_timer)=stopped
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)
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))
131 timer_delta(
jj_nb,no_timer,mpi_rank)=0
145 real,
allocatable,
dimension(:,:) :: tmp_table
149 if (alltimer_isactive)
then
152 allocate(tmp_table(max_size,nb_timer))
154 data_size=max_size*nb_timer
156 tmp_table(:,:)=timer_table(:,:,mpi_rank)
158 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)
160 tmp_table(:,:)=timer_table_sqr(:,:,mpi_rank)
162 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)
164 deallocate(tmp_table)
180 real,
allocatable,
dimension(:,:),
target :: tmp_table
181 integer,
allocatable,
dimension(:,:),
target :: tmp_iter
186 if (alltimer_isactive)
then
188 allocate(tmp_table(max_size,nb_timer))
189 allocate(tmp_iter(max_size,nb_timer))
191 data_size=max_size*nb_timer
193 tmp_table(:,:)=timer_average(:,:,mpi_rank)
195 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)
197 tmp_table(:,:)=timer_delta(:,:,mpi_rank)
199 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)
201 tmp_iter(:,:)=timer_iteration(:,:,mpi_rank)
203 call mpi_allgather(tmp_iter(1,1),data_size,mpi_integer,timer_iteration(1,1,0),data_size,mpi_integer,comm_lmdz,ierr)
205 deallocate(tmp_table)
214 integer :: count,count_rate,count_max
216 alltimer_isactive=.true.
217 if (alltimer_isactive)
then
218 call system_clock(count,count_rate,count_max)
219 call cpu_time(last_cpucount)
227 integer :: count,count_rate,count_max
229 call system_clock(count,count_rate,count_max)
230 if (count>=last_count)
then
231 difftime=(1.*(count-last_count))/count_rate
233 difftime=(1.*(count-last_count+count_max))/count_rate