Are there really any reliable ways to time Fortran code?

This SYSTEM_CLOCK approach is best for Windows 10 (and probably +) and Gfortran.
The best way to check is to report “clock_rate” as it can show the update rate of “clock_reading”.
Unfortunately for some implementations ( eg Intel Ifort from a few years ago provided SYSTEM_CLOCK updating at 64 cps ) where the “clock_rate” did not represent the frequency at which “clock_reading” was updated.
On windows, CPU_TIME and OMP_get_wtime did also suffer from awful precision, being updated only 64 cycles per second. I do not know if this has been improved with recent updates.

I understand that for linux, this update frequency issue is not as serious a problem.

However, even for Windows 10, Gfortran and integer(8), the clock_rate is about processor clock rate / 1024, so this can not be used to time smaller packets of computation.

For higher precision, you need to sample the rdtsc clock. This should be an intrinsic function extension provided by the compiler. Unfortunately I do not know how this timer varies when the processor rate varies, ie over-clocks, but all high frequency timers have problems !

1 Like

My preferred way is how I handle my timers. If I am timing time per ranks I will use MPI_Wtime but since my MPI workloads are decently simple I just simple set a timer around where I know I won’t time two ranks.

Are you timing an MPI application or what are you timing?

1 Like

If you need to profile large scale parallel applications, then you should check out PAPI, TAU, and VAMPIR.

These are probably overkill for just timing a small routine but can really help identify the parts of your code that need work to improve overall performance.

1 Like

Thank much all of your replies! @jorgeg @JohnCampbell @rwmsu
The application I am timing, have both MPI and non-MPI version. The non-MPI version is just the MPI version with a dummy mpi module (so all the MPI operations reduced to those on just one core). In the dummy mpi module, I use John Burkardt’s system_clock version as a ‘fake’ mpi_wtime. It seems fine for estimating the wall time.