forked from HYCOM/HYCOM-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wtime.F90
87 lines (87 loc) · 2.04 KB
/
wtime.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#if defined(AIX)
REAL*8 FUNCTION WTIME_DUMMY()
IMPLICIT NONE
!
! USE A C-ROUTINE, SEE machi_c.c.
!
WTIME_DUMMY = 0.0
RETURN
! END OF WTIME_DUMMY.
END
#elif defined(MPI)
REAL*8 FUNCTION WTIME()
IMPLICIT NONE
!
! USE THE MPI FUNCTION MPI_WTIME TO RETURN WALL TIME.
!
DOUBLE PRECISION MPI_WTIME
!
WTIME = MPI_WTIME()
RETURN
! END OF WTIME.
END
#else
REAL*8 FUNCTION WTIME()
IMPLICIT NONE
!
! USE THE F90 INTRINSIC SYSTEM_CLOCK TO RETURN WALL TIME.
!
! WILL FAIL IF THE COUNT IS EVER NEGATIVE, BUT THE STANDARD
! SAYS THAT IT IS AWAYS NON-NEGATIVE IF A CLOCK EXISTS.
! NOT THREAD-SAFE, UNLESS LCOUNT AND IOVER ARE THREADPRIVATE.
!
REAL*8 ZERO,ONE
PARAMETER (ZERO=0.0, ONE=1.0)
!
INTEGER COUNT, MCOUNT, RATE
!
REAL*8 OFFSEC, OFFSET, PERSEC
INTEGER ICOUNT, IOVER, LCOUNT, NCOUNT
SAVE OFFSEC, OFFSET, PERSEC
SAVE ICOUNT, IOVER, LCOUNT, NCOUNT
!
DATA IOVER, LCOUNT / -1, -1 /
!
CALL SYSTEM_CLOCK(COUNT)
!
IF (COUNT.LT.LCOUNT) THEN
!
! COUNT IS SUPPOSED TO BE NON-DECREASING EXCEPT WHEN IT WRAPS,
! BUT SOME IMPLEMENTATIONS DON''T DO THIS. SO IGNORE ANY
! DECREASE OF LESS THAN ONE PERCENT OF THE RANGE.
!
IF (LCOUNT-COUNT.LT.NCOUNT) THEN
COUNT = LCOUNT
ELSE
IOVER = IOVER + 1
OFFSET = OFFSET + OFFSEC
ENDIF
ENDIF
LCOUNT = COUNT
!
IF (IOVER.EQ.0) THEN
!
! FIRST CYCLE, FOR ACCURACY WITH 64-BIT COUNTS.
!
WTIME = (COUNT - ICOUNT) * PERSEC
ELSEIF (IOVER.GT.0) THEN
!
! ALL OTHER CYCLES.
!
WTIME = COUNT * PERSEC + OFFSET
ELSE
!
! INITIALIZATION.
!
CALL SYSTEM_CLOCK(ICOUNT, RATE, MCOUNT)
NCOUNT = MCOUNT/100
PERSEC = ONE/RATE
OFFSEC = MCOUNT * PERSEC
OFFSET = -ICOUNT * PERSEC
IOVER = 0
WTIME = ZERO
ENDIF
RETURN
! END OF WTIME.
END
#endif /* MPI:else */