Skip to content
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

Logger timing update - Improvements due to deployment in LightROM #135

Merged
merged 6 commits into from
Nov 27, 2024
Merged
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
1 change: 1 addition & 0 deletions example/ginzburg_landau/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ program demo

!> Set up timing
call timer%initialize()
call timer%add_timer('Ginzburg-Landau example', start=.true.)

!> Initialize physical parameters.
call initialize_parameters()
Expand Down
47 changes: 36 additions & 11 deletions example/roessler/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ program demo
real(wp), dimension(r, r) :: Lr
! IO
character(len=20) :: data_fmt, header_fmt
!integer, allocatable :: logunits(:)

write (header_fmt, *) '(22X,*(A,2X))'
write (data_fmt, *) '(A22,*(1X,F15.6))'
Expand All @@ -53,6 +52,8 @@ program demo

! Set up timing
call timer%initialize()
call timer%add_timer('Roessler example (total)', start=.true.)
call timer%add_timer('Chaotic attractor', start=.true.)

! Initialize baseflow and perturbation state vectors
call bf%zero(); call dx%zero(); call residual%zero()
Expand All @@ -75,6 +76,9 @@ program demo
print data_fmt, 'Final position :', eval(1), eval(2), eval(3), Tend
print *, ''

call timer%stop('Chaotic attractor')
call timer%add_timer('Newton iteration (const. tol)', start=.true.)

print *, '########################################################################################'
print '(A,E9.2,A)', ' # Newton iteration with constant tolerance (tol=', tol, ') #'
print *, '########################################################################################'
Expand All @@ -92,11 +96,6 @@ program demo
sys%jacobian = jacobian()
sys%jacobian%X = bf

! Reset eval timer
call sys%reset_timer()
! Reset system timers
call timer%reset_all()

! Set tolerance
tol = 1e-12_wp

Expand All @@ -110,6 +109,12 @@ program demo
print data_fmt, 'Solution residual:', residual%x, residual%y, residual%z, residual%T
print *, ''

! Reset timers
call timer%stop('Newton iteration (const. tol)')
call sys%reset_timer()
call timer%reset_all()
call timer%add_timer('Newton iteration (dyn. tol)', start=.true.)

print *, '########################################################################################'
print '(A,E9.2,A)', ' # Newton iteration with dynamic tolerances (target=', tol, ') #'
print *, '########################################################################################'
Expand All @@ -131,6 +136,12 @@ program demo
print data_fmt, 'Solution residual:', residual%x, residual%y, residual%z, residual%T
print *, ''

! Reset timers
call timer%stop('Newton iteration (dyn. tol)')
call sys%reset_timer()
call timer%reset_all()
call timer%add_timer('Monodromy matrix & Floquet exp.', start=.true.)

print *, '########################################################################################'
print *, '# Monodromy matrix and floquet exponents #'
print *, '########################################################################################'
Expand All @@ -139,11 +150,6 @@ program demo
! Compute the stability of the orbit
sys%jacobian = floquet_operator()
sys%jacobian%X = bf ! <- periodic orbit

! Reset eval timer
call sys%reset_timer()
! Reset system timers
call timer%reset_all()

M = 0.0_wp
Id = eye(npts)
Expand All @@ -161,6 +167,12 @@ program demo
end do
print *, ''

! Reset timers
call timer%stop('Monodromy matrix & Floquet exp.')
call sys%reset_timer()
call timer%reset_all()
call timer%add_timer('OTD modes - fixed-point', start=.true.)

print *, '########################################################################################'
print *, '# Optimally Time-Dependent (OTD) modes on fixed point #'
print *, '########################################################################################'
Expand Down Expand Up @@ -208,6 +220,13 @@ program demo
print '(A16,1X,*(F16.9,1X))', 'Reference ', EV_ref
print *, ''
print '(A10,F6.3,1X,*(F16.9,1X))', 'OTD: t=', Tend, eval(1:r)

! Reset timers
call timer%stop('OTD modes - fixed-point')
call sys%reset_timer()
call timer%reset_all()
call timer%add_timer('OTD modes - periodic orbit', start=.true.)

print *, ''
print *, '########################################################################################'
print *, '# Optimally Time-Dependent (OTD) modes on periodic orbit #'
Expand All @@ -232,6 +251,12 @@ program demo
call rename(report_file_OTD_LE, 'example/roessler/PO_LE.txt')
print *, ''

! Reset timers
call timer%stop('OTD modes - periodic orbit')
call sys%reset_timer()
call timer%reset_all()
call timer%add_timer('OTD modes - route to chaos', start=.true.)

