[630] | 1 | module times |
---|
| 2 | integer,private,save :: Last_Count=0 |
---|
| 3 | real, private,save :: Last_cpuCount=0 |
---|
[774] | 4 | logical, private,save :: AllTimer_IsActive=.false. |
---|
[630] | 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 |
---|
[1864] | 27 | USE parallel_lmdz |
---|
[630] | 28 | implicit none |
---|
[792] | 29 | #include "dimensions.h" |
---|
| 30 | #include "paramet.h" |
---|
[630] | 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) |
---|
[1864] | 103 | USE parallel_lmdz |
---|
[630] | 104 | implicit none |
---|
| 105 | integer :: no_timer |
---|
| 106 | integer :: N |
---|
| 107 | real :: V,V2 |
---|
| 108 | |
---|
| 109 | if (AllTimer_IsActive) then |
---|
| 110 | |
---|
| 111 | if (timer_state(no_timer)/=running) then |
---|
| 112 | stop 'stop_timer :: timer is not running' |
---|
| 113 | else |
---|
| 114 | timer_state(no_timer)=stopped |
---|
| 115 | endif |
---|
| 116 | |
---|
| 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) |
---|
| 120 | |
---|
| 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) |
---|
[774] | 129 | timer_delta(jj_nb,no_timer,mpi_rank)=sqrt(ABS(V2-V*V/N)/(N-1)) |
---|
[630] | 130 | else |
---|
| 131 | timer_delta(jj_nb,no_timer,mpi_rank)=0 |
---|
| 132 | endif |
---|
| 133 | endif |
---|
| 134 | |
---|
| 135 | end subroutine stop_timer |
---|
| 136 | |
---|
| 137 | subroutine allgather_timer |
---|
[1864] | 138 | USE parallel_lmdz |
---|
[630] | 139 | implicit none |
---|
[1000] | 140 | #ifdef CPP_MPI |
---|
[630] | 141 | include 'mpif.h' |
---|
[1000] | 142 | #endif |
---|
[630] | 143 | integer :: ierr |
---|
| 144 | integer :: data_size |
---|
| 145 | real, allocatable,dimension(:,:) :: tmp_table |
---|
[1000] | 146 | |
---|
| 147 | IF (using_mpi) THEN |
---|
| 148 | |
---|
| 149 | if (AllTimer_IsActive) then |
---|
[630] | 150 | |
---|
| 151 | |
---|
[1000] | 152 | allocate(tmp_table(max_size,nb_timer)) |
---|
[630] | 153 | |
---|
[1000] | 154 | data_size=max_size*nb_timer |
---|
[630] | 155 | |
---|
[1000] | 156 | tmp_table(:,:)=timer_table(:,:,mpi_rank) |
---|
| 157 | #ifdef CPP_MPI |
---|
| 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) |
---|
| 159 | #endif |
---|
| 160 | tmp_table(:,:)=timer_table_sqr(:,:,mpi_rank) |
---|
| 161 | #ifdef CPP_MPI |
---|
| 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) |
---|
| 163 | #endif |
---|
| 164 | deallocate(tmp_table) |
---|
[630] | 165 | |
---|
[1000] | 166 | endif |
---|
| 167 | |
---|
| 168 | ENDIF ! using_mpi |
---|
[630] | 169 | |
---|
| 170 | end subroutine allgather_timer |
---|
| 171 | |
---|
| 172 | subroutine allgather_timer_average |
---|
[1864] | 173 | USE parallel_lmdz |
---|
[630] | 174 | implicit none |
---|
[1000] | 175 | #ifdef CPP_MPI |
---|
[630] | 176 | include 'mpif.h' |
---|
[1000] | 177 | #endif |
---|
[630] | 178 | integer :: ierr |
---|
| 179 | integer :: data_size |
---|
| 180 | real, allocatable,dimension(:,:),target :: tmp_table |
---|
| 181 | integer, allocatable,dimension(:,:),target :: tmp_iter |
---|
| 182 | integer :: istats |
---|
[1000] | 183 | |
---|
| 184 | IF (using_mpi) THEN |
---|
| 185 | |
---|
| 186 | if (AllTimer_IsActive) then |
---|
[630] | 187 | |
---|
[1000] | 188 | allocate(tmp_table(max_size,nb_timer)) |
---|
| 189 | allocate(tmp_iter(max_size,nb_timer)) |
---|
[630] | 190 | |
---|
[1000] | 191 | data_size=max_size*nb_timer |
---|
[630] | 192 | |
---|
[1000] | 193 | tmp_table(:,:)=timer_average(:,:,mpi_rank) |
---|
| 194 | #ifdef CPP_MPI |
---|
| 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) |
---|
| 196 | #endif |
---|
| 197 | tmp_table(:,:)=timer_delta(:,:,mpi_rank) |
---|
| 198 | #ifdef CPP_MPI |
---|
| 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) |
---|
| 200 | #endif |
---|
| 201 | tmp_iter(:,:)=timer_iteration(:,:,mpi_rank) |
---|
| 202 | #ifdef CPP_MPI |
---|
| 203 | call mpi_allgather(tmp_iter(1,1),data_size,MPI_INTEGER,timer_iteration(1,1,0),data_size,MPI_INTEGER,COMM_LMDZ,ierr) |
---|
| 204 | #endif |
---|
| 205 | deallocate(tmp_table) |
---|
[630] | 206 | |
---|
[1000] | 207 | endif |
---|
| 208 | |
---|
[1146] | 209 | ENDIF ! using_mp� |
---|
[630] | 210 | end subroutine allgather_timer_average |
---|
| 211 | |
---|
| 212 | subroutine InitTime |
---|
| 213 | implicit none |
---|
| 214 | integer :: count,count_rate,count_max |
---|
| 215 | |
---|
[774] | 216 | AllTimer_IsActive=.TRUE. |
---|
[630] | 217 | if (AllTimer_IsActive) then |
---|
[774] | 218 | call system_clock(count,count_rate,count_max) |
---|
| 219 | call cpu_time(Last_cpuCount) |
---|
| 220 | Last_Count=count |
---|
[630] | 221 | endif |
---|
| 222 | end subroutine InitTime |
---|
| 223 | |
---|
[1146] | 224 | function DiffTime() |
---|
[630] | 225 | implicit none |
---|
| 226 | double precision :: DiffTime |
---|
| 227 | integer :: count,count_rate,count_max |
---|
| 228 | |
---|
| 229 | call system_clock(count,count_rate,count_max) |
---|
| 230 | if (Count>=Last_Count) then |
---|
| 231 | DiffTime=(1.*(Count-last_Count))/count_rate |
---|
| 232 | else |
---|
| 233 | DiffTime=(1.*(Count-last_Count+Count_max))/count_rate |
---|
| 234 | endif |
---|
| 235 | Last_Count=Count |
---|
| 236 | end function DiffTime |
---|
| 237 | |
---|
[1146] | 238 | function DiffCpuTime() |
---|
[630] | 239 | implicit none |
---|
| 240 | real :: DiffCpuTime |
---|
| 241 | real :: Count |
---|
| 242 | |
---|
| 243 | call cpu_time(Count) |
---|
| 244 | DiffCpuTime=Count-Last_cpuCount |
---|
| 245 | Last_cpuCount=Count |
---|
| 246 | end function DiffCpuTime |
---|
| 247 | |
---|
| 248 | end module times |
---|