Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28461 Discussions

Timing code (CPU_Time vs System_Clock)

lklawrie
Beginner
758 Views
Does anyone have experience with timing code processes (non-threaded) using System_Clock?

As described (Fortran 95/2003 Explained, Metcalf et al), it looks like System_Clock would be the preferred way to go, but the CPU_Time seems to be more in line with the "clock time" on the computer.

Any hints on articles (search on the forum didn't show much) that I should look at?
0 Kudos
1 Reply
TimP
Honored Contributor III
758 Views
Certainly, system_clock() is useful when you want elapsed time. On linux, a generally implemented way of taking advantage of the f2003 requirement to allow big integer arguments (kind=8) is to have system_clock give microsecond resolution as well as supporting reasonably long intervals. Support for Fortran 2003 guarantees only that the big integers are acceptable, not that they necessarily work better than default integers. Maybe Windows Fortran could adopt this improvement soon.
cpu_time totals up the time spent by the CPU on your application only among all threads. Yes, it's effectively the same as the C library clock() function. In ifort, it has 0.01 second resolution, so it can't time smaller intervals. It may be interesting to compare cpu_time against system_clock to see what effective parallelism you achieve in a parallelized application, or how much time is idle or taken by tasks outside your application.
The primary alternatives for elapsed time would be omp_get_wtime(), for an application using OpenMP library, or MPI_Wtime, when using MPI library.
Unfortunately, several articles easily found by your search engine (even Wikipedia) may mislead you about implementation details.
0 Kudos
Reply