From: theld@udecc.engr.udayton.edu (Thomas W Held (S))
Subject: For HP and IBM RISC hosts, how to get cpu times from Fortran?
Organization: Univ. of Dayton, School of Engineering
Date: Sun, 11 Oct 1992 22:51:25 GMT

Hello:

We have a code (all Fortran) that runs on several platforms.  I want to
add a routine that returns the total elapsed cpu time for the run (not 
elapsed wall-clock time).  In the routine I'll put some 
platform-specific code that gets this value somehow.  I know how to do 
this for most of the targeted platforms, but I haven't found info on how 
to do this for an HP 9000/700 or for an IBM R/S 6000.  Any suggestions?

Below are the target platforms and the library routines I plan to use.  
Feel free to suggest alternatives or post comments.  I'm not particularly
concerned with high-resolution values -- these results will be used to
report progress to a user over a several-day run.

Add your favorite machine if it's not on the list.

I'll post results in this group. 

Thanks for any suggestions...

Later, Tom

Sample code follows.  Look for routine CPUSEC:
C***********************************************************************
      PROGRAM ELTEST
C
      REAL ELTIME
C
      WRITE ( *, 6100 )
 6100 FORMAT ( 2X, 'How many times through the loop? :', $ )
      READ ( 5, * ) NTIMES
C
C     Spend some time checking up on DUMDUM.
C
C
      DO 120  J=1, NTIMES 
        CALL DUMDUM ( J )
        CALL CPUSEC ( ELTIME )
        IF ( MOD( J, 10000 ) .EQ. 0 ) THEN
          WRITE ( *, 6110 ) J, ELTIME
 6110       FORMAT ( 4X, 'Loop count now.:', I12,
     +              /4X, 'ELTIME is......:', 1PE12.4 )
        ENDIF
  120 CONTINUE
C
      CALL CPUSEC ( ELTIME )
C
      WRITE ( *, 6130 ) NTIMES, ELTIME
 6130 FORMAT (/2X, 'NTIMES was.....:', I12,
     +        /2X, 'ELTIME was.....:', 1PE12.4 )
C
      STOP
      END
C***********************************************************************
C
      SUBROUTINE DUMDUM ( JJJ )
C
C     Filler routine which may fool the optimizer...
C
      RETURN
      END
C
C***********************************************************************
C
      SUBROUTINE CPUSEC ( ELTIME )
C
C     Return elapsed cpu time, in seconds, for the process.
C     If unknown for this machine, return a negative value
C     in ELTIME.
C
C     For your machine, remove the strings as follows before
C     you compile:
C
C     1. C-H-P       H-P 9000/700 -- HPUX 8.xxx?
C     2. C-IBM       IBM R/S 6000 -- AIX 3.2 ?
C
C     3. C-VAX       VAX/VMS      -- VMS 5.x
C     4. C-SUN       Sun SS2, 4   -- SunOS 4.1.x, f77 1.4.x
C
C     5. C-SGI       Silicon Graphics -- IRIX 4.0.x
C     6. C-RSC       DEC / MIPS   -- RISC ULTRIX 4?, DEC Fortran xx
C
C     7. C-CVX       Convex 210?  -- OS 10.?, fc 7.0.x ?
C     8. C-HAR       Harris HCX ? -- CX/UX 5.x?
C
C     9. C-CRY       Cray X-MP/Y-MP -- UNICOS 6.x, cf77 5?
C
C
C
           REAL ELTIME
           REAL TARRAY( 2 )
C
C-VAX      INTEGER*4 CPU_TIME    
C-VAX      INTEGER*4 ITEM_LIST(3,2)   
C
           ELTIME = -1.0
C
C-H-PC      Don't know.  ETIME wasn't found when I did f77 
C-H-PC      with the default libraries.  I don't have any H-P docs,
C-H-PC      just the man page for f77.
C
C-IBMC      Don't know.  Someone said MCLOCK maybe, but I don't
C-IBMC      have any docs at the moment.
C-IBMC        Also:
C-IBMC      - Anyone know a good way to get current time and date?
C-IBMC        I've got a C routine I wrote that worked AIX 3.1.
C-IBMC        Any library routines that will work without needing 
C-IBMC        to invoke the C compiler?
C
C
C-SUN      ELTIME = ETIME( TARRAY )
C
C-SGI      ELTIME = ETIME( TARRAY )
C
C-RSC      ELTIME = ETIME( TARRAY )
C
C-CVX      ELTIME = ETIME( TARRAY )
C
C-HAR      ELTIME = ETIME( TARRAY )
C
C-CRY      CALL     SECOND ( ELTIME )
C
C-VAXC    
C-VAXC     DETERMINES THE CURRENT CPU TIME FOR TASK IN SECONDS   
C-VAXC     This will include your login process values as well, if
C-VAXC     that's appropriate for this run.
C-VAXC     This was written in 1980.  Anything better in 1992?
C-VAXC    
C-VAX      ITEM_LIST (1,1) = '04070004'X    
C-VAX      ITEM_LIST (2,1) = %LOC(CPU_TIME) 
C-VAX      ITEM_LIST (3,1) = 0   
C-VAX      ITEM_LIST (1,2) = 0   
C-VAX      ITEM_LIST (2,2) = 0   
C-VAX      ITEM_LIST (3,2) = 0   
C-VAX      CALL SYS$GETJPI (,,,ITEM_LIST,,,)  
C-VAX      ELTIME = CPU_TIME / 100.  
C
           RETURN
           END
-- 
== Thomas W. Held                           theld@udecc.engr.udayton.edu  == 
== University of Dayton Research Institute     or                         ==
== Dayton, Ohio                             heldtw@udavxb.oca.udayton.edu ==
==    -->Not speaking for the University of Dayton or any of its offices. ==