How to show the true wall time instead of cpu_time?

The current description of cpu_time is:

CPU_TIME(TIME)

Description. Processor time used.

Class. Subroutine.

Argument. TIME shall be a real scalar. It is an INTENT(OUT) argument. If the processor cannot provide a meaningful value for the time, it is assigned a processor-dependent negative value; otherwise, it is assigned a processor-dependent approximation to the processor time in seconds. Whether the value assigned is an approximation to the amount of time used by the invoking image, or the amount of time used by the whole program, is processor dependent. [emphasis added]

Interestingly, there is a note I did not know about:

A processor for which a single result is inadequate (for example, a parallel processor) might choose to provide an additional version for which time is an array. [emphasis added]

The exact definition of time is left imprecise because of the variability in what different processors are able to provide. The primary purpose is to compare different algorithms on the same processor or discover which parts of a calculation are the most expensive

I haven’t tested any compiler to see if there exists an array version of cpu_time.

3 Likes

Well, just found that our great friend John Burkardt has a wtime() function which uses system_clock, link is below,

https://people.sc.fsu.edu/~jburkardt/f_src/wtime/wtime.html

John Burkardt said in the webpage,

wtime, a FORTRAN90 code which returns a reading of the wall clock time.

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 code provides a way to get a similar reading:

    seconds = wtime ( );
    operations;
    seconds = wtime ( ) - seconds;

I have briefly test it with and without openMP, it seems really give the wall (elapsed) time. I may just use it for now.

There is also a similar SO link question,