A few years ago, I compared time measurement subroutines in Fortran. I recommend date_and_time
or omp_get_wtime
(OpenMP’s time measurement function) as time measurement subroutines.
For system_clock
, the count rate is different depending on the compiler. Especially for PGI (currently nvfortran), the upper limit of measurement time is about 36 minutes when integer(int32)
is used for the count.
Also, system_clock and cpu_time cannot measure the execution time of a parallelized program.
The table below shows the measurement results when calculating the addition of 2^{13} \times 2^{13} 2d arrays (c(:,:)=a(:,:)+b(:,:)
) parallelized by OpenMP.
date_and_time
is the best in viewpoints of the accuracy and portability. omp_get_wtime
is the second best.
compiler | subroutine | execution time [s] 1 thread |
2 threads |
4 threads |
---|---|---|---|---|
Intel | system_clock |
0.113 | 0.069 | 0.048 |
cpu_time |
0.109 | 0.115 | 0.109 | |
date_and_time |
0.114 | 0.060 | 0.029 | |
omp_get_wtime |
0.112 | 0.057 | 0.027 | |
PGI | system_clock |
0.112 | 0.063 | 0.050 |
cpu_time |
0.111 | 0.057 | 0.028 | |
date_and_time |
0.112 | 0.057 | 0.028 | |
omp_get_wtime |
0.111 | 0.057 | 0.028 | |
GNU | system_clock |
0.113 | 0.063 | 0.045 |
cpu_time |
0.109 | 0.094 | 0.031 | |
date_and_time |
0.113 | 0.058 | 0.029 | |
omp_get_wtime |
0.113 | 0.057 | 0.028 |
Intel: Intel Parallel Studio XE Composer Edition for Fortran 17.0.4.210
PGI: PGI Visual Fortran for Windows 18.7
GNU: gfortran 7.3.0 (for Ubuntu on WSL)