abstract_watch Derived Type

type, public, abstract :: abstract_watch

Base type to define a global timer. All watches within LightKrylov and associated tools are derived from this type.

Within LightKrylov, the derived type global_lightkrylov_timer is used to manage all atomic timers associated with both internal routines (private) as well as user-defined (public) timers that can be added and removed as necessary. In order to protect the private timers, they are defined and set only during the initialisation of the derived type via the deferred procedure set_private_timers_and_name if timing is requested and cannot be deleted. Once the global watch is initalized, the user can define and subsequently remove user-defined timers at any point that will be managed by the global watch in the same way as private timers. Upon finalization, the user-defined timers with the associated timing information is presented together with that of the private timers.

The type-bound procedures of the abstract_watch type allow individual access to each managed timer individually using the timer name as reference.


Type-Bound Procedures

procedure, public, pass(self) :: add_group

Add new timer group to the watch.

  • private subroutine add_group(self, name, istart, iend, count)

    Type-bound to abstract_watch: Add timer group to watch. Note: The new group name must be unique. This is a quick hack and should be done better.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name
    integer, intent(in) :: istart
    integer, intent(in) :: iend
    integer, intent(out), optional :: count

procedure, public, pass(self) :: add_timer

Add new timer to the watch.

  • private subroutine add_timer(self, name, start, count)

    Type-bound to abstract_watch: Add timer to watch and optionally start it immediately. Note: The new timer name must be unique.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name
    logical, intent(in), optional :: start
    integer, intent(out), optional :: count

procedure, public, pass(self) :: enumerate

Print summary of registered timers and their current status.

  • private subroutine enumerate(self, only_user)

    Type-bound to abstract_watch: Summarize registered timers and their status.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(in) :: self
    logical, intent(in), optional :: only_user

    Summarize only user defined timers? default: .false.

procedure, public, pass(self) :: finalize

Gather timing information and print it to screen/logfile.

  • private subroutine finalize(self, write_to_file)

    Finalize global watch within LightKrylov and print used timers.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    logical, intent(in), optional :: write_to_file

    Print timer summary to a dedicated timer logfile as well as the general log file? default: .true.

procedure, public, pass(self) :: get_data => get_timer_data_by_name

  • private subroutine get_timer_data_by_name(self, name, restart, etime, etmin, etmax, etimp, lcount, rcount, gcount)

    Type-bound to abstract_watch: Getter routine to return the data for timer referenced by name. Notes: Wrapper of the corresponding routine from lightkrylov_timer. If it is running, the timer is stopped.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name
    logical, intent(in), optional :: restart
    real(kind=dp), intent(out), optional :: etime
    real(kind=dp), intent(out), optional :: etmin
    real(kind=dp), intent(out), optional :: etmax
    real(kind=dp), intent(out), optional :: etimp
    integer, intent(out), optional :: lcount
    integer, intent(out), optional :: rcount
    integer, intent(out), optional :: gcount

procedure, public, pass(self) :: get_group_id

  • private function get_group_id(self, name) result(id)

    Type-bound to abstract_watch: Getter routine to return the group id based on name.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch) :: self
    character(len=*) :: name

    Timer name

    Return Value integer

procedure, public, pass(self) :: get_time => get_timer_etime_by_name

  • private function get_timer_etime_by_name(self, name, restart) result(etime)

    Type-bound to abstract_watch: Getter routine to return the current etime for timer referenced by name. Notes: Wrapper of the corresponding routine from lightkrylov_timer. If it is running, the timer is stopped.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch) :: self
    character(len=*) :: name
    logical, optional :: restart

    Return Value real(kind=dp)

procedure, public, pass(self) :: get_timer_id

  • private function get_timer_id(self, name) result(id)

    Type-bound to abstract_watch: Getter routine to return the timer id based on name.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch) :: self
    character(len=*) :: name

    Timer name

    Return Value integer

procedure, public, pass(self) :: initialize

Set up private timers, flags and counters. Switch on timing.

  • private subroutine initialize(self)

    Initialize global watch within LightKrylov and define private system timers.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self

procedure, public, pass(self) :: pause => pause_timer_by_name

  • private subroutine pause_timer_by_name(self, name)

    Type-bound to abstract_watch: Pause timer referenced by name. Note: Wrapper of the corresponding routine from lightkrylov_timer.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name

procedure, public, pass(self) :: print_info => print_timer_info_by_name

  • private subroutine print_timer_info_by_name(self, name)

    Type-bound to abstract_watch: Print timing information for timer referenced by name. Note: Wrapper of the corresponding routine from lightkrylov_timer.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name

procedure, public, pass(self) :: remove_timer

Remove existing timer from the watch.

  • private subroutine remove_timer(self, name, count)

    Type-bound to abstract_watch: Remove timer from watch. Note: Timers considered private (defined during initialisation) cannot be removed.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name
    integer, intent(out), optional :: count

