From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19391 invoked by alias); 1 Mar 2008 16:49:59 -0000 Received: (qmail 18390 invoked by uid 48); 1 Mar 2008 16:49:06 -0000 Date: Sat, 01 Mar 2008 16:49:00 -0000 Message-ID: <20080301164906.18389.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug libfortran/35355] Result of call cpu_time(x) can decrease or give non credible values with repeated calls In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "fxcoudert at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg00030.txt.bz2 ------- 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