Skip to content

compacter timing #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions drhook/yomhook_dummy.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@

module yomhook

use omp_lib

public

logical :: lhook = .true.

! allocate two large arrays
DOUBLE PRECISION, allocatable :: total_time(:)
DOUBLE PRECISION, allocatable :: tstart(:), tstop(:)
DOUBLE PRECISION, allocatable :: total_time(:,:)
DOUBLE PRECISION, allocatable :: tstart(:,:)
integer, allocatable :: ncalls(:)
CHARACTER(len=80), allocatable :: names(:)
integer, parameter :: hash_size = 1000
integer, parameter :: hash_size = 100000
integer :: omp_num_threads

contains

Expand All @@ -32,7 +35,7 @@ SUBROUTINE char_to_hash(c, a)
INTEGER :: i

INTEGER :: p = 31
INTEGER :: m = hash_size - 3
INTEGER :: m = 1e5 + 5
INTEGER :: p_pow

a = 0
Expand All @@ -42,37 +45,51 @@ SUBROUTINE char_to_hash(c, a)
p_pow = MOD(p_pow * p, m)
END DO

! convert to index
a = MOD(a, hash_size) + 1

END SUBROUTINE

subroutine dr_hook(proc_name, iswitch, proc_key)

use parkind1, only : jprb

character(len=*), intent(in) :: proc_name
character(len=*), intent(in) :: proc_name
integer, intent(in) :: iswitch
real(jprb), intent(inout) :: proc_key
integer :: idx
double precision, external :: omp_get_wtime
integer :: idx, thread_id
double precision :: tstop

idx = INT(proc_key)
thread_id = omp_get_thread_num()
if (iswitch == 0) then
call char_to_hash(proc_name, idx)
proc_key = real(idx)
names(idx) = proc_name
ncalls(idx) = ncalls(idx) + 1
tstart(idx) = omp_get_wtime()
if(thread_id == 0) then
if(ncalls(idx) == 0) then
names(idx) = proc_name
endif
ncalls(idx) = ncalls(idx) + 1
if(trim(proc_name) /= names(idx)) then
print*, "careful, overlapping entries in hash table: ", proc_name, " and ", names(idx)
endif
endif
tstart(idx,thread_id) = omp_get_wtime()
else if (iswitch == 1) then
tstop(idx) = omp_get_wtime()
total_time(idx) = total_time(idx) + (tstop(idx) - tstart(idx))
idx = INT(proc_key)
tstop = omp_get_wtime()
total_time(idx,thread_id) = total_time(idx,thread_id) + (tstop - tstart(idx,thread_id))
endif

end subroutine dr_hook

subroutine initialize_timers()

allocate(total_time(hash_size))
allocate(tstart(hash_size))
allocate(tstop(hash_size))
CHARACTER(len=255) :: ntstr
CALL get_environment_variable("OMP_NUM_THREADS", ntstr)
READ(ntstr, '(I2)') omp_num_threads

allocate(total_time(hash_size, 0:omp_num_threads-1))
allocate(tstart(hash_size, 0:omp_num_threads-1))
allocate(ncalls(hash_size))
allocate(names(hash_size))

Expand All @@ -84,12 +101,16 @@ end subroutine initialize_timers
subroutine finalize_timers()

integer :: idx
double precision :: ttime

open(1, file="timing.txt", action="write")

do idx = 1,1000
if(total_time(idx) > 0.0) then
write(1, '(A80,E10.3,I10)'), names(idx), total_time(idx), ncalls(idx)
do idx = 1,hash_size
ttime = 0
if(total_time(idx,0) > 0.0) then
ttime = sum(total_time(idx,:)) / omp_num_threads
rms = sqrt( sum( (total_time(idx,:) - ttime)**2) / omp_num_threads)
write(1, '(A80,E10.3,E10.3,I10)'), names(idx), ttime, rms, ncalls(idx)
end if
end do

Expand Down
4 changes: 1 addition & 3 deletions driver/ecrad_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ program ecrad_driver
! --------------------------------------------------------
use parkind1, only : jprb, jprd ! Working/double precision

use yomhook, only : dr_hook, lhook, initialize_timers, finalize_timers
use yomhook, only : lhook, initialize_timers, finalize_timers

use radiation_io, only : nulout
use radiation_interface, only : setup_radiation, radiation, set_gas_units
Expand Down Expand Up @@ -113,7 +113,6 @@ program ecrad_driver


if (lhook) call initialize_timers()
if (lhook) call dr_hook('ecrad_driver:ecrad_driver',0,hook_handle)
! --------------------------------------------------------
! Section 2: Configure
! --------------------------------------------------------
Expand Down Expand Up @@ -361,7 +360,6 @@ program ecrad_driver
write(nulout,'(a)') '------------------------------------------------------------------------------------'
end if

if (lhook) call dr_hook('ecrad_driver:ecrad_driver',1,hook_handle)
if (lhook) call finalize_timers()

end program ecrad_driver
16 changes: 7 additions & 9 deletions timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def cli(ref_file, cur_file):
ref = pd.read_csv(
ref_file,
delim_whitespace=True,
names=["routine", "time", "ncalls"],
names=["routine", "time", "spread", "ncalls"],
index_col=0,
)
cur = pd.read_csv(
cur_file,
delim_whitespace=True,
names=["routine", "time", "ncalls"],
names=["routine", "time", "spread", "ncalls"],
index_col=0,
)

Expand Down Expand Up @@ -46,14 +46,12 @@ def cli(ref_file, cur_file):

a = cur.loc[selection, "time"]
b = ref.loc[selection, "time"]
c = b / a
d = cur.loc[selection, "ncalls"]

print("\ncurrent time")
print("-------------------------------------")
print(a)

print("\nreference time")
print("-------------------------------------")
print(b)
d = pd.concat([b, a, c, d], axis=1)
d.columns = ["reference", "current", "speedup", "ncalls"]
print(d)


if __name__ == "__main__":
Expand Down