Actual source code: nt_time.c

      1: #define PETSC_DLL

      3: #include <petsc.h>
      4: #if defined (PETSC_USE_NT_TIME)
      5: #include <Windows.h>
      6: #define FACTOR   4294967296.0 /* pow(2,32) */

     10: PetscLogDouble PETSC_DLLEXPORT nt_time(void)
     11: {
     12:   static PetscTruth     flag = PETSC_TRUE;

     15:   static LARGE_INTEGER  StartTime,PerfFreq,CurTime;
     16:   static PetscLogDouble SecInTick=0.0;
     17:
     18:   DWORD                 dwStartHigh,dwCurHigh;
     19:   PetscLogDouble        dTime,dHigh;
     20:   PetscLogDouble        ptime;
     21:
     22:
     24:   if (flag) {
     25:     QueryPerformanceCounter(&StartTime);CHKERRQ(!ierr);
     26:     QueryPerformanceFrequency(&PerfFreq);CHKERRQ(!ierr);
     27:     /* Explicitly convert the higher 32 bits, and add the lower 32 bits from the counter */
     28:     /* works on non-pentium CPUs ? */
     29: #if defined(PETSC_HAVE_LARGE_INTEGER_U)
     30:     SecInTick = 1.0/((double)PerfFreq.u.HighPart*FACTOR+(double)PerfFreq.u.LowPart);
     31: #else
     32:     SecInTick = 1.0/((double)PerfFreq.HighPart*FACTOR+(double)PerfFreq.LowPart);
     33: #endif
     34:     flag = PETSC_FALSE;
     35:   }
     36:
     37:   QueryPerformanceCounter(&CurTime);CHKERRQ(!ierr);
     38: #if defined(PETSC_HAVE_LARGE_INTEGER_U)
     39:   dwCurHigh   = (DWORD)CurTime.u.HighPart;
     40:   dwStartHigh = (DWORD)StartTime.u.HighPart;
     41: #else
     42:   dwCurHigh   = (DWORD)CurTime.HighPart;
     43:   dwStartHigh = (DWORD)StartTime.HighPart;
     44: #endif
     45:   dHigh       = (signed)(dwCurHigh - dwStartHigh);

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

     57:   PetscFunctionReturn(ptime);
     58: }
     59: #endif