TIMER
Compute Elapsed Time


TIMER is a directory of FORTRAN77 programs which compute the elapsed CPU time or wallclock time of a part of a calculation.

The idea is that you want to determine the amount of CPU time taken by a piece of your code, so you write lines like this:


        call timer ( t_start)
        do i = 1, n
          ...some big calculation...
        end do
        call timer ( t_stop )
        write ( *, * ) 'Elapsed CPU time = ', t_stop - t_start
      

Up until FORTRAN90, the FORTRAN language did not specify a standard way to access a system timer. At that point, the subroutine CPU_TIME() was added to the language. In many cases, a single FORTRAN compiler is used to compile FORTRAN77 and FORTRAN90 codes. In that case, it is possible that the compiler will allow a FORTRAN77 program to invoke the CPU_TIME() subroutine, thus solving the timing problem.

Users of FORTRAN on UNIX systems could access a system library routine called ETIME for this purpose, but ETIME was not part of the language, and was not to be found on other operating systems.

On various computers, there are often vendor-supplied routines to do this chore. You will often find that the timer is inaccurate; some operations will be reported as taking zero time; other operations will be reported with times that differ by 5 or 10 percent. Moreover, two timers that profess to measure the same thing may produce results that are consistently different by a factor of 40 percent.

Another problem is "wrap around". Many timers reach a maximum value, and then reset themselves to zero. If this happens to you, (it's happened to me many times!) you may find that a certain procedure seems to take negative time!

Some timers return CPU time, that is, the amount of elapsed computer time that was used by your program; other routines return "real" time or "wall clock" time, which will not account for situations in which your program started, and then was paused for some reason (swapped out, waiting for I/O, or other system functions), and then finished.

For parallel programming, the important thing to measure is the elapsed wallclock time. This can be found by subtracting an initial reading of the wallclock time from a final one.

The OpenMP system provides a function used as follows:

        seconds = omp_get_wtime ( )
        operations to time;
        seconds = omp_get_wtime ( ) - seconds;
      
while the MPI system provides a similar function used as:
        seconds = MPI_Wtime ( );
        operations;
        seconds = MPI_Wtime ( ) - seconds;
      
and in MATLAB, wallclock time can be taken with "tic" and "toc":
        tic;
        operation;
        seconds = toc;
      

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages:

TIMER is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version and a PYTHON version.

Related Data and Programs:

LINPACK_BENCH, a FORTRAN77 program which measures the time taken by LINPACK to solve a particular linear system.

MATMUL, a FORTRAN77 program which is an interactive matrix multiplication benchmark program.

MDBNCH, a FORTRAN77 program which is a benchmark code for a molecular dynamics calculation.

MEMORY_TEST, a FORTRAN90 program which declares and uses a sequence of larger and larger vectors, to see how big a vector can be used on a given machine and compiler.

MPI, FORTRAN77 programs which illustrate the use of the MPI application program interface for carrying out parallel computations in a distributed memory environment.

OPENMP, FORTRAN77 programs which illustrate the use of the OpenMP application program interface for carrying out parallel computations in a shared memory environment.

SUM_MILLION, a FORTRAN77 program which sums the integers from 1 to 1,000,000, as a demonstration of how to rate a computer's speed;

TIMESTAMP, a FORTRAN77 library which returns the YMDHMS date as a timestamp.

WTIME, a FORTRAN77 library which returns a reading of the wall clock time in seconds.

Examples and Tests:

TIMER_CPU_TIME uses the CPU_TIME() subroutine, which was only added to the FORTRAN language with FORTRAN90. Therefore, a given FORTRAN77 program might, or might not, be able to call this subroutine, depending on how the compiler is implemented.

TIMER_ETIME uses the ETIME routine, which is only available on UNIX systems:

TIMER_OMP_GET_WTIME uses the OpenMP wall clock function omp_get_wtime():

You can go up one level to the FORTRAN77 source codes.


Last revised on 08 January 2013.