Actual source code: mpitime.c
petsc-3.7.1 2016-05-15
Report Typos and Errors

      1: #include <petscsys.h>
      3: #error "Wrong mpi.h included! require mpi.h from MPIUNI"
      4: #endif

      6: #if defined(__cplusplus)
      7: extern "C" {
      8: #endif
      9: /* ------------------------------------------------------------------
     10:    Microsoft Windows has its own time routines
     11: */
     12: #if defined (PETSC_USE_MICROSOFT_TIME)
     13: #include <Windows.h>
     14: #define FACTOR   4294967296.0 /* pow(2,32) */

     16: double MPI_Wtime(void)
     17: {
     18:   static int flag = 1;
     19:   static LARGE_INTEGER  StartTime,PerfFreq,CurTime;
     20:   static double SecInTick=0.0;

     22:   DWORD  dwStartHigh,dwCurHigh;
     23:   double dTime,dHigh;
     24:   double ptime;

     26:   if (flag) {
     27:     if (!QueryPerformanceCounter(&StartTime)) MPI_Abort(MPI_COMM_WORLD,1);
     28:     if (!QueryPerformanceFrequency(&PerfFreq)) MPI_Abort(MPI_COMM_WORLD,1);
     29:     /* Explicitly convert the higher 32 bits, and add the lower 32 bits from the counter */
     30:     /* works on non-pentium CPUs ? */
     31: #if defined(PETSC_HAVE_LARGE_INTEGER_U)
     32:     SecInTick = 1.0/((double)PerfFreq.u.HighPart*FACTOR+(double)PerfFreq.u.LowPart);
     33: #else
     34:     SecInTick = 1.0/((double)PerfFreq.HighPart*FACTOR+(double)PerfFreq.LowPart);
     35: #endif
     36:     flag = 0;
     37:   }

     39:   if (!QueryPerformanceCounter(&CurTime)) MPI_Abort(MPI_COMM_WORLD,1);
     40: #if defined(PETSC_HAVE_LARGE_INTEGER_U)
     41:   dwCurHigh   = (DWORD)CurTime.u.HighPart;
     42:   dwStartHigh = (DWORD)StartTime.u.HighPart;
     43: #else
     44:   dwCurHigh   = (DWORD)CurTime.HighPart;
     45:   dwStartHigh = (DWORD)StartTime.HighPart;
     46: #endif
     47:   dHigh       = (signed)(dwCurHigh - dwStartHigh);

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

     62: /* ------------------------------------------------------------------
     63:     The usual Unix time routines.
     64: */
     65: #else

     67: #if defined(PETSC_HAVE_SYS_TIME_H)
     68: #include <sys/time.h>
     69: #endif

     71: #if defined(PETSC_NEEDS_GETTIMEOFDAY_PROTO)
     72: extern int gettimeofday(struct timeval *,struct timezone *);
     73: #endif

     75: double MPI_Wtime(void)
     76: {
     77:   static struct timeval _tp;
     78:   gettimeofday(&_tp,(struct timezone *)0);
     79:   return  ((double)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);
     80: }
     81: #endif

     83: #if defined(__cplusplus)
     84: }
     85: #endif