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

Last change on this file since 5327 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
RevLine 
[1632]1module times
[5117]2  INTEGER,PRIVATE,save :: Last_Count=0
3  REAL, PRIVATE,save :: Last_cpuCount=0
[5113]4  logical, PRIVATE,save :: AllTimer_IsActive=.FALSE.
[1632]5 
[5117]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
[1632]14 
[5116]15  INTEGER :: max_size
[5117]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
[1632]23 
[5119]24  CONTAINS
[1632]25 
[5103]26  SUBROUTINE init_timer
[1823]27    USE parallel_lmdz
[5159]28USE lmdz_dimensions, ONLY: iim, jjm, llm, ndm
29  USE lmdz_paramet
[5113]30    IMPLICIT NONE
[5159]31
32
[1632]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     
[5103]50  END SUBROUTINE  init_timer
[1632]51 
[5103]52  SUBROUTINE start_timer(no_timer)
[5128]53
54
[5113]55    IMPLICIT NONE
[5116]56    INTEGER :: no_timer
[1632]57   
[5117]58    IF (AllTimer_IsActive) THEN
59      IF (timer_state(no_timer)/=stopped) THEN
[4469]60        CALL abort_gcm("times","start_timer :: timer is already running or suspended",1)
[1632]61      else
62        timer_state(no_timer)=running
63      endif
64     
65      timer_running(no_timer)=0
[5101]66      CALL cpu_time(last_time(no_timer))
[1632]67   
68    endif
69   
[5103]70  END SUBROUTINE  start_timer
[1632]71 
[5103]72  SUBROUTINE suspend_timer(no_timer)
[5113]73    IMPLICIT NONE
[5116]74    INTEGER :: no_timer
[1632]75     
[5117]76    IF (AllTimer_IsActive) THEN
77      IF (timer_state(no_timer)/=running) THEN
[4469]78         CALL abort_gcm("times","suspend_timer :: timer is not running",1)
[1632]79      else
80        timer_state(no_timer)=suspended
81      endif
82   
83      timer_running(no_timer)=timer_running(no_timer)-last_time(no_timer)
[5101]84      CALL cpu_time(last_time(no_timer))
[1632]85      timer_running(no_timer)=timer_running(no_timer)+last_time(no_timer)
86    endif
[5103]87  END SUBROUTINE  suspend_timer
[1632]88 
[5103]89  SUBROUTINE resume_timer(no_timer)
[5113]90    IMPLICIT NONE
[5116]91    INTEGER :: no_timer
[1632]92     
[5117]93    IF (AllTimer_IsActive) THEN
94      IF (timer_state(no_timer)/=suspended) THEN
[4469]95        CALL abort_gcm("times","resume_timer :: timer is not suspended",1)
[1632]96      else
97        timer_state(no_timer)=running
98      endif
99     
[5101]100      CALL cpu_time(last_time(no_timer))
[1632]101    endif
102   
[5103]103  END SUBROUTINE  resume_timer
[1632]104
[5103]105  SUBROUTINE stop_timer(no_timer)
[1823]106    USE parallel_lmdz
[5113]107    IMPLICIT NONE
[5116]108    INTEGER :: no_timer
109    INTEGER :: N
110    REAL :: V,V2
[1632]111   
[5117]112    IF (AllTimer_IsActive) THEN
113      IF (timer_state(no_timer)/=running) THEN
[4469]114        CALL abort_gcm("times","stop_timer :: timer is not running",1)
[1632]115      else
116        timer_state(no_timer)=stopped
117      endif
118   
119      timer_running(no_timer)=timer_running(no_timer)-last_time(no_timer)
[5101]120      CALL cpu_time(last_time(no_timer))
[1632]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)
[5117]127      IF (timer_iteration(jj_nb,no_timer,mpi_rank)>=2) THEN
[1632]128        N=timer_iteration(jj_nb,no_timer,mpi_rank)
[5158]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))
[1632]132      else
133        timer_delta(jj_nb,no_timer,mpi_rank)=0
134      endif
135    endif
136   
[5103]137  END SUBROUTINE  stop_timer
[1632]138   
[5103]139  SUBROUTINE allgather_timer
[1823]140    USE parallel_lmdz
[4600]141    USE lmdz_mpi
[5113]142    IMPLICIT NONE
[4600]143
[5116]144    INTEGER :: ierr
145    INTEGER :: data_size
[5117]146    REAL, ALLOCATABLE,DIMENSION(:,:) :: tmp_table
[1632]147
148    IF (using_mpi) THEN   
149   
[5117]150      IF (AllTimer_IsActive) THEN
[1632]151      allocate(tmp_table(max_size,nb_timer))
152   
153      data_size=max_size*nb_timer
154   
155      tmp_table(:,:)=timer_table(:,:,mpi_rank)
[5101]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)
[1632]157      tmp_table(:,:)=timer_table_sqr(:,:,mpi_rank)
[5101]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)
[1632]159      deallocate(tmp_table)
160   
161      endif
162     
163    ENDIF ! using_mpi
164   
[5103]165  END SUBROUTINE  allgather_timer
[1632]166 
[5103]167  SUBROUTINE allgather_timer_average
[1823]168    USE parallel_lmdz
[4600]169    USE lmdz_mpi
[5113]170    IMPLICIT NONE
[5116]171    INTEGER :: ierr
172    INTEGER :: data_size
[5117]173    REAL, ALLOCATABLE,DIMENSION(:,:),target :: tmp_table
174    INTEGER, ALLOCATABLE,DIMENSION(:,:),target :: tmp_iter
[5116]175    INTEGER :: istats
[1632]176
177    IF (using_mpi) THEN
178       
[5117]179      IF (AllTimer_IsActive) THEN
[1632]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)
[5101]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)
[1632]187      tmp_table(:,:)=timer_delta(:,:,mpi_rank)
[5101]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)
[1632]189      tmp_iter(:,:)=timer_iteration(:,:,mpi_rank)
[5101]190      CALL mpi_allgather(tmp_iter(1,1),data_size,MPI_INTEGER,timer_iteration(1,1,0),data_size,MPI_INTEGER,COMM_LMDZ,ierr)
[1632]191      deallocate(tmp_table)
192   
193      endif
194     
[5093]195    ENDIF  ! using_mpi
[5103]196  END SUBROUTINE  allgather_timer_average
[1632]197 
[5103]198  SUBROUTINE InitTime
[5113]199  IMPLICIT NONE
[5116]200    INTEGER :: count,count_rate,count_max
[1632]201   
202    AllTimer_IsActive=.TRUE.
[5117]203    IF (AllTimer_IsActive) THEN
[5101]204      CALL system_clock(count,count_rate,count_max)
205      CALL cpu_time(Last_cpuCount)
[1632]206      Last_Count=count
207    endif
[5103]208  END SUBROUTINE  InitTime
[1632]209 
210  function DiffTime()
[5113]211  IMPLICIT NONE
[1632]212    double precision :: DiffTime
[5116]213    INTEGER :: count,count_rate,count_max
[1632]214 
[5101]215    CALL system_clock(count,count_rate,count_max)
[5117]216    IF (Count>=Last_Count) THEN
[1632]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
[5116]222  END FUNCTION DiffTime
[1632]223 
224  function DiffCpuTime()
[5113]225  IMPLICIT NONE
[5116]226    REAL :: DiffCpuTime
227    REAL :: Count
[1632]228   
[5101]229    CALL cpu_time(Count)
[1632]230    DiffCpuTime=Count-Last_cpuCount
231    Last_cpuCount=Count
[5116]232  END FUNCTION DiffCpuTime
[1632]233
[5119]234END MODULE times
Note: See TracBrowser for help on using the repository browser.