print *, ''
print *, '########################################################################################'
print *, '# Optimally Time-Dependent (OTD) modes on Route to Chaos #'
Expand Down
3 changes: 2 additions & 1 deletion src/AbstractLinops.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module LightKrylov_AbstractLinops
use stdlib_optval, only: optval
use LightKrylov_Logger
use LightKrylov_Constants
use LightKrylov_Timer_Utils
use LightKrylov_Timer_Utils, only: lightkrylov_timer
use LightKrylov_Timing, only: time_lightkrylov
use LightKrylov_Utils
use LightKrylov_AbstractVectors
implicit none
Expand Down
3 changes: 2 additions & 1 deletion src/AbstractLinops.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module LightKrylov_AbstractLinops
use stdlib_optval, only: optval
use LightKrylov_Logger
use LightKrylov_Constants
use LightKrylov_Timer_Utils
use LightKrylov_Timer_Utils, only: lightkrylov_timer
use LightKrylov_Timing, only: time_lightkrylov
use LightKrylov_Utils
use LightKrylov_AbstractVectors
implicit none
Expand Down
3 changes: 2 additions & 1 deletion src/AbstractSystems.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module LightKrylov_AbstractSystems
use stdlib_optval, only: optval
use LightKrylov_Logger
use LightKrylov_Constants
use LightKrylov_Timer_Utils
use LightKrylov_Timer_Utils, only: lightkrylov_timer
use LightKrylov_Timing, only: time_lightkrylov
use LightKrylov_AbstractVectors
use LightKrylov_AbstractLinops
implicit none
Expand Down
3 changes: 2 additions & 1 deletion src/AbstractSystems.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module LightKrylov_AbstractSystems
use stdlib_optval, only: optval
use LightKrylov_Logger
use LightKrylov_Constants
use LightKrylov_Timer_Utils
use LightKrylov_Timer_Utils, only: lightkrylov_timer
use LightKrylov_Timing, only: time_lightkrylov
use LightKrylov_AbstractVectors
use LightKrylov_AbstractLinops
implicit none
Expand Down
3 changes: 1 addition & 2 deletions src/BaseKrylov.f90
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module lightkrylov_BaseKrylov
!-------------------------------
use LightKrylov_Constants
use LightKrylov_Logger
use LightKrylov_Timing, only: timer => global_lightkrylov_timer
use LightKrylov_Timer_Utils, only: time_lightkrylov
use LightKrylov_Timing, only: timer => global_lightkrylov_timer, time_lightkrylov
use LightKrylov_Utils
use LightKrylov_AbstractVectors
use LightKrylov_AbstractLinops
Expand Down
3 changes: 1 addition & 2 deletions src/BaseKrylov.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ module lightkrylov_BaseKrylov
!-------------------------------
use LightKrylov_Constants
use LightKrylov_Logger
use LightKrylov_Timing, only: timer => global_lightkrylov_timer
use LightKrylov_Timer_Utils, only: time_lightkrylov
use LightKrylov_Timing, only: timer => global_lightkrylov_timer, time_lightkrylov
use LightKrylov_Utils
use LightKrylov_AbstractVectors
use LightKrylov_AbstractLinops
Expand Down
3 changes: 1 addition & 2 deletions src/IterativeSolvers.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ module lightkrylov_IterativeSolvers
use LightKrylov_Constants
Use LightKrylov_Logger
use LightKrylov_Utils
use LightKrylov_Timing, only: timer => global_lightkrylov_timer
use LightKrylov_Timer_Utils, only: time_lightkrylov
use LightKrylov_Timing, only: timer => global_lightkrylov_timer, time_lightkrylov
use LightKrylov_AbstractVectors
use LightKrylov_AbstractLinops
use LightKrylov_BaseKrylov
Expand Down
3 changes: 1 addition & 2 deletions src/IterativeSolvers.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ module lightkrylov_IterativeSolvers
use LightKrylov_Constants
Use LightKrylov_Logger
use LightKrylov_Utils
use LightKrylov_Timing, only: timer => global_lightkrylov_timer
use LightKrylov_Timer_Utils, only: time_lightkrylov
use LightKrylov_Timing, only: timer => global_lightkrylov_timer, time_lightkrylov
use LightKrylov_AbstractVectors
use LightKrylov_AbstractLinops
use LightKrylov_BaseKrylov
Expand Down
3 changes: 1 addition & 2 deletions src/NewtonKrylov.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module LightKrylov_NewtonKrylov
use stdlib_optval, only: optval
use LightKrylov_Constants
use LightKrylov_Logger
use LightKrylov_Timing, only: timer => global_lightkrylov_timer
use LightKrylov_Timer_Utils, only: time_lightkrylov
use LightKrylov_Timing, only: timer => global_lightkrylov_timer, time_lightkrylov
use LightKrylov_AbstractVectors
use LightKrylov_AbstractLinops
use LightKrylov_AbstractSystems
Expand Down
3 changes: 1 addition & 2 deletions src/NewtonKrylov.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module LightKrylov_NewtonKrylov
use stdlib_optval, only: optval
use LightKrylov_Constants
use LightKrylov_Logger
use LightKrylov_Timing, only: timer => global_lightkrylov_timer
use LightKrylov_Timer_Utils, only: time_lightkrylov
use LightKrylov_Timing, only: timer => global_lightkrylov_timer, time_lightkrylov
use LightKrylov_AbstractVectors
use LightKrylov_AbstractLinops
use LightKrylov_AbstractSystems
Expand Down
53 changes: 37 additions & 16 deletions src/Timer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,41 @@ module LightKrylov_Timing
private
character(len=*), parameter :: this_module = 'LK_Timer'
character(len=*), parameter :: this_module_long = 'LightKrylov_Timer'
logical :: if_time = .false.
logical :: if_time = .false.

