SUBROUTINE cpu_log( log_event, place, modus, barrierwait ) !--------------------------------------------------------------------------------! ! This file is part of PALM. ! ! PALM is free software: you can redistribute it and/or modify it under the terms ! of the GNU General Public License as published by the Free Software Foundation, ! either version 3 of the License, or (at your option) any later version. ! ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2012 Leibniz University Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: cpu_log.f90 1037 2012-10-22 14:10:22Z gryschka $ ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 274 2009-03-26 15:11:21Z heinze ! Output of messages replaced by message handling routine. ! Type of count and count_rate changed to default INTEGER on NEC machines ! ! 225 2009-01-26 14:44:20Z raasch ! Type of count and count_rate changed to INTEGER(8) ! ! 82 2007-04-16 15:40:52Z raasch ! Preprocessor strings for different linux clusters changed to "lc", ! preprocessor directives for old systems removed ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.24 2006/06/02 15:12:17 raasch ! cpp-directives extended for lctit ! ! Revision 1.1 1997/07/24 11:12:29 raasch ! Initial revision ! ! ! Description: ! ------------ ! Cpu-time measurements for any program part whatever. !------------------------------------------------------------------------------! USE control_parameters USE cpulog USE pegrid IMPLICIT NONE CHARACTER (LEN=*) :: modus, place CHARACTER (LEN=*), OPTIONAL :: barrierwait LOGICAL, SAVE :: first = .TRUE. REAL :: mtime = 0.0, mtimevec = 0.0 TYPE(logpoint) :: log_event #if defined( __lc ) || defined( __decalpha ) INTEGER(8) :: count, count_rate #elif defined( __nec ) INTEGER :: count, count_rate #elif defined( __ibm ) INTEGER(8) :: IRTC #endif ! !-- Initialize and check, respectively, point of measurement IF ( log_event%place == ' ' ) THEN log_event%place = place ELSEIF ( log_event%place /= place ) THEN WRITE( message_string, * ) 'wrong argument & expected: ', & TRIM(log_event%place), ' given: ', TRIM( place ) CALL message( 'cpu_log', 'PA0174', 1, 2, 0, 6, 0 ) ENDIF ! !-- Take current time #if defined( __lc ) || defined( __decalpha ) || defined( __nec ) CALL SYSTEM_CLOCK( count, count_rate ) mtime = REAL( count ) / REAL( count_rate ) #elif defined( __ibm ) mtime = IRTC( ) * 1E-9 #else message_string = 'no time measurement defined on this host' CALL message( 'cpu_log', 'PA0175', 1, 2, 0, 6, 0 ) #endif ! !-- Start, stop or pause measurement IF ( modus == 'start' .OR. modus == 'continue' ) THEN log_event%mtime = mtime log_event%mtimevec = mtimevec ELSEIF ( modus == 'pause' ) THEN IF ( ( mtime - log_event%mtime ) < 0.0 .AND. first ) THEN WRITE( message_string, * ) 'negative time interval occured', & ' &PE',myid,' L=PAUSE "',TRIM(log_event%place),'" new=', & mtime,' last=',log_event%mtime CALL message( 'cpu_log', 'PA0176', 0, 1, -1, 6, 0 ) first = .FALSE. ENDIF log_event%isum = log_event%isum + mtime - log_event%mtime log_event%ivect = log_event%ivect + mtimevec - log_event%mtimevec ELSEIF ( modus == 'stop' ) THEN IF ( ( mtime - log_event%mtime + log_event%isum ) < 0.0 .AND. & first ) THEN WRITE( message_string, * ) 'negative time interval occured', & ' &PE',myid,' L=STOP "',TRIM(log_event%place),'" new=', & mtime,' last=',log_event%mtime,' isum=',log_event%isum CALL message( 'cpu_log', 'PA0177', 0, 1, -1, 6, 0 ) first = .FALSE. ENDIF log_event%mtime = mtime - log_event%mtime + log_event%isum log_event%mtimevec = mtimevec - log_event%mtimevec + log_event%ivect log_event%sum = log_event%sum + log_event%mtime IF ( log_event%sum < 0.0 .AND. first ) THEN WRITE( message_string, * ) 'negative time interval occured', & ' &PE',myid,' L=STOP "',TRIM(log_event%place),'" sum=', & log_event%sum,' mtime=',log_event%mtime CALL message( 'cpu_log', 'PA0178', 0, 1, -1, 6, 0 ) first = .FALSE. ENDIF log_event%vector = log_event%vector + log_event%mtimevec log_event%counts = log_event%counts + 1 log_event%isum = 0.0 log_event%ivect = 0.0 ELSE message_string = 'unknown modus of time measurement: ' // TRIM( modus ) CALL message( 'cpu_log', 'PA0179', 0, 1, -1, 6, 0 ) ENDIF END SUBROUTINE cpu_log