Date: 2013-07-02T14:39:06+00:00

Actual source code: nt_time.c
petsc-3.4.2 2013-07-02

      2: #include <petscsys.h>
      3: #include <Windows.h>
      4: #define FACTOR   4294967296.0 /* pow(2,32) */

      8: PETSC_EXTERN PetscLogDouble PetscMicrosoftTime(void)
      9: {
     10:   static PetscBool flag = PETSC_TRUE;
     11:   PetscErrorCode   ierr;

     13:   static LARGE_INTEGER  StartTime,PerfFreq,CurTime;
     14:   static PetscLogDouble SecInTick=0.0;

     16:   DWORD          dwStartHigh,dwCurHigh;
     17:   PetscLogDouble dTime,dHigh;
     18:   PetscLogDouble ptime;

     22:   if (flag) {
     23:     QueryPerformanceCounter(&StartTime);CHKERRQ(!ierr);
     24:     QueryPerformanceFrequency(&PerfFreq);CHKERRQ(!ierr);
     25:     /* Explicitly convert the higher 32 bits, and add the lower 32 bits from the counter */
     26:     /* works on non-pentium CPUs ? */
     27: #if defined(PETSC_HAVE_LARGE_INTEGER_U)
     28:     SecInTick = 1.0/((double)PerfFreq.u.HighPart*FACTOR+(double)PerfFreq.u.LowPart);
     29: #else
     30:     SecInTick = 1.0/((double)PerfFreq.HighPart*FACTOR+(double)PerfFreq.LowPart);
     31: #endif
     32:     flag = PETSC_FALSE;
     33:   }

     35:   QueryPerformanceCounter(&CurTime);CHKERRQ(!ierr);
     36: #if defined(PETSC_HAVE_LARGE_INTEGER_U)
     37:   dwCurHigh   = (DWORD)CurTime.u.HighPart;
     38:   dwStartHigh = (DWORD)StartTime.u.HighPart;
     39: #else
     40:   dwCurHigh   = (DWORD)CurTime.HighPart;
     41:   dwStartHigh = (DWORD)StartTime.HighPart;
     42: #endif
     43:   dHigh       = (signed)(dwCurHigh - dwStartHigh);

     45: #if defined(PETSC_HAVE_LARGE_INTEGER_U)
     46:   dTime = dHigh*(double)FACTOR + (double)CurTime.u.LowPart - (double)StartTime.u.LowPart;
     47: #else
     48:   dTime = dHigh*(double)FACTOR + (double)CurTime.LowPart - (double)StartTime.LowPart;
     49: #endif
     50:   /* Use the following with older versions of the Borland compiler
     51:   dTime = dHigh*(double)FACTOR + (double)CurTime.u.LowPart - (double)StartTime.u.LowPart;
     52:   */
     53:   ptime = (double)SecInTick*dTime;
     54:   PetscFunctionReturn(ptime);
     55: }