source: LMDZ4/branches/V3_test/libf/dyn3dpar/times.F90 @ 3733

Last change on this file since 3733 was 743, checked in by Laurent Fairhead, 18 years ago

Nettoyage sur la version YM
LF

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1module times
2  use parallel
3  integer,private,save :: Last_Count=0
4  real, private,save :: Last_cpuCount=0
5  logical, private,save :: AllTimer_IsActive=.true.
6 
7  integer, parameter :: nb_timer = 4
8  integer, parameter :: timer_caldyn  = 1
9  integer, parameter :: timer_vanleer = 2
10  integer, parameter :: timer_dissip = 3
11  integer, parameter :: timer_physic = 4
12  integer, parameter :: stopped = 1
13  integer, parameter :: running = 2
14  integer, parameter :: suspended = 3
15 
16  integer :: max_size
17  real,    allocatable, dimension(:,:,:) :: timer_table
18  real,    allocatable, dimension(:,:,:) :: timer_table_sqr
19  integer, allocatable, dimension(:,:,:) :: timer_iteration
20  real,    allocatable, dimension(:,:,:) :: timer_average
21  real,    allocatable, dimension(:,:,:) :: timer_delta
22  real,    allocatable,dimension(:) :: timer_running, last_time
23  integer, allocatable,dimension(:) :: timer_state
24 
25  contains
26 
27  subroutine init_timer
28    implicit none
29#include "dimensions90.h"
30#include "paramet90.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        stop 'start_timer :: timer is already running or suspended'
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        stop 'suspend_timer :: timer is not running'
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        stop 'resume_timer :: timer is not suspended'
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    implicit none
104    integer :: no_timer
105    integer :: N
106    real :: V,V2
107   
108    if (AllTimer_IsActive) then
109       
110      if (timer_state(no_timer)/=running) then
111        stop 'stop_timer :: timer is not running'
112      else
113        timer_state(no_timer)=stopped
114      endif
115   
116      timer_running(no_timer)=timer_running(no_timer)-last_time(no_timer)
117      call cpu_time(last_time(no_timer))
118      timer_running(no_timer)=timer_running(no_timer)+last_time(no_timer)
119   
120      timer_table(jj_nb,no_timer,mpi_rank)=timer_table(jj_nb,no_timer,mpi_rank)+timer_running(no_timer)
121      timer_table_sqr(jj_nb,no_timer,mpi_rank)=timer_table_sqr(jj_nb,no_timer,mpi_rank)+timer_running(no_timer)**2
122      timer_iteration(jj_nb,no_timer,mpi_rank)=timer_iteration(jj_nb,no_timer,mpi_rank)+1
123      timer_average(jj_nb,no_timer,mpi_rank)=timer_table(jj_nb,no_timer,mpi_rank)/timer_iteration(jj_nb,no_timer,mpi_rank)
124      if (timer_iteration(jj_nb,no_timer,mpi_rank)>=2) then
125        N=timer_iteration(jj_nb,no_timer,mpi_rank)
126        V2=timer_table_sqr(jj_nb,no_timer,mpi_rank)
127        V=timer_table(jj_nb,no_timer,mpi_rank)
128        timer_delta(jj_nb,no_timer,mpi_rank)=sqrt(abs(V2-V*V/N)/(N-1))
129      else
130        timer_delta(jj_nb,no_timer,mpi_rank)=0
131      endif
132    endif
133   
134  end subroutine stop_timer
135   
136  subroutine allgather_timer
137    implicit none
138    include 'mpif.h'
139    integer :: ierr
140    integer :: data_size
141    real, allocatable,dimension(:,:) :: tmp_table
142   
143    if (AllTimer_IsActive) then
144   
145    allocate(tmp_table(max_size,nb_timer))
146   
147    data_size=max_size*nb_timer
148   
149    tmp_table(:,:)=timer_table(:,:,mpi_rank)
150    call mpi_allgather(tmp_table(1,1),data_size,MPI_REAL8,timer_table(1,1,mpi_rank),data_size,MPI_REAL8,COMM_LMDZ,ierr)
151
152    tmp_table(:,:)=timer_table_sqr(:,:,mpi_rank)
153    call mpi_allgather(tmp_table(1,1),data_size,MPI_REAL8,timer_table_sqr(1,1,mpi_rank),data_size,MPI_REAL8,COMM_LMDZ,ierr)
154   
155    deallocate(tmp_table)
156   
157    endif
158   
159  end subroutine allgather_timer
160 
161  subroutine allgather_timer_average
162    implicit none
163    include 'mpif.h'
164    integer :: ierr
165    integer :: data_size
166    real, allocatable,dimension(:,:),target :: tmp_table
167    integer, allocatable,dimension(:,:),target :: tmp_iter
168    integer :: istats
169   
170    if (AllTimer_IsActive) then
171   
172    allocate(tmp_table(max_size,nb_timer))
173    allocate(tmp_iter(max_size,nb_timer))
174   
175    data_size=max_size*nb_timer
176
177    tmp_table(:,:)=timer_average(:,:,mpi_rank)
178    call mpi_allgather(tmp_table(1,1),data_size,MPI_REAL8,timer_average(1,1,0),data_size,MPI_REAL8,COMM_LMDZ,ierr)
179
180    tmp_table(:,:)=timer_delta(:,:,mpi_rank)
181    call mpi_allgather(tmp_table(1,1),data_size,MPI_REAL8,timer_delta(1,1,0),data_size,MPI_REAL8,COMM_LMDZ,ierr)
182
183    tmp_iter(:,:)=timer_iteration(:,:,mpi_rank)
184    call mpi_allgather(tmp_iter(1,1),data_size,MPI_INTEGER,timer_iteration(1,1,0),data_size,MPI_INTEGER,COMM_LMDZ,ierr)
185   
186    deallocate(tmp_table)
187   
188    endif
189  end subroutine allgather_timer_average
190 
191  subroutine InitTime
192  implicit none
193    integer :: count,count_rate,count_max
194   
195    if (AllTimer_IsActive) then
196    call system_clock(count,count_rate,count_max)
197    call cpu_time(Last_cpuCount)
198    Last_Count=count
199    endif
200  end subroutine InitTime
201 
202  function DiffTime
203  implicit none
204    double precision :: DiffTime
205    integer :: count,count_rate,count_max
206 
207    call system_clock(count,count_rate,count_max)
208    if (Count>=Last_Count) then
209      DiffTime=(1.*(Count-last_Count))/count_rate
210    else
211      DiffTime=(1.*(Count-last_Count+Count_max))/count_rate
212    endif
213    Last_Count=Count
214  end function DiffTime
215 
216  function DiffCpuTime
217  implicit none
218    real :: DiffCpuTime
219    real :: Count
220   
221    call cpu_time(Count)
222    DiffCpuTime=Count-Last_cpuCount
223    Last_cpuCount=Count
224  end function DiffCpuTime
225
226end module times
Note: See TracBrowser for help on using the repository browser.