[1850] | 1 | !> @file cpulog_mod.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 4 | ! |
---|
[2000] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
| 6 | ! terms of the GNU General Public License as published by the Free Software |
---|
| 7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
| 8 | ! version. |
---|
[1036] | 9 | ! |
---|
| 10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | ! |
---|
| 14 | ! You should have received a copy of the GNU General Public License along with |
---|
| 15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | ! |
---|
[4360] | 17 | ! Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[254] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[1403] | 22 | ! |
---|
[3049] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: cpulog_mod.f90 4378 2020-01-16 13:22:48Z suehring $ |
---|
[4378] | 27 | ! Format of rms output changed to allow values >= 100 |
---|
| 28 | ! |
---|
| 29 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
[4182] | 30 | ! Corrected "Former revisions" section |
---|
| 31 | ! |
---|
| 32 | ! 4015 2019-06-05 13:25:35Z raasch |
---|
[4015] | 33 | ! all reals changed to double precision in order to work with 32-bit working precision, |
---|
| 34 | ! otherwise calculated time intervals would mostly give zero |
---|
| 35 | ! |
---|
| 36 | ! 3885 2019-04-11 11:29:34Z kanani |
---|
[3885] | 37 | ! Changes related to global restructuring of location messages and introduction |
---|
| 38 | ! of additional debug messages |
---|
| 39 | ! |
---|
| 40 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3483] | 41 | ! output format limited to a maximum line length of 80 |
---|
[2716] | 42 | ! |
---|
[4182] | 43 | ! Revision 1.1 1997/07/24 11:12:29 raasch |
---|
| 44 | ! Initial revision |
---|
| 45 | ! |
---|
| 46 | ! |
---|
[1] | 47 | ! Description: |
---|
| 48 | ! ------------ |
---|
[1682] | 49 | !> CPU-time measurements for any program part whatever. Results of the |
---|
| 50 | !> measurements are output at the end of the run in local file CPU_MEASURES. |
---|
| 51 | !> |
---|
| 52 | !> To measure the CPU-time (better to say the wallclock time) of a specific code |
---|
| 53 | !> segment, two calls of cpu_log have to be used as brackets in front and at the |
---|
| 54 | !> end of the segment: |
---|
| 55 | !> |
---|
| 56 | !> CALL cpu_log( log_point(n), 'any identifier', 'start' ) |
---|
| 57 | !> ... code segment ... |
---|
| 58 | !> CALL cpu_log( log_point(n), 'any identifier', 'stop' ) |
---|
| 59 | !> |
---|
| 60 | !> Parts of the code segment can be excluded from the measurement by additional |
---|
| 61 | !> call of cpu_log: |
---|
| 62 | !> |
---|
| 63 | !> ... first segment to be measured |
---|
| 64 | !> CALL cpu_log( log_point(n), 'any identifier', 'pause' ) |
---|
| 65 | !> ... oart of segment to be excluded from measurement |
---|
| 66 | !> CALL cpu_log( log_point(n), 'any identifier', 'continue' ) |
---|
| 67 | !> ... second segment to be mesasured |
---|
| 68 | !> |
---|
| 69 | !> n is an INTEGER within the interval [1,100] defining the id of the specific |
---|
| 70 | !> code segment, 'any identifier' is a string describing the code segment to be |
---|
| 71 | !> measured. It can be freely chosen and results will appear under this name in |
---|
| 72 | !> file CPU_MEASURES. ids can only be used once. If you like to do a |
---|
| 73 | !> measurement of a new part of the code, please look for an id which is unused |
---|
| 74 | !> ao far. |
---|
| 75 | !> |
---|
[2932] | 76 | !> runtime_parameters-parameter cpu_log_barrierwait can be used to set an MPI |
---|
| 77 | !> barrier at the beginning of the measurement (modus 'start' or 'continue'), |
---|
| 78 | !> to avoid that idle times (due to MPI calls in the code segment, which are |
---|
[1682] | 79 | !> waiting for other processes to be finished) affect the measurements. |
---|
| 80 | !> If barriers shall not be used at all, a fourth, optional parameter has to be |
---|
| 81 | !> given: |
---|
| 82 | !> |
---|
| 83 | !> CALL cpu_log( ..., ..., 'start', cpu_log_nowait ) |
---|
| 84 | !> |
---|
| 85 | !> Variable log_point should be used for non-overlapping code segments, and they |
---|
| 86 | !> should sum up to the total cpu-time required by the complete run. |
---|
| 87 | !> Variable log_point_s can be used for any other special (s) measurements. |
---|
[3] | 88 | !------------------------------------------------------------------------------! |
---|
[1682] | 89 | MODULE cpulog |
---|
| 90 | |
---|
[1] | 91 | |
---|
[4015] | 92 | USE control_parameters, & |
---|
| 93 | ONLY: message_string, nr_timesteps_this_run, run_description_header, synchronous_exchange |
---|
[1320] | 94 | |
---|
[4015] | 95 | USE indices, & |
---|
[2266] | 96 | ONLY: ngp_3d, nx, ny, nz |
---|
[1320] | 97 | |
---|
| 98 | USE kinds |
---|
| 99 | |
---|
[1] | 100 | USE pegrid |
---|
| 101 | |
---|
| 102 | IMPLICIT NONE |
---|
| 103 | |
---|
[1318] | 104 | PRIVATE |
---|
[4015] | 105 | PUBLIC cpu_log, cpu_log_barrierwait, cpu_log_nowait, cpu_statistics, initial_wallclock_time, & |
---|
| 106 | log_point, log_point_s |
---|
[1] | 107 | |
---|
[1318] | 108 | INTERFACE cpu_log |
---|
| 109 | MODULE PROCEDURE cpu_log |
---|
| 110 | END INTERFACE cpu_log |
---|
| 111 | |
---|
| 112 | INTERFACE cpu_statistics |
---|
| 113 | MODULE PROCEDURE cpu_statistics |
---|
| 114 | END INTERFACE cpu_statistics |
---|
| 115 | |
---|
[1682] | 116 | INTEGER(iwp), PARAMETER :: cpu_log_continue = 0 !< |
---|
| 117 | INTEGER(iwp), PARAMETER :: cpu_log_pause = 1 !< |
---|
| 118 | INTEGER(iwp), PARAMETER :: cpu_log_start = 2 !< |
---|
| 119 | INTEGER(iwp), PARAMETER :: cpu_log_stop = 3 !< |
---|
[1318] | 120 | |
---|
[1682] | 121 | LOGICAL :: cpu_log_barrierwait = .FALSE. !< |
---|
| 122 | LOGICAL, PARAMETER :: cpu_log_nowait = .FALSE. !< |
---|
[1318] | 123 | |
---|
[4015] | 124 | REAL(dp) :: initial_wallclock_time !< |
---|
[1318] | 125 | |
---|
| 126 | TYPE logpoint |
---|
[4015] | 127 | REAL(dp) :: isum !< |
---|
| 128 | REAL(dp) :: ivect !< |
---|
| 129 | REAL(dp) :: mean !< |
---|
| 130 | REAL(dp) :: mtime !< |
---|
| 131 | REAL(dp) :: mtimevec !< |
---|
| 132 | REAL(dp) :: sum !< |
---|
| 133 | REAL(dp) :: vector !< |
---|
[1682] | 134 | INTEGER(iwp) :: counts !< |
---|
[1931] | 135 | CHARACTER (LEN=25) :: place !< |
---|
[1318] | 136 | END TYPE logpoint |
---|
| 137 | |
---|
[4015] | 138 | TYPE(logpoint), DIMENSION(100) :: log_point = logpoint( 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, & |
---|
| 139 | 0.0_dp, 0.0_dp, 0.0_dp, 0, ' ' ) |
---|
| 140 | TYPE(logpoint), DIMENSION(100) :: log_point_s = logpoint( 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, & |
---|
| 141 | 0.0_dp, 0.0_dp, 0.0_dp, 0, ' ' ) |
---|
[1318] | 142 | |
---|
| 143 | SAVE |
---|
| 144 | |
---|
| 145 | CONTAINS |
---|
| 146 | |
---|
[1682] | 147 | !------------------------------------------------------------------------------! |
---|
| 148 | ! Description: |
---|
| 149 | ! ------------ |
---|
| 150 | !> @todo Missing subroutine description. |
---|
| 151 | !------------------------------------------------------------------------------! |
---|
[1318] | 152 | SUBROUTINE cpu_log( log_event, place, modus, barrierwait ) |
---|
| 153 | |
---|
| 154 | IMPLICIT NONE |
---|
| 155 | |
---|
[1682] | 156 | CHARACTER (LEN=*) :: modus !< |
---|
| 157 | CHARACTER (LEN=*) :: place !< |
---|
[1320] | 158 | |
---|
[1682] | 159 | LOGICAL :: wait_allowed !< |
---|
| 160 | LOGICAL, OPTIONAL :: barrierwait !< |
---|
| 161 | LOGICAL, SAVE :: first = .TRUE. !< |
---|
[1320] | 162 | |
---|
[4015] | 163 | REAL(dp) :: mtime = 0.0_dp !< |
---|
| 164 | REAL(dp) :: mtimevec = 0.0_dp !< |
---|
[1682] | 165 | TYPE(logpoint) :: log_event !< |
---|
[1318] | 166 | |
---|
[1682] | 167 | INTEGER(idp) :: count !< |
---|
| 168 | INTEGER(idp) :: count_rate !< |
---|
[1] | 169 | |
---|
| 170 | |
---|
| 171 | ! |
---|
[1318] | 172 | !-- Initialize and check, respectively, point of measurement |
---|
| 173 | IF ( log_event%place == ' ' ) THEN |
---|
| 174 | log_event%place = place |
---|
| 175 | ELSEIF ( log_event%place /= place ) THEN |
---|
[4015] | 176 | WRITE( message_string, * ) 'wrong argument expected: ', & |
---|
| 177 | TRIM(log_event%place), ' given: ', TRIM( place ) |
---|
[1318] | 178 | CALL message( 'cpu_log', 'PA0174', 1, 2, 0, 6, 0 ) |
---|
| 179 | ENDIF |
---|
[1] | 180 | |
---|
| 181 | ! |
---|
[1318] | 182 | !-- Determine, if barriers are allowed to set |
---|
| 183 | IF ( PRESENT( barrierwait ) ) THEN |
---|
| 184 | wait_allowed = barrierwait |
---|
| 185 | ELSE |
---|
| 186 | wait_allowed = .TRUE. |
---|
| 187 | ENDIF |
---|
| 188 | |
---|
| 189 | ! |
---|
| 190 | !-- MPI barrier, if requested, in order to avoid measuring wait times |
---|
| 191 | !-- caused by MPI routines waiting for other MPI routines of other |
---|
| 192 | !-- PEs that have not yet finished |
---|
| 193 | #if defined( __parallel ) |
---|
[4015] | 194 | IF ( cpu_log_barrierwait .AND. wait_allowed .AND. & |
---|
[1318] | 195 | ( modus == 'start' .OR. modus == 'continue' ) ) THEN |
---|
| 196 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 197 | ENDIF |
---|
| 198 | #endif |
---|
| 199 | |
---|
| 200 | ! |
---|
| 201 | !-- Take current time |
---|
| 202 | CALL SYSTEM_CLOCK( count, count_rate ) |
---|
[4015] | 203 | mtime = REAL( count, KIND=dp ) / REAL( count_rate, KIND=dp ) |
---|
[1] | 204 | |
---|
| 205 | ! |
---|
[1318] | 206 | !-- Start, stop or pause measurement |
---|
| 207 | IF ( modus == 'start' .OR. modus == 'continue' ) THEN |
---|
| 208 | log_event%mtime = mtime |
---|
| 209 | log_event%mtimevec = mtimevec |
---|
| 210 | ELSEIF ( modus == 'pause' ) THEN |
---|
| 211 | IF ( ( mtime - log_event%mtime ) < 0.0 .AND. first ) THEN |
---|
[4015] | 212 | WRITE( message_string, * ) 'negative time interval occured', & |
---|
| 213 | '&PE',myid,' L=PAUSE "',TRIM(log_event%place), & |
---|
| 214 | '" new=', mtime,' last=',log_event%mtime |
---|
[1318] | 215 | CALL message( 'cpu_log', 'PA0176', 0, 1, -1, 6, 0 ) |
---|
| 216 | first = .FALSE. |
---|
| 217 | ENDIF |
---|
| 218 | log_event%isum = log_event%isum + mtime - log_event%mtime |
---|
| 219 | log_event%ivect = log_event%ivect + mtimevec - log_event%mtimevec |
---|
| 220 | ELSEIF ( modus == 'stop' ) THEN |
---|
[4015] | 221 | IF ( ( mtime - log_event%mtime + log_event%isum ) < 0.0 .AND. first ) THEN |
---|
| 222 | WRITE( message_string, * ) 'negative time interval occured', & |
---|
| 223 | '&PE',myid,' L=STOP "',TRIM(log_event%place),'" new=', & |
---|
| 224 | mtime,' last=',log_event%mtime,' isum=',log_event%isum |
---|
[1318] | 225 | CALL message( 'cpu_log', 'PA0177', 0, 1, -1, 6, 0 ) |
---|
| 226 | first = .FALSE. |
---|
| 227 | ENDIF |
---|
| 228 | log_event%mtime = mtime - log_event%mtime + log_event%isum |
---|
| 229 | log_event%mtimevec = mtimevec - log_event%mtimevec + log_event%ivect |
---|
| 230 | log_event%sum = log_event%sum + log_event%mtime |
---|
| 231 | IF ( log_event%sum < 0.0 .AND. first ) THEN |
---|
[4015] | 232 | WRITE( message_string, * ) 'negative time interval occured', & |
---|
| 233 | '&PE',myid,' L=STOP "',TRIM(log_event%place),'" sum=', & |
---|
| 234 | log_event%sum,' mtime=',log_event%mtime |
---|
[1318] | 235 | CALL message( 'cpu_log', 'PA0178', 0, 1, -1, 6, 0 ) |
---|
| 236 | first = .FALSE. |
---|
| 237 | ENDIF |
---|
| 238 | log_event%vector = log_event%vector + log_event%mtimevec |
---|
| 239 | log_event%counts = log_event%counts + 1 |
---|
[4015] | 240 | log_event%isum = 0.0_dp |
---|
| 241 | log_event%ivect = 0.0_dp |
---|
[1318] | 242 | ELSE |
---|
[4015] | 243 | message_string = 'unknown modus of time measurement: ' // TRIM( modus ) |
---|
[1318] | 244 | CALL message( 'cpu_log', 'PA0179', 0, 1, -1, 6, 0 ) |
---|
[1] | 245 | ENDIF |
---|
[1318] | 246 | |
---|
| 247 | END SUBROUTINE cpu_log |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | !------------------------------------------------------------------------------! |
---|
| 251 | ! Description: |
---|
| 252 | ! ------------ |
---|
[1682] | 253 | !> Analysis and output of the cpu-times measured. All PE results are collected |
---|
| 254 | !> on PE0 in order to calculate the mean cpu-time over all PEs and other |
---|
| 255 | !> statistics. The output is sorted according to the amount of cpu-time consumed |
---|
| 256 | !> and output on PE0. |
---|
[1318] | 257 | !------------------------------------------------------------------------------! |
---|
[1682] | 258 | |
---|
| 259 | SUBROUTINE cpu_statistics |
---|
[1318] | 260 | |
---|
| 261 | IMPLICIT NONE |
---|
| 262 | |
---|
[1682] | 263 | INTEGER(iwp) :: i !< |
---|
| 264 | INTEGER(iwp) :: ii(1) !< |
---|
| 265 | INTEGER(iwp) :: iii !< |
---|
| 266 | INTEGER(iwp) :: sender !< |
---|
[4015] | 267 | REAL(dp) :: average_cputime !< |
---|
| 268 | REAL(dp), SAVE :: norm = 1.0_dp !< |
---|
| 269 | REAL(dp), DIMENSION(:), ALLOCATABLE :: pe_max !< |
---|
| 270 | REAL(dp), DIMENSION(:), ALLOCATABLE :: pe_min !< |
---|
| 271 | REAL(dp), DIMENSION(:), ALLOCATABLE :: pe_rms !< |
---|
| 272 | REAL(dp), DIMENSION(:), ALLOCATABLE :: pe_tmp !< |
---|
| 273 | REAL(dp), DIMENSION(:), ALLOCATABLE :: sum !< |
---|
| 274 | REAL(dp), DIMENSION(:,:), ALLOCATABLE :: pe_log_points !< |
---|
[1318] | 275 | |
---|
| 276 | |
---|
[3885] | 277 | CALL location_message( 'calculating cpu statistics', 'start' ) |
---|
[1402] | 278 | |
---|
[1318] | 279 | ! |
---|
| 280 | !-- Compute cpu-times in seconds |
---|
| 281 | log_point%mtime = log_point%mtime / norm |
---|
| 282 | log_point%sum = log_point%sum / norm |
---|
| 283 | log_point%vector = log_point%vector / norm |
---|
| 284 | WHERE ( log_point%counts /= 0 ) |
---|
| 285 | log_point%mean = log_point%sum / log_point%counts |
---|
| 286 | END WHERE |
---|
| 287 | |
---|
| 288 | |
---|
| 289 | ! |
---|
| 290 | !-- Collect cpu-times from all PEs and calculate statistics |
---|
| 291 | IF ( myid == 0 ) THEN |
---|
| 292 | ! |
---|
| 293 | !-- Allocate and initialize temporary arrays needed for statistics |
---|
[4015] | 294 | ALLOCATE( pe_max( SIZE( log_point ) ), pe_min( SIZE( log_point ) ), & |
---|
| 295 | pe_rms( SIZE( log_point ) ), pe_tmp( SIZE( log_point ) ), & |
---|
[1318] | 296 | pe_log_points( SIZE( log_point ), 0:numprocs-1 ) ) |
---|
| 297 | pe_min = log_point%sum |
---|
| 298 | pe_max = log_point%sum ! need to be set in case of 1 PE |
---|
[4015] | 299 | pe_rms = 0.0_dp |
---|
| 300 | pe_tmp = 0.0_dp |
---|
[1318] | 301 | |
---|
| 302 | #if defined( __parallel ) |
---|
| 303 | ! |
---|
| 304 | !-- Receive data from all PEs |
---|
| 305 | DO i = 1, numprocs-1 |
---|
[4015] | 306 | CALL MPI_RECV( pe_tmp(1), SIZE( log_point ), MPI_DOUBLE_PRECISION, i, i, comm2d, & |
---|
| 307 | status, ierr ) |
---|
[1318] | 308 | sender = status(MPI_SOURCE) |
---|
[3229] | 309 | pe_log_points(:,sender) = pe_tmp |
---|
[1318] | 310 | ENDDO |
---|
| 311 | pe_log_points(:,0) = log_point%sum ! Results from PE0 |
---|
| 312 | ! |
---|
| 313 | !-- Calculate mean of all PEs, store it on log_point%sum |
---|
| 314 | !-- and find minimum and maximum |
---|
| 315 | DO iii = 1, SIZE( log_point ) |
---|
| 316 | DO i = 1, numprocs-1 |
---|
| 317 | log_point(iii)%sum = log_point(iii)%sum + pe_log_points(iii,i) |
---|
| 318 | pe_min(iii) = MIN( pe_min(iii), pe_log_points(iii,i) ) |
---|
| 319 | pe_max(iii) = MAX( pe_max(iii), pe_log_points(iii,i) ) |
---|
| 320 | ENDDO |
---|
| 321 | log_point(iii)%sum = log_point(iii)%sum / numprocs |
---|
| 322 | ! |
---|
| 323 | !-- Calculate rms |
---|
| 324 | DO i = 0, numprocs-1 |
---|
[4015] | 325 | pe_rms(iii) = pe_rms(iii) + ( pe_log_points(iii,i) - log_point(iii)%sum )**2 |
---|
[1318] | 326 | ENDDO |
---|
| 327 | pe_rms(iii) = SQRT( pe_rms(iii) / numprocs ) |
---|
| 328 | ENDDO |
---|
| 329 | ELSE |
---|
| 330 | ! |
---|
| 331 | !-- Send data to PE0 (pe_max is used as temporary storage to send |
---|
| 332 | !-- the data in order to avoid sending the data type log) |
---|
| 333 | ALLOCATE( pe_max( SIZE( log_point ) ) ) |
---|
| 334 | pe_max = log_point%sum |
---|
[4015] | 335 | CALL MPI_SEND( pe_max(1), SIZE( log_point ), MPI_DOUBLE_PRECISION, 0, myid, comm2d, ierr ) |
---|
[1318] | 336 | #endif |
---|
| 337 | |
---|
[1] | 338 | ENDIF |
---|
[1318] | 339 | |
---|
| 340 | ! |
---|
| 341 | !-- Write cpu-times |
---|
| 342 | IF ( myid == 0 ) THEN |
---|
| 343 | ! |
---|
| 344 | !-- Re-store sums |
---|
| 345 | ALLOCATE( sum( SIZE( log_point ) ) ) |
---|
| 346 | WHERE ( log_point%counts /= 0 ) |
---|
| 347 | sum = log_point%sum |
---|
| 348 | ELSEWHERE |
---|
[4015] | 349 | sum = -1.0_dp |
---|
[1318] | 350 | ENDWHERE |
---|
| 351 | |
---|
| 352 | ! |
---|
[2266] | 353 | !-- Get total time in order to calculate CPU-time per gridpoint and |
---|
| 354 | !-- timestep |
---|
[1318] | 355 | IF ( nr_timesteps_this_run /= 0 ) THEN |
---|
[4015] | 356 | average_cputime = log_point(1)%sum / REAL( ngp_3d(0), KIND=dp ) / & |
---|
| 357 | REAL( nr_timesteps_this_run, KIND=dp ) * 1E6_dp ! in micro-sec |
---|
[1318] | 358 | ELSE |
---|
[4015] | 359 | average_cputime = -1.0_dp |
---|
[1318] | 360 | ENDIF |
---|
| 361 | |
---|
| 362 | ! |
---|
| 363 | !-- Write cpu-times sorted by size |
---|
| 364 | CALL check_open( 18 ) |
---|
| 365 | #if defined( __parallel ) |
---|
[4015] | 366 | WRITE ( 18, 100 ) TRIM( run_description_header ), numprocs * threads_per_task, & |
---|
| 367 | pdims(1), pdims(2), threads_per_task, nx+1, ny+1, nz, & |
---|
[2266] | 368 | nr_timesteps_this_run, average_cputime |
---|
[1318] | 369 | |
---|
| 370 | WRITE ( 18, 110 ) |
---|
| 371 | #else |
---|
[4015] | 372 | WRITE ( 18, 100 ) TRIM( run_description_header ), numprocs * threads_per_task, 1, 1, & |
---|
| 373 | threads_per_task, nx+1, ny+1, nz, nr_timesteps_this_run, & |
---|
| 374 | average_cputime |
---|
[1318] | 375 | |
---|
| 376 | WRITE ( 18, 110 ) |
---|
| 377 | #endif |
---|
| 378 | DO |
---|
| 379 | ii = MAXLOC( sum ) |
---|
| 380 | i = ii(1) |
---|
[4015] | 381 | IF ( sum(i) /= -1.0_dp ) THEN |
---|
| 382 | WRITE ( 18, 102 ) log_point(i)%place, log_point(i)%sum, & |
---|
| 383 | log_point(i)%sum / log_point(1)%sum * 100.0_dp, & |
---|
| 384 | log_point(i)%counts, pe_min(i), pe_max(i), pe_rms(i) |
---|
| 385 | sum(i) = -1.0_dp |
---|
[1318] | 386 | ELSE |
---|
| 387 | EXIT |
---|
| 388 | ENDIF |
---|
| 389 | ENDDO |
---|
[1] | 390 | ENDIF |
---|
| 391 | |
---|
| 392 | |
---|
[1318] | 393 | ! |
---|
| 394 | !-- The same procedure again for the individual measurements. |
---|
| 395 | ! |
---|
| 396 | !-- Compute cpu-times in seconds |
---|
| 397 | log_point_s%mtime = log_point_s%mtime / norm |
---|
| 398 | log_point_s%sum = log_point_s%sum / norm |
---|
| 399 | log_point_s%vector = log_point_s%vector / norm |
---|
| 400 | WHERE ( log_point_s%counts /= 0 ) |
---|
| 401 | log_point_s%mean = log_point_s%sum / log_point_s%counts |
---|
| 402 | END WHERE |
---|
| 403 | |
---|
| 404 | ! |
---|
| 405 | !-- Collect cpu-times from all PEs and calculate statistics |
---|
| 406 | #if defined( __parallel ) |
---|
| 407 | ! |
---|
| 408 | !-- Set barrier in order to avoid that PE0 receives log_point_s-data |
---|
| 409 | !-- while still busy with receiving log_point-data (see above) |
---|
| 410 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 411 | #endif |
---|
| 412 | IF ( myid == 0 ) THEN |
---|
| 413 | ! |
---|
| 414 | !-- Initialize temporary arrays needed for statistics |
---|
| 415 | pe_min = log_point_s%sum |
---|
| 416 | pe_max = log_point_s%sum ! need to be set in case of 1 PE |
---|
[4015] | 417 | pe_rms = 0.0_dp |
---|
[1318] | 418 | |
---|
| 419 | #if defined( __parallel ) |
---|
| 420 | ! |
---|
| 421 | !-- Receive data from all PEs |
---|
| 422 | DO i = 1, numprocs-1 |
---|
[4015] | 423 | CALL MPI_RECV( pe_tmp(1), SIZE( log_point ), MPI_DOUBLE_PRECISION, MPI_ANY_SOURCE, & |
---|
| 424 | MPI_ANY_TAG, comm2d, status, ierr ) |
---|
[1318] | 425 | sender = status(MPI_SOURCE) |
---|
[3229] | 426 | pe_log_points(:,sender) = pe_tmp |
---|
[1318] | 427 | ENDDO |
---|
| 428 | pe_log_points(:,0) = log_point_s%sum ! Results from PE0 |
---|
| 429 | ! |
---|
| 430 | !-- Calculate mean of all PEs, store it on log_point_s%sum |
---|
| 431 | !-- and find minimum and maximum |
---|
| 432 | DO iii = 1, SIZE( log_point ) |
---|
| 433 | DO i = 1, numprocs-1 |
---|
[4015] | 434 | log_point_s(iii)%sum = log_point_s(iii)%sum + pe_log_points(iii,i) |
---|
[1318] | 435 | pe_min(iii) = MIN( pe_min(iii), pe_log_points(iii,i) ) |
---|
| 436 | pe_max(iii) = MAX( pe_max(iii), pe_log_points(iii,i) ) |
---|
| 437 | ENDDO |
---|
| 438 | log_point_s(iii)%sum = log_point_s(iii)%sum / numprocs |
---|
| 439 | ! |
---|
| 440 | !-- Calculate rms |
---|
| 441 | DO i = 0, numprocs-1 |
---|
[4015] | 442 | pe_rms(iii) = pe_rms(iii) + ( pe_log_points(iii,i) - log_point_s(iii)%sum )**2 |
---|
[1318] | 443 | ENDDO |
---|
| 444 | pe_rms(iii) = SQRT( pe_rms(iii) / numprocs ) |
---|
| 445 | ENDDO |
---|
| 446 | ELSE |
---|
| 447 | ! |
---|
| 448 | !-- Send data to PE0 (pe_max is used as temporary storage to send |
---|
| 449 | !-- the data in order to avoid sending the data type log) |
---|
| 450 | pe_max = log_point_s%sum |
---|
[4015] | 451 | CALL MPI_SEND( pe_max(1), SIZE( log_point ), MPI_DOUBLE_PRECISION, 0, 0, comm2d, ierr ) |
---|
[1318] | 452 | #endif |
---|
| 453 | |
---|
| 454 | ENDIF |
---|
| 455 | |
---|
| 456 | ! |
---|
| 457 | !-- Write cpu-times |
---|
| 458 | IF ( myid == 0 ) THEN |
---|
| 459 | ! |
---|
| 460 | !-- Re-store sums |
---|
| 461 | WHERE ( log_point_s%counts /= 0 ) |
---|
| 462 | sum = log_point_s%sum |
---|
| 463 | ELSEWHERE |
---|
[4015] | 464 | sum = -1.0_dp |
---|
[1318] | 465 | ENDWHERE |
---|
| 466 | |
---|
| 467 | ! |
---|
| 468 | !-- Write cpu-times sorted by size |
---|
| 469 | WRITE ( 18, 101 ) |
---|
| 470 | DO |
---|
| 471 | ii = MAXLOC( sum ) |
---|
| 472 | i = ii(1) |
---|
[4015] | 473 | IF ( sum(i) /= -1.0_dp ) THEN |
---|
| 474 | WRITE ( 18, 102 ) log_point_s(i)%place, log_point_s(i)%sum, & |
---|
| 475 | log_point_s(i)%sum / log_point(1)%sum * 100.0_dp, & |
---|
| 476 | log_point_s(i)%counts, pe_min(i), pe_max(i), pe_rms(i) |
---|
| 477 | sum(i) = -1.0_dp |
---|
[1318] | 478 | ELSE |
---|
| 479 | EXIT |
---|
| 480 | ENDIF |
---|
| 481 | ENDDO |
---|
| 482 | |
---|
| 483 | ! |
---|
| 484 | !-- Output of handling of MPI operations |
---|
| 485 | IF ( collective_wait ) THEN |
---|
| 486 | WRITE ( 18, 103 ) |
---|
| 487 | ELSE |
---|
| 488 | WRITE ( 18, 104 ) |
---|
| 489 | ENDIF |
---|
| 490 | IF ( cpu_log_barrierwait ) WRITE ( 18, 111 ) |
---|
| 491 | IF ( synchronous_exchange ) THEN |
---|
| 492 | WRITE ( 18, 105 ) |
---|
| 493 | ELSE |
---|
| 494 | WRITE ( 18, 106 ) |
---|
| 495 | ENDIF |
---|
| 496 | |
---|
| 497 | ! |
---|
| 498 | !-- Empty lines in order to create a gap to the results of the model |
---|
| 499 | !-- continuation runs |
---|
| 500 | WRITE ( 18, 107 ) |
---|
| 501 | |
---|
| 502 | ! |
---|
| 503 | !-- Unit 18 is not needed anymore |
---|
| 504 | CALL close_file( 18 ) |
---|
| 505 | |
---|
| 506 | ENDIF |
---|
| 507 | |
---|
[3885] | 508 | CALL location_message( 'calculating cpu statistics', 'finished' ) |
---|
[1318] | 509 | |
---|
[3885] | 510 | |
---|
[4015] | 511 | 100 FORMAT (A/11('-')//'CPU measures for ',I5,' PEs (',I5,'(x) * ',I5,'(y', & |
---|
| 512 | &') tasks *',I5,' threads):'// & |
---|
| 513 | 'gridpoints (x/y/z): ',20X,I5,' * ',I5,' * ',I5/ & |
---|
| 514 | 'nr of timesteps: ',22X,I6/ & |
---|
[1318] | 515 | 'cpu time per grid point and timestep: ',5X,F8.5,' * 10**-6 s') |
---|
| 516 | |
---|
| 517 | 101 FORMAT (/'special measures:'/ & |
---|
[4015] | 518 | &'-----------------------------------------------------------', & |
---|
[3483] | 519 | &'---------------------') |
---|
[1318] | 520 | |
---|
[4378] | 521 | 102 FORMAT (A25,2X,F9.3,2X,F7.2,1X,I7,2(1X,F9.3),1X,F6.2) |
---|
[1318] | 522 | 103 FORMAT (/'Barriers are set in front of collective operations') |
---|
| 523 | 104 FORMAT (/'No barriers are set in front of collective operations') |
---|
| 524 | 105 FORMAT (/'Exchange of ghostpoints via MPI_SENDRCV') |
---|
| 525 | 106 FORMAT (/'Exchange of ghostpoints via MPI_ISEND/MPI_IRECV') |
---|
| 526 | 107 FORMAT (//) |
---|
[4015] | 527 | 110 FORMAT ('------------------------------------------------------------', & |
---|
| 528 | &'----------'// & |
---|
| 529 | &'place: mean counts ', & |
---|
| 530 | &' min max rms'/ & |
---|
| 531 | &' sec. % ', & |
---|
| 532 | &'sec. sec. sec.'/ & |
---|
| 533 | &'-----------------------------------------------------------', & |
---|
[3483] | 534 | &'---------------------') |
---|
[1318] | 535 | 111 FORMAT (/'Barriers are set at beginning (start/continue) of measurements') |
---|
| 536 | |
---|
| 537 | END SUBROUTINE cpu_statistics |
---|
| 538 | |
---|
| 539 | END MODULE cpulog |
---|