1 /* 2 Low cost access to a system time. This, in general, should not be included in user programs. 3 */ 4 #pragma once 5 6 #include <petscsys.h> 7 8 /* SUBMANSEC = Sys */ 9 10 PETSC_EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble *); 11 12 /* Global counters */ 13 PETSC_EXTERN PetscLogDouble petsc_BaseTime; 14 15 /*MC 16 PetscTime - Returns the current time from some base time in the past in seconds. 17 18 Synopsis: 19 #include <petsctime.h> 20 PetscErrorCode PetscTime(PetscLogDouble *v) 21 22 Not Collective 23 24 Output Parameter: 25 . v - time counter 26 27 Usage: 28 .vb 29 PetscLogDouble v; 30 PetscTime(&v); 31 .... perform some calculation ... 32 printf("Time for operation %g\n",v); 33 .ve 34 35 Level: developer 36 37 Notes: 38 Since the PETSc libraries incorporate timing of phases and operations, 39 we do not recommend ever using PetscTime() 40 The options database command `-log_view` activates 41 PETSc library timing. 42 43 .seealso: `PetscTimeSubtract()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` 44 M*/ 45 46 /*MC 47 PetscTimeSubtract - Subtracts the current time (in seconds) from the value `v`. 48 49 Synopsis: 50 #include <petsctime.h> 51 PetscErrorCode PetscTimeSubtract(PetscLogDouble *v) 52 53 Not Collective 54 55 Input Parameter: 56 . v - time counter 57 58 Output Parameter: 59 . v - time counter (`v` = `v` - current time) 60 61 Level: developer 62 63 Notes: 64 Since the PETSc libraries incorporate timing of phases and operations, 65 we do not always recommend using `PetscTimeSubtract()`. 66 The options database command `-log_view` activates 67 PETSc library timing. See `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` for how to register 68 stages and events in application codes. 69 70 .seealso: `PetscTime()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` 71 M*/ 72 73 /*MC 74 PetscTimeAdd - Adds the current time (in seconds) to the value `v`. 75 76 Synopsis: 77 #include <petsctime.h> 78 PetscErrorCode PetscTimeAdd(PetscLogDouble *v) 79 80 Not Collective 81 82 Input Parameter: 83 . v - time counter 84 85 Output Parameter: 86 . v - time counter (`v` = `v` + current time) 87 88 Level: developer 89 90 Notes: 91 Since the PETSc libraries incorporate timing of phases and operations, 92 we do not ever recommend using `PetscTimeAdd()`. 93 The options database command `-log_view` activates 94 PETSc library timing. 95 96 .seealso: `PetscTime()`, `PetscTimeSubtract()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` 97 M*/ 98 99 static inline PetscErrorCode PetscTime(PetscLogDouble *v) 100 { 101 *v = MPI_Wtime(); 102 return PETSC_SUCCESS; 103 } 104 105 static inline PetscErrorCode PetscTimeSubtract(PetscLogDouble *v) 106 { 107 *v -= MPI_Wtime(); 108 return PETSC_SUCCESS; 109 } 110 111 static inline PetscErrorCode PetscTimeAdd(PetscLogDouble *v) 112 { 113 *v += MPI_Wtime(); 114 return PETSC_SUCCESS; 115 } 116