TIMER is a directory of C programs which demonstrate ways of computing the elapse CPU time or elapsed wall clock time in a calculation.
The idea is that you want to determine the amount of time taken by a piece of your code, so you write lines like this:
time1 = timer ( ); for ( i = 0; i < n; i++ ) ...some big calculation... } time2 = timer ( ); printf ( "Elapsed CPU time = %f seconds\n", time2 - time1 );
You should not trust a timer that you only use once. If you run the same code several times in a row, you are likely to get different results, especially if you are trying to time things that don't take long. The time will often also vary depending on the system load, the number of other users or processes running, and other factors.
Another problem is "wrap around". Some 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;
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
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.
MPI, C examples which illustrate the use of the MPI application program interface for carrying out parallel computations in a distributed memory environment.
OPENMP, C examples which illustrate the use of the OpenMP application program interface for carrying out parallel computations in a shared memory environment.
SUM_MILLION, a C program which sums the integers from 1 to 1,000,000, as a demonstration of how to rate a computer's speed;
TIMESTAMP, a C library which returns the current wallclock time.
WTIME, a C library which returns a reading of the wall clock time in seconds.
TIMER_CLOCK uses the standard C library CLOCK routine:
TIMER_OMP_GET_WTIME uses the OpenMP wall clock function omp_get_wtime():
You can go up one level to the C source codes.