[PATCH] Fix PR fortran/41157 -- dtime gives inconsistent results.
Steve Kargl
sgk@troutmask.apl.washington.edu
Mon Aug 24 21:07:00 GMT 2009
Here's a patch for fortran/41157. dtime is documented
to return the execution since its last invocation. For
x reasons that I don't fully understand, the current
implementation of dtime seems to skip saving the current
execution time on every other invocation.
For an unpatched gfortran, this code
program test_dtime
implicit none
integer :: i, k
real, dimension(2) :: tarray
real result, accum, x
accum = 0.e0
do k=1, 10
call loop(k, x)
call dtime(tarray, result)
print '(4F10.6)', tarray, result, x
accum = accum + tarray(1)
end do
print '(''accum ='', F10.5)', accum
end program test_dtime
subroutine loop(k, x)
integer, intent(in) :: k
real, intent(out) :: x
x = 1.
do i = 1, 10000000
x = sin(x * i + 1.)
end do
x = x / k
end subroutine loop
REMOVE:kargl[310] ./z
0.442741 0.000000 0.442741 0.927705
0.442212 0.000000 0.442212 0.463853
0.884233 0.000000 0.884233 0.309235
0.884425 0.000000 0.884425 0.231926
1.326463 0.000000 1.326463 0.185541
1.326812 0.000000 1.326812 0.154618
1.768775 0.000000 1.768775 0.132529
1.768707 0.000000 1.768707 0.115963
2.209823 0.000000 2.209823 0.103078
2.209864 0.000000 2.209864 0.092771
accum = 13.26406
The first column should be 0.44xxx. The second column is
0.00000 and the third column is the sum of the first two.
The last column is the output from the loop() to prevent
the optimizer from removing the call to loop().
While a patched gfortran now yields
REMOVE:kargl[299] ./z
0.441574 0.000000 0.441574 0.927705
0.441296 0.000000 0.441296 0.463853
0.441349 0.000000 0.441349 0.309235
0.441090 0.000000 0.441090 0.231926
0.441855 0.000000 0.441855 0.185541
0.442233 0.000000 0.442233 0.154618
0.442404 0.000000 0.442404 0.132529
0.442425 0.000000 0.442425 0.115963
0.442323 0.000000 0.442323 0.103078
0.441952 0.000000 0.441952 0.092771
accum = 4.41850
2009-08-24 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/41157
* dtime.c (dtime_sub): Fix computing time increment.
* time_1.h: Add <sys/types.h> header. Use RUSAGE_SELF macro instead
of a hardcoded 0.
OK for trunk and 4.4?
--
Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dtime.diff
Type: text/x-diff
Size: 2051 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20090824/ce8b136a/attachment.bin>
More information about the Fortran
mailing list