public :: time_lightkrylov
public :: global_lightkrylov_timer

! LightKrylov_watch type
type, extends(abstract_watch), public :: lightkrylov_watch
!! Global timing structure to contain all timers within Lightkrylov
character(len=128) :: name = 'lightkrylov_timer'
contains
private
procedure, pass(self), public :: set_private_timers => set_lightkrylov_timers
procedure, pass(self), public :: set_private_timers_and_name => set_lightkrylov_timers
end type lightkrylov_watch

type(lightkrylov_watch) :: global_lightkrylov_timer

contains

logical function time_lightkrylov() result(if_time_lightkrylov)
if_time_lightkrylov = if_time
end function time_lightkrylov

subroutine set_lightkrylov_timer_switch(value)
logical, intent(in) :: value
if (if_time .neqv. value) then
if_time = value
if (if_time) then
call logger%log_message('LightKrylov timing enabled.', module=this_module)
else
call logger%log_message('LightKrylov timing disabled.', module=this_module)
end if
else
call logger%log_debug('LightKrylov timing switched unchanged.', module=this_module)
end if
end subroutine set_lightkrylov_timer_switch

!--------------------------------------------------------------
! Concrete implementations for the lightkrylov_watch type
!--------------------------------------------------------------
Expand All @@ -33,11 +51,11 @@ subroutine set_lightkrylov_timers(self)
!! Initialize global watch within LightKrylov and define private system timers.
class(lightkrylov_watch), intent(inout) :: self
! internal
integer :: count_old
integer :: istart, iend
call self%set_watch_name('LightKrylov_timer')
! timers for LightKrylov_BaseKrylov
count_old = self%get_timer_count()
! rsp
call self%add_timer('qr_with_pivoting_rsp')
call self%add_timer('qr_with_pivoting_rsp', count=istart)
call self%add_timer('qr_no_pivoting_rsp')
call self%add_timer('orthonormalize_basis_rsp')
call self%add_timer('orthonormalize_vector_against_basis_rsp')
Expand Down Expand Up @@ -79,12 +97,12 @@ subroutine set_lightkrylov_timers(self)
call self%add_timer('dgs_basis_against_basis_cdp')
call self%add_timer('arnoldi_cdp')
call self%add_timer('lanczos_bidiagonalization_cdp')
call self%add_timer('lanczos_tridiagonalization_cdp')
call self%add_group('BaseKrylov', istart=count_old+1, iend=self%get_timer_count())
call self%add_timer('lanczos_tridiagonalization_cdp', count=iend)
! define BaseKrylov group
call self%add_group('BaseKrylov', istart=istart, iend=iend)
! timers for LightKrylov_IterativeSolvers
count_old = self%get_timer_count()
! rsp
call self%add_timer('eigs_rsp')
call self%add_timer('eigs_rsp', count=istart)
call self%add_timer('eighs_rsp')
call self%add_timer('svds_rsp')
call self%add_timer('gmres_rsp')
Expand All @@ -110,19 +128,22 @@ subroutine set_lightkrylov_timers(self)
call self%add_timer('svds_cdp')
call self%add_timer('gmres_cdp')
call self%add_timer('fgmres_cdp')
call self%add_timer('cg_cdp')
call self%add_group('IterativeSolvers', istart=count_old+1, iend=self%get_timer_count())
call self%add_timer('cg_cdp', count=iend)
! define IterativeSolvers group
call self%add_group('IterativeSolvers', istart=istart, iend=iend)
! timers for LightKrylov_NewtonKrylov
count_old = self%get_timer_count()
! rsp
call self%add_timer('newton_rsp')
call self%add_timer('newton_rsp', count=istart)
! rdp
call self%add_timer('newton_rdp')
! csp
call self%add_timer('newton_csp')
! cdp
call self%add_timer('newton_cdp')
call self%add_group('NewtonKrylov', istart=count_old+1, iend=self%get_timer_count())
call self%add_timer('newton_cdp', count=iend)
! define NewtonKrylov group
call self%add_group('NewtonKrylov', istart=istart, iend=iend)
! Enable timing
call set_lightkrylov_timer_switch(.true.)
end subroutine set_lightkrylov_timers

end module LightKrylov_Timing
Loading
Loading