I am using gprof on Windows 10 on a toy Fortran program compiled with GNU Fortran (GCC) 11.0.0 20200927 from equation.com . It runs and times the program, but the output of the program is suppressed. For the code
module stats_mod
implicit none
private
public :: rms,mean
contains
function rms(x) result(rms_x)
real, intent(in) :: x(:)
real :: rms_x
rms_x = sqrt(mean(x**2))
end function rms
!
function mean(x) result(xmean)
real, intent(in) :: x(:)
real :: xmean
xmean = sum(x)/max(1,size(x))
end function mean
end module stats_mod
!
program xran_stats
use stats_mod, only: rms,mean
implicit none
integer, parameter :: n = 10000000, niter = 100
real :: x(n),xrms(niter)
integer :: iter
do iter=1,niter
call random_number(x)
xrms(iter) = rms(x)
end do
write (6,*) "results: RMS mean, min, max =",sum(xrms)/niter,minval(xrms),maxval(xrms)
end program xran_stats
compiled and run with
gfortran -pg xran_stats.f90
gprof a.exe
The results of the program are not printed to the screen, although the profile information is shown:
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
36.93 0.89 0.89 _gfortran_arandom_r4
31.95 1.66 0.77 101 7.62 15.05 __stats_mod_MOD_rms
31.12 2.41 0.75 100 7.50 7.50 __stats_mod_MOD_mean
<snip>
Call graph (explanation follows)
granularity: each sample hit covers 4 byte(s) for 0.41% of 2.41 seconds
index % time self children called name
0.01 0.01 1/101 main [5]
0.76 0.74 100/101 MAIN__ [2]
[1] 63.1 0.77 0.75 101 __stats_mod_MOD_rms [1]
0.75 0.00 100/100 __stats_mod_MOD_mean [4]
-----------------------------------------------
<spontaneous>
[2] 62.4 0.00 1.50 MAIN__ [2]
0.76 0.74 100/101 __stats_mod_MOD_rms [1]
-----------------------------------------------
<spontaneous>
[3] 36.9 0.89 0.00 _gfortran_arandom_r4 [3]
-----------------------------------------------
0.75 0.00 100/100 __stats_mod_MOD_rms [1]
[4] 31.1 0.75 0.00 100 __stats_mod_MOD_mean [4]
-----------------------------------------------
<spontaneous>
[5] 0.6 0.00 0.02 main [5]
0.01 0.01 1/101 __stats_mod_MOD_rms [1]
-----------------------------------------------
<snip>
Index by function name
[4] __stats_mod_MOD_mean [1] __stats_mod_MOD_rms [3] _gfortran_arandom_r4
If I change write (6,*)
to write (10,*)
in my code, the file fort.10 is not written to, but if I just run.exe it is created with contents such as
results: RMS mean, min, max = 0.574540854 0.574369133 0.574764371
So it looks like program run with prof can be used for timing but not to generate program results, which is inconvenient. I get the same behavior running gfortran and gprof under Windows Subsystem for Linux.