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

Last change on this file since 5119 was 5119, checked in by abarral, 4 months ago

enforce PRIVATE by default in several modules, expose PUBLIC as needed
move eigen.f90 to obsolete/
(lint) aslong the way

  • 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.0 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
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      IF (timer_state(no_timer)/=stopped) THEN
56        CALL abort_gcm("times","start_timer :: timer is already running or suspended",1)
57      else
58        timer_state(no_timer)=running
59      endif
60     
61      timer_running(no_timer)=0
62      CALL cpu_time(last_time(no_timer))
63   
64    endif
65   
66  END SUBROUTINE  start_timer
67 
68  SUBROUTINE suspend_timer(no_timer)
69    IMPLICIT NONE
70    INTEGER :: no_timer
71     
72    IF (AllTimer_IsActive) THEN
73      IF (timer_state(no_timer)/=running) THEN
74         CALL abort_gcm("times","suspend_timer :: timer is not running",1)
75      else
76        timer_state(no_timer)=suspended
77      endif
78   
79      timer_running(no_timer)=timer_running(no_timer)-last_time(no_timer)
80      CALL cpu_time(last_time(no_timer))
81      timer_running(no_timer)=timer_running(no_timer)+last_time(no_timer)
82    endif
83  END SUBROUTINE  suspend_timer
84 
85  SUBROUTINE resume_timer(no_timer)
86    IMPLICIT NONE
87    INTEGER :: no_timer
88     
89    IF (AllTimer_IsActive) THEN
90      IF (timer_state(no_timer)/=suspended) THEN
91        CALL abort_gcm("times","resume_timer :: timer is not suspended",1)
92      else
93        timer_state(no_timer)=running
94      endif
95     
96      CALL cpu_time(last_time(no_timer))
97    endif
98   
99  END SUBROUTINE  resume_timer
100
101  SUBROUTINE stop_timer(no_timer)
102    USE parallel_lmdz
103    IMPLICIT NONE
104    INTEGER :: no_timer
105    INTEGER :: N
106    REAL :: V,V2
107   
108    IF (AllTimer_IsActive) THEN
109      IF (timer_state(no_timer)/=running) THEN
110        CALL abort_gcm("times","stop_timer :: timer is not running",1)
111      else
112        timer_state(no_timer)=stopped
113      endif
114   
115      timer_running(no_timer)=timer_running(no_timer)-last_time(no_timer)
116      CALL cpu_time(last_time(no_timer))
117      timer_running(no_timer)=timer_running(no_timer)+last_time(no_timer)
118   
119      timer_table(jj_nb,no_timer,mpi_rank)=timer_table(jj_nb,no_timer,mpi_rank)+timer_running(no_timer)
120      timer_table_sqr(jj_nb,no_timer,mpi_rank)=timer_table_sqr(jj_nb,no_timer,mpi_rank)+timer_running(no_timer)**2
121      timer_iteration(jj_nb,no_timer,mpi_rank)=timer_iteration(jj_nb,no_timer,mpi_rank)+1
122      timer_average(jj_nb,no_timer,mpi_rank)=timer_table(jj_nb,no_timer,mpi_rank)/timer_iteration(jj_nb,no_timer,mpi_rank)
123      IF (timer_iteration(jj_nb,no_timer,mpi_rank)>=2) THEN
124        N=timer_iteration(jj_nb,no_timer,mpi_rank)
125        V2=timer_table_sqr(jj_nb,no_timer,mpi_rank)
126        V=timer_table(jj_nb,no_timer,mpi_rank)
127        timer_delta(jj_nb,no_timer,mpi_rank)=sqrt(ABS(V2-V*V/N)/(N-1))
128      else
129        timer_delta(jj_nb,no_timer,mpi_rank)=0
130      endif
131    endif
132   
133  END SUBROUTINE  stop_timer
134   
135  SUBROUTINE allgather_timer
136    USE parallel_lmdz
137    USE lmdz_mpi
138    IMPLICIT NONE
139
140    INTEGER :: ierr
141    INTEGER :: data_size
142    REAL, ALLOCATABLE,DIMENSION(:,:) :: tmp_table
143
144    IF (using_mpi) THEN   
145   
146      IF (AllTimer_IsActive) THEN
147      allocate(tmp_table(max_size,nb_timer))
148   
149      data_size=max_size*nb_timer
150   
151      tmp_table(:,:)=timer_table(:,:,mpi_rank)
152      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)
153      tmp_table(:,:)=timer_table_sqr(:,:,mpi_rank)
154      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)
155      deallocate(tmp_table)
156   
157      endif
158     
159    ENDIF ! using_mpi
160   
161  END SUBROUTINE  allgather_timer
162 
163  SUBROUTINE allgather_timer_average
164    USE parallel_lmdz
165    USE lmdz_mpi
166    IMPLICIT NONE
167    INTEGER :: ierr
168    INTEGER :: data_size
169    REAL, ALLOCATABLE,DIMENSION(:,:),target :: tmp_table
170    INTEGER, ALLOCATABLE,DIMENSION(:,:),target :: tmp_iter
171    INTEGER :: istats
172
173    IF (using_mpi) THEN
174       
175      IF (AllTimer_IsActive) THEN
176      allocate(tmp_table(max_size,nb_timer))
177      allocate(tmp_iter(max_size,nb_timer))
178   
179      data_size=max_size*nb_timer
180
181      tmp_table(:,:)=timer_average(:,:,mpi_rank)
182      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)
183      tmp_table(:,:)=timer_delta(:,:,mpi_rank)
184      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)
185      tmp_iter(:,:)=timer_iteration(:,:,mpi_rank)
186      CALL mpi_allgather(tmp_iter(1,1),data_size,MPI_INTEGER,timer_iteration(1,1,0),data_size,MPI_INTEGER,COMM_LMDZ,ierr)
187      deallocate(tmp_table)
188   
189      endif
190     
191    ENDIF  ! using_mpi
192  END SUBROUTINE  allgather_timer_average
193 
194  SUBROUTINE InitTime
195  IMPLICIT NONE
196    INTEGER :: count,count_rate,count_max
197   
198    AllTimer_IsActive=.TRUE.
199    IF (AllTimer_IsActive) THEN
200      CALL system_clock(count,count_rate,count_max)
201      CALL cpu_time(Last_cpuCount)
202      Last_Count=count
203    endif
204  END SUBROUTINE  InitTime
205 
206  function DiffTime()
207  IMPLICIT NONE
208    double precision :: DiffTime
209    INTEGER :: count,count_rate,count_max
210 
211    CALL system_clock(count,count_rate,count_max)
212    IF (Count>=Last_Count) THEN
213      DiffTime=(1.*(Count-last_Count))/count_rate
214    else
215      DiffTime=(1.*(Count-last_Count+Count_max))/count_rate
216    endif
217    Last_Count=Count
218  END FUNCTION DiffTime
219 
220  function DiffCpuTime()
221  IMPLICIT NONE
222    REAL :: DiffCpuTime
223    REAL :: Count
224   
225    CALL cpu_time(Count)
226    DiffCpuTime=Count-Last_cpuCount
227    Last_cpuCount=Count
228  END FUNCTION DiffCpuTime
229
230END MODULE times
Note: See TracBrowser for help on using the repository browser.