This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libfortran/35355] Result of call cpu_time(x) can decrease or give non credible values with repeated calls



------- Comment #3 from fxcoudert at gcc dot gnu dot org  2008-03-01 16:49 -------
I've built new binaries today and I can also see it  :(

$ cat a.f90
implicit none
integer, parameter :: pr = selected_real_kind (6,37)
real(kind=pr) :: t
integer ,parameter :: n = 1000
real :: x(n,n), y(n,n), z(n,n)

call cpu_time(t)
print *, t
call flush()
z = matmul(x,y)
call cpu_time(t)
print *, t
call flush()
z = matmul(x,y)
call cpu_time(t)
print *, t
call flush()
z = matmul(x,y)
call cpu_time(t)
print *, t
call flush()
end

$ gfortran.exe a.f90 && a
  0.46875000    
   8.5625000    
   8.5937500    
   17.000000    

I've spotted the issue: the Windows FILETIME structure stores time as a "number
of 100-nanosecond intervals". So, to get to our usual microseconds, we need to
divide by 10 (we're not loosing any precision, because Windows doesn't have
100ns resolution anyway). But, Daniel's 2007-12-25 patch reworked the code and
remove the division by 10. Thus, we're now storing tens of microseconds in the
usec variables, which leads to wrong results in the end.

A possible patch is:

Index: time_1.h
===================================================================
--- time_1.h    (revision 132800)
+++ time_1.h    (working copy)
@@ -104,10 +104,10 @@
                   &kernel_time.ft, &user_time.ft);

   *user_sec = user_time.ulltime / 10000000;
-  *user_usec = user_time.ulltime % 10000000;
+  *user_usec = (user_time.ulltime % 10000000) / 10;

   *system_sec = kernel_time.ulltime / 10000000;
-  *system_usec = kernel_time.ulltime % 10000000;
+  *system_usec = (kernel_time.ulltime % 10000000) / 10;
   return 0;
 }


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dfranke at gcc dot gnu dot
                   |                            |org, fxcoudert at gcc dot
                   |                            |gnu dot org
             Status|UNCONFIRMED                 |NEW
          Component|fortran                     |libfortran
     Ever Confirmed|0                           |1
 GCC target triplet|                            |i586-pc-mingw32
           Keywords|                            |patch, wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2008-03-01 16:49:05
               date|                            |
   Target Milestone|---                         |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35355


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]