How to do time measurements in C and Fortran?


On BG/L we recommend to use the rts_get_timebase() function for timing purposes:
  • rts_get_timebase() returns the number of processor cycles executed since the partition was booted.
  • This number of clock ticks can be converted to seconds using the processor frequency (700 MHz).

Time measurement in C

    #include <rts.h>
    
    static double clockspeed=1.0e-6/700.0;
    
    double bgl_wtime() {
      return ( rts_get_timebase() * clockspeed );
    }
    
Time measurement in Fortran
    module rts
    ! interface definition of rts_get_timebase, Fortran2003, available in XLF Version 9
      interface
        function rts_get_timebase() bind(c)
          use, intrinsic       :: iso_c_binding
          integer(c_long_long) :: rts_get_timebase
        end function rts_get_timebase
      end interface
    end module rts
    
    program rts_from_fortran
      use rts
      use, intrinsic :: iso_c_binding
      implicit none
    
      integer(c_long_long)  :: t1, t2
      real(kind=8)          :: clockspeed
    
      clockspeed = 700.0d6
    
      t1 = rts_get_timebase()
    !      do some work
      t2 = rts_get_timebase()
    
      write(*,*) "Diff Ticks", (t2 - t1)
      write(*,*) "Total time", (t2 - t1)/clockspeed       ! Elapsed equal to CPU time
    end program rts_from_fortran
    
  • To use RTS function calls, you need to link with the library librts.rts.a:
          blrts_xlf90 ... -L /bgl/BlueLight/ppcfloor/bglsys/lib -l rts.rts ...



last change 25.08.2005 | Ulrike Schmidt | Print