procedure, public, pass(self) :: reset => reset_timer_by_name

  • private subroutine reset_timer_by_name(self, name, soft, clean)

    Type-bound to abstract_watch: Reset timer referenced by name. Note: Wrapper of the corresponding routine from lightkrylov_timer.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name
    logical, intent(in), optional :: soft
    logical, intent(in), optional :: clean

procedure, public, pass(self) :: reset_all

Reset all timers in watch.

  • private subroutine reset_all(self, soft, clean)

    Type-bound to abstract_watch: Utility function to reset all timers at once. Note: Wrapper of the corresponding routine from lightkrylov_timer.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    logical, intent(in), optional :: soft
    logical, intent(in), optional :: clean

procedure(abstract_set_timers), public, deferred, pass(self) :: set_private_timers_and_name

Define private timers that cannot be removed by the user.

  • subroutine abstract_set_timers(self) Prototype

    Interface for defining timers and groups.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self

procedure, public, pass(self) :: set_watch_name

  • private subroutine set_watch_name(self, name)

    Type-bound to abstract_watch: Set name of watch

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name

    Watch name

procedure, public, pass(self) :: start => start_timer_by_name

  • private subroutine start_timer_by_name(self, name)

    Type-bound to abstract_watch: Start timer referenced by name. Note: Wrapper of the corresponding routine from lightkrylov_timer.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name

procedure, public, pass(self) :: stop => stop_timer_by_name

  • private subroutine stop_timer_by_name(self, name)

    Type-bound to abstract_watch: Stop timer referenced by name. Note: Wrapper of the corresponding routine from lightkrylov_timer.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_watch), intent(inout) :: self
    character(len=*), intent(in) :: name

Source Code

   type, abstract, public :: abstract_watch
      !! Base type to define a global timer.
      !! All watches within LightKrylov and associated tools are derived from this type.
      !!
      !! Within LightKrylov, the derived type `global_lightkrylov_timer` is used to manage all
      !! atomic timers associated with both internal routines (private) as well as user-defined
      !! (public) timers that can be added and removed as necessary. In order to protect the 
      !! private timers, they are defined and set only during the initialisation of the derived 
      !! type via the deferred procedure `set_private_timers_and_name` if timing is requested 
      !! and cannot be deleted.
      !! Once the global watch is initalized, the user can define and subsequently remove 
      !! user-defined timers at any point that will be managed by the global watch in the same
      !! way as private timers.
      !! Upon finalization, the user-defined timers with the associated timing information is 
      !! presented together with that of the private timers.
      !!
      !! The type-bound procedures of the abstract_watch type allow individual access to each
      !! managed timer individually using the timer name as reference.
      private
      character(len=128) :: name = 'default_watch'
      type(lightkrylov_timer), dimension(:), allocatable :: timers
      !! Array of timers contained in the watch.
      integer :: timer_count    = 0
      !! Number of timers managed by watch.
      type(lightkrylov_timer_group), dimension(:), allocatable :: groups
      !! Array of timer groups contained in the watch.
      integer :: group_count    = 0
      !! Number of timer groups managed by watch.
      integer :: private_count  = 0
      !! Number of private timers (immutable by user).
      integer :: user_count     = 0
      !! Number of user defined timers.
      logical :: user_mode      = .false.
      !! Number of user defined timers.
      logical :: is_initialized = .false.
   contains
      private
      procedure, pass(self), public :: add_timer
      !! Add new timer to the watch.
      procedure, pass(self), public :: remove_timer
      !! Remove existing timer from the watch.
      procedure, pass(self), public :: add_group
      !! Add new timer group to the watch.
      ! Getter/Setter and helper routines for watch components.
      procedure, pass(self), public :: get_timer_id
      procedure, pass(self), public :: get_group_id
      procedure, pass(self), public :: set_watch_name
      ! Wrappers for the basic timing routines/access to timer components.
      procedure, pass(self), public :: start => start_timer_by_name
      procedure, pass(self), public :: stop => stop_timer_by_name
      procedure, pass(self), public :: pause => pause_timer_by_name
      procedure, pass(self), public :: reset => reset_timer_by_name
      procedure, pass(self), public :: get_time => get_timer_etime_by_name
      procedure, pass(self), public :: get_data => get_timer_data_by_name
      procedure, pass(self), public :: print_info => print_timer_info_by_name
      ! Global manipulation routines.
      procedure, pass(self), public :: reset_all
      !! Reset all timers in watch.
      procedure, pass(self), public :: enumerate
      !! Print summary of registered timers and their current status.
      procedure, pass(self), public :: initialize
      !! Set up private timers, flags and counters. Switch on timing.
      procedure, pass(self), public :: finalize
      !! Gather timing information and print it to screen/logfile.
      procedure(abstract_set_timers), pass(self), deferred, public :: set_private_timers_and_name
      !! Define private timers that cannot be removed by the user.
   end type abstract_watch