io_stopwatch Subroutine

public subroutine io_stopwatch(tag, mode)

Stopwatch to time parts of the code

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: tag

Which stopwatch to act upon

integer, intent(in) :: mode

Action 1=start 2=stop


Calls

proc~~io_stopwatch~~CallsGraph proc~io_stopwatch io_stopwatch proc~io_error io_error proc~io_stopwatch->proc~io_error

Called by

proc~~io_stopwatch~~CalledByGraph proc~io_stopwatch io_stopwatch proc~gyrotropic_main gyrotropic_main proc~gyrotropic_main->proc~io_stopwatch proc~berry_main berry_main proc~berry_main->proc~io_stopwatch

Contents

Source Code


Source Code

  subroutine io_stopwatch(tag, mode)
    !=====================================
    !! Stopwatch to time parts of the code
    !=====================================

    implicit none

    character(len=*), intent(in) :: tag
    !! Which stopwatch to act upon
    integer, intent(in)          :: mode
    !! Action  1=start 2=stop

    integer :: i
    real(kind=dp) :: t

    call cpu_time(t)

    select case (mode)

    case (1)

      do i = 1, nnames
        if (clocks(i)%label .eq. tag) then
          clocks(i)%ptime = t
          clocks(i)%ncalls = clocks(i)%ncalls + 1
          return
        endif
      enddo

      nnames = nnames + 1
      if (nnames .gt. nmax) call io_error('Maximum number of calls to io_stopwatch exceeded')

      clocks(nnames)%label = tag
      clocks(nnames)%ctime = 0.0_dp
      clocks(nnames)%ptime = t
      clocks(nnames)%ncalls = 1

    case (2)

      do i = 1, nnames
        if (clocks(i)%label .eq. tag) then
          clocks(i)%ctime = clocks(i)%ctime + t - clocks(i)%ptime
          return
        endif
      end do

      write (stdout, '(1x,3a)') 'WARNING: name = ', trim(tag), ' not found in io_stopwatch'

    case default

      write (stdout, *) ' Name = ', trim(tag), ' mode = ', mode
      call io_error('Value of mode not recognised in io_stopwatch')

    end select

    return

  end subroutine io_stopwatch