source: LMDZ6/branches/Amaury_dev/libf/dyn3dmem/times.F90 @ 5214

Last change on this file since 5214 was 5159, checked in by abarral, 3 months ago

Put dimensions.h and paramet.h into modules

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
File size: 7.1 KB
Line 
1module 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
28USE lmdz_dimensions, ONLY: iim, jjm, llm, ndm
29  USE lmdz_paramet
30    IMPLICIT NONE
31
32
33   
34    max_size=jjm+1
35    allocate(timer_table(max_size,nb_timer,0:mpi_size-1))
36    allocate(timer_table_sqr(max_size,nb_timer,0:mpi_size-1))
37    allocate(timer_iteration(max_size,nb_timer,0:mpi_size-1))
38    allocate(timer_average(max_size,nb_timer,0:mpi_size-1))
39    allocate(timer_delta(max_size,nb_timer,0:mpi_size-1))
40    allocate(timer_running(nb_timer))
41    allocate(timer_state(nb_timer))
42    allocate(last_time(nb_timer))
43   
44    timer_table(:,:,:)=0
45    timer_table_sqr(:,:,:)=0
46    timer_iteration(:,:,:)=0
47    timer_average(:,:,:)=0
48    timer_delta(:,:,:)=0
49    timer_state(:)=stopped     
50  END SUBROUTINE  init_timer
51 
52  SUBROUTINE start_timer(no_timer)
53
54
55    IMPLICIT NONE
56    INTEGER :: no_timer
57   
58    IF (AllTimer_IsActive) THEN
59      IF (timer_state(no_timer)/=stopped) THEN
60        CALL abort_gcm("times","start_timer :: timer is already running or suspended",1)
61      else
62        timer_state(no_timer)=running
63      endif
64     
65      timer_running(no_timer)=0
66      CALL cpu_time(last_time(no_timer))
67   
68    endif
69   
70  END SUBROUTINE  start_timer
71 
72  SUBROUTINE suspend_timer(no_timer)
73    IMPLICIT NONE
74    INTEGER :: no_timer
75     
76    IF (AllTimer_IsActive) THEN
77      IF (timer_state(no_timer)/=running) THEN
78         CALL abort_gcm("times","suspend_timer :: timer is not running",1)
79      else
80        timer_state(no_timer)=suspended
81      endif
82   
83      timer_running(no_timer)=timer_running(no_timer)-last_time(no_timer)
84      CALL cpu_time(last_time(no_timer))
85      timer_running(no_timer)=timer_running(no_timer)+last_time(no_timer)
86    endif
87  END SUBROUTINE  suspend_timer
88 
89  SUBROUTINE resume_timer(no_timer)
90    IMPLICIT NONE
91    INTEGER :: no_timer
92     
93    IF (AllTimer_IsActive) THEN
94      IF (timer_state(no_timer)/=suspended) THEN
95        CALL abort_gcm("times","resume_timer :: timer is not suspended",1)
96      else
97        timer_state(no_timer)=running
98      endif
99     
100      CALL cpu_time(last_time(no_timer))
101    endif
102   
103  END SUBROUTINE  resume_timer
104
105  SUBROUTINE stop_timer(no_timer)
106    USE parallel_lmdz
107    IMPLICIT NONE
108    INTEGER :: no_timer
109    INTEGER :: N
110    REAL :: V,V2
111   
112    IF (AllTimer_IsActive) THEN
113      IF (timer_state(no_timer)/=running) THEN
114        CALL abort_gcm("times","stop_timer :: timer is not running",1)
115      else
116        timer_state(no_timer)=stopped
117      endif
118   
119      timer_running(no_timer)=timer_running(no_timer)-last_time(no_timer)
120      CALL cpu_time(last_time(no_timer))
121      timer_running(no_timer)=timer_running(no_timer)+last_time(no_timer)
122   
123      timer_table(jj_nb,no_timer,mpi_rank)=timer_table(jj_nb,no_timer,mpi_rank)+timer_running(no_timer)
124      timer_table_sqr(jj_nb,no_timer,mpi_rank)=timer_table_sqr(jj_nb,no_timer,mpi_rank)+timer_running(no_timer)**2
125      timer_iteration(jj_nb,no_timer,mpi_rank)=timer_iteration(jj_nb,no_timer,mpi_rank)+1
126      timer_average(jj_nb,no_timer,mpi_rank)=timer_table(jj_nb,no_timer,mpi_rank)/timer_iteration(jj_nb,no_timer,mpi_rank)
127      IF (timer_iteration(jj_nb,no_timer,mpi_rank)>=2) THEN
128        N=timer_iteration(jj_nb,no_timer,mpi_rank)
129    V2=timer_table_sqr(jj_nb,no_timer,mpi_rank)
130    V=timer_table(jj_nb,no_timer,mpi_rank)
131    timer_delta(jj_nb,no_timer,mpi_rank)=sqrt(ABS(V2-V*V/N)/(N-1))
132      else
133        timer_delta(jj_nb,no_timer,mpi_rank)=0
134      endif
135    endif
136   
137  END SUBROUTINE  stop_timer
138   
139  SUBROUTINE allgather_timer
140    USE parallel_lmdz
141    USE lmdz_mpi
142    IMPLICIT NONE
143
144    INTEGER :: ierr
145    INTEGER :: data_size
146    REAL, ALLOCATABLE,DIMENSION(:,:) :: tmp_table
147
148    IF (using_mpi) THEN   
149   
150      IF (AllTimer_IsActive) THEN
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      allocate(tmp_table(max_size,nb_timer))
181      allocate(tmp_iter(max_size,nb_timer))
182   
183      data_size=max_size*nb_timer
184
185      tmp_table(:,:)=timer_average(:,:,mpi_rank)
186      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)
187      tmp_table(:,:)=timer_delta(:,:,mpi_rank)
188      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)
189      tmp_iter(:,:)=timer_iteration(:,:,mpi_rank)
190      CALL mpi_allgather(tmp_iter(1,1),data_size,MPI_INTEGER,timer_iteration(1,1,0),data_size,MPI_INTEGER,COMM_LMDZ,ierr)
191      deallocate(tmp_table)
192   
193      endif
194     
195    ENDIF  ! using_mpi
196  END SUBROUTINE  allgather_timer_average
197 
198  SUBROUTINE InitTime
199  IMPLICIT NONE
200    INTEGER :: count,count_rate,count_max
201   
202    AllTimer_IsActive=.TRUE.
203    IF (AllTimer_IsActive) THEN
204      CALL system_clock(count,count_rate,count_max)
205      CALL cpu_time(Last_cpuCount)
206      Last_Count=count
207    endif
208  END SUBROUTINE  InitTime
209 
210  function DiffTime()
211  IMPLICIT NONE
212    double precision :: DiffTime
213    INTEGER :: count,count_rate,count_max
214 
215    CALL system_clock(count,count_rate,count_max)
216    IF (Count>=Last_Count) THEN
217      DiffTime=(1.*(Count-last_Count))/count_rate
218    else
219      DiffTime=(1.*(Count-last_Count+Count_max))/count_rate
220    endif
221    Last_Count=Count
222  END FUNCTION DiffTime
223 
224  function DiffCpuTime()
225  IMPLICIT NONE
226    REAL :: DiffCpuTime
227    REAL :: Count
228   
229    CALL cpu_time(Count)
230    DiffCpuTime=Count-Last_cpuCount
231    Last_cpuCount=Count
232  END FUNCTION DiffCpuTime
233
234END MODULE times
Note: See TracBrowser for help on using the repository browser.