[1] | 1 | SUBROUTINE cpu_log( log_event, place, modus, barrierwait ) |
---|
| 2 | |
---|
| 3 | !------------------------------------------------------------------------------! |
---|
[254] | 4 | ! Current revisions: |
---|
[1] | 5 | ! ----------------- |
---|
[254] | 6 | ! Output of messages replaced by message handling routine. |
---|
[239] | 7 | ! Type of count and count_rate changed to default INTEGER on NEC machines |
---|
[1] | 8 | ! |
---|
| 9 | ! Former revisions: |
---|
| 10 | ! ----------------- |
---|
[3] | 11 | ! $Id: cpu_log.f90 254 2009-03-05 15:33:42Z letzel $ |
---|
[83] | 12 | ! |
---|
[226] | 13 | ! 225 2009-01-26 14:44:20Z raasch |
---|
| 14 | ! Type of count and count_rate changed to INTEGER(8) |
---|
| 15 | ! |
---|
[83] | 16 | ! 82 2007-04-16 15:40:52Z raasch |
---|
| 17 | ! Preprocessor strings for different linux clusters changed to "lc", |
---|
| 18 | ! preprocessor directives for old systems removed |
---|
| 19 | ! |
---|
[3] | 20 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 21 | ! |
---|
[1] | 22 | ! Revision 1.24 2006/06/02 15:12:17 raasch |
---|
| 23 | ! cpp-directives extended for lctit |
---|
| 24 | ! |
---|
| 25 | ! Revision 1.1 1997/07/24 11:12:29 raasch |
---|
| 26 | ! Initial revision |
---|
| 27 | ! |
---|
| 28 | ! |
---|
| 29 | ! Description: |
---|
| 30 | ! ------------ |
---|
| 31 | ! Cpu-time measurements for any program part whatever. |
---|
[3] | 32 | !------------------------------------------------------------------------------! |
---|
[1] | 33 | |
---|
[254] | 34 | USE control_parameters |
---|
[1] | 35 | USE cpulog |
---|
| 36 | USE pegrid |
---|
| 37 | |
---|
| 38 | IMPLICIT NONE |
---|
| 39 | |
---|
| 40 | CHARACTER (LEN=*) :: modus, place |
---|
| 41 | CHARACTER (LEN=*), OPTIONAL :: barrierwait |
---|
| 42 | LOGICAL, SAVE :: first = .TRUE. |
---|
| 43 | REAL :: mtime = 0.0, mtimevec = 0.0 |
---|
| 44 | TYPE(logpoint) :: log_event |
---|
| 45 | |
---|
[239] | 46 | #if defined( __lc ) || defined( __decalpha ) |
---|
[225] | 47 | INTEGER(8) :: count, count_rate |
---|
[239] | 48 | #elif defined( __nec ) |
---|
| 49 | INTEGER :: count, count_rate |
---|
[1] | 50 | #elif defined( __ibm ) |
---|
| 51 | INTEGER(8) :: IRTC |
---|
| 52 | #endif |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | ! |
---|
| 56 | !-- Initialize and check, respectively, point of measurement |
---|
| 57 | IF ( log_event%place == ' ' ) THEN |
---|
| 58 | log_event%place = place |
---|
| 59 | ELSEIF ( log_event%place /= place ) THEN |
---|
[254] | 60 | WRITE( message_string, * ) 'wrong argument & expected: ', & |
---|
| 61 | TRIM(log_event%place), ' given: ', TRIM( place ) |
---|
| 62 | CALL message( 'cpu_log', 'PA0174', 1, 2, 0, 6, 0 ) |
---|
[1] | 63 | ENDIF |
---|
| 64 | |
---|
| 65 | ! |
---|
| 66 | !-- Take current time |
---|
[82] | 67 | #if defined( __lc ) || defined( __decalpha ) || defined( __nec ) |
---|
[1] | 68 | CALL SYSTEM_CLOCK( count, count_rate ) |
---|
| 69 | mtime = REAL( count ) / REAL( count_rate ) |
---|
| 70 | #elif defined( __ibm ) |
---|
| 71 | mtime = IRTC( ) * 1E-9 |
---|
| 72 | #else |
---|
[254] | 73 | message_string = 'no time measurement defined on this host' |
---|
| 74 | CALL message( 'cpu_log', 'PA0175', 1, 2, 0, 6, 0 ) |
---|
[1] | 75 | #endif |
---|
| 76 | |
---|
| 77 | ! |
---|
| 78 | !-- Start, stop or pause measurement |
---|
| 79 | IF ( modus == 'start' .OR. modus == 'continue' ) THEN |
---|
| 80 | log_event%mtime = mtime |
---|
| 81 | log_event%mtimevec = mtimevec |
---|
| 82 | ELSEIF ( modus == 'pause' ) THEN |
---|
| 83 | IF ( ( mtime - log_event%mtime ) < 0.0 .AND. first ) THEN |
---|
[254] | 84 | WRITE( message_string, * ) 'negative time interval occured', & |
---|
| 85 | ' &PE',myid,' L=PAUSE "',TRIM(log_event%place),'" new=', & |
---|
| 86 | mtime,' last=',log_event%mtime |
---|
| 87 | CALL message( 'cpu_log', 'PA0176', 0, 1, -1, 6, 0 ) |
---|
[1] | 88 | first = .FALSE. |
---|
| 89 | ENDIF |
---|
| 90 | log_event%isum = log_event%isum + mtime - log_event%mtime |
---|
| 91 | log_event%ivect = log_event%ivect + mtimevec - log_event%mtimevec |
---|
| 92 | ELSEIF ( modus == 'stop' ) THEN |
---|
| 93 | IF ( ( mtime - log_event%mtime + log_event%isum ) < 0.0 .AND. & |
---|
| 94 | first ) THEN |
---|
[254] | 95 | WRITE( message_string, * ) 'negative time interval occured', & |
---|
| 96 | ' &PE',myid,' L=STOP "',TRIM(log_event%place),'" new=', & |
---|
| 97 | mtime,' last=',log_event%mtime,' isum=',log_event%isum |
---|
| 98 | CALL message( 'cpu_log', 'PA0177', 0, 1, -1, 6, 0 ) |
---|
[1] | 99 | first = .FALSE. |
---|
| 100 | ENDIF |
---|
| 101 | log_event%mtime = mtime - log_event%mtime + log_event%isum |
---|
| 102 | log_event%mtimevec = mtimevec - log_event%mtimevec + log_event%ivect |
---|
| 103 | log_event%sum = log_event%sum + log_event%mtime |
---|
| 104 | IF ( log_event%sum < 0.0 .AND. first ) THEN |
---|
[254] | 105 | WRITE( message_string, * ) 'negative time interval occured',& |
---|
| 106 | ' &PE',myid,' L=STOP "',TRIM(log_event%place),'" sum=', & |
---|
| 107 | log_event%sum,' mtime=',log_event%mtime |
---|
| 108 | CALL message( 'cpu_log', 'PA0178', 0, 1, -1, 6, 0 ) |
---|
[1] | 109 | first = .FALSE. |
---|
| 110 | ENDIF |
---|
| 111 | log_event%vector = log_event%vector + log_event%mtimevec |
---|
| 112 | log_event%counts = log_event%counts + 1 |
---|
| 113 | log_event%isum = 0.0 |
---|
| 114 | log_event%ivect = 0.0 |
---|
| 115 | ELSE |
---|
[254] | 116 | message_string = 'unknown modus of time measurement: ' // TRIM( modus ) |
---|
| 117 | CALL message( 'cpu_log', 'PA0179', 0, 1, -1, 6, 0 ) |
---|
[1] | 118 | ENDIF |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | END SUBROUTINE cpu_log |
---|