Timing your code

To time portions of your code, here are some solutions.


SYSTEM_CLOCK is standard Fortran90, very efficient, since it is a language intrinsic.

integer :: counti, countf, count_rate real :: dt call system_clock(counti,count_rate) ... work .... call system_clock(countf) dt=REAL(countf-counti)/REAL(count_rate)

MPI (both Fortran and C):

MPI_WTIME is an MPI function, returning the elapsed time on the calling processor.

double precision :: t1,t2,dt ... t1 = MPI_WTIME() ... work ... t2 = MPI_WTIME() dt = t2-t1


If you need timing in C and you are not using MPI, you must avoid the typical routines time, times, clock, because all of them return the user time, not the real one. To get the real-time use gettimeofday():

#include <stddef.h>
#include <sys/time.h>
double t1,t2,dt;
struct timeval start,end;
int rtn;

rtn=gettimeofday(&start, NULL);
... work ...
rtn=gettimeofday(&end, NULL);