-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimer.F90
90 lines (76 loc) · 1.98 KB
/
timer.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
88
89
90
! The philosophy of this module is the following:
! 1. in case we're using MPI, we can rely on MPI_Wtime and all is
! easy and straightforward.
! 2. Otherwise, we must rely on system_clock, which gives a value
! which wraps around and is always smaller than count_max, so we
! need to compensate for that.
! Note: since this program is mostly run with MPI, case 2 is likely to
! be less tested.
module timer
implicit none
real :: initial_time
logical :: initialised = .false.
private :: initial_time, initialised
#ifndef MPI
real :: last_time
private :: last_time
#endif
contains
subroutine initialise()
#ifdef MPI
use mpi
use comms_common
implicit none
integer :: ierr
#else
implicit none
integer :: count, count_rate, count_max
#endif
#ifdef MPI
initial_time = real(MPI_Wtime())
call MPI_AllReduce(MPI_In_Place, initial_time, 1, MPI_Real, MPI_Min, comm, ierr)
#else
call system_clock(count, count_rate, count_max)
initial_time = real(count)/count_rate
last_time = initial_time
#endif
initialised = .true.
end subroutine initialise
function get_time_from_start() result(time_from_start)
#ifdef MPI
use mpi
use comms_common
implicit none
integer :: ierr
#else
implicit none
integer :: count, count_rate, count_max
#endif
real :: time, time_from_start
if (.not. initialised) then
#ifdef MPI
if (ip_global .eq. 0) then
#endif
print *, "Timer not initialised!"
#ifdef MPI
endif
#endif
#ifdef MPI
call MPI_Abort(comm, 1, ierr)
#endif
stop
endif
#ifdef MPI
time = real(MPI_Wtime())
call MPI_AllReduce(MPI_In_Place, time, 1, MPI_Real, MPI_Max, comm, ierr)
#else
call system_clock(count, count_rate, count_max)
time = real(count)/count_rate
do while (time .lt. last_time)
time = time + real(count_max)/count_rate
enddo
last_time = time
#endif
time_from_start = time - initial_time
end function get_time_from_start
end module timer