checktime Subroutine

public subroutine checktime(avail_time, exit, margin_in)

Check whether elapsed run time is within a 5 minutes of exceeding the available CPU time, and if so trigger the code exit.

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: avail_time
logical, intent(inout) :: exit
real, intent(in), optional :: margin_in

Contents

Source Code


Source Code

  subroutine checktime(avail_time, exit, margin_in)
    use mp, only: proc0, broadcast
    use file_utils, only: error_unit
    use exit_codes, only: EXIT_OUT_OF_TIME
    use optionals, only: get_option_with_default
    implicit none
    ! available time in second
    real, intent(in) :: avail_time
    ! margin
    real, intent(in), optional :: margin_in
    ! true if elapse time exceed available time
    logical, intent(in out) :: exit
    real :: elapse_time
    real, save :: margin = 300. ! 5 minutes
    margin = get_option_with_default(margin_in, margin)

    if (.not. checktime_initialized) then
       call init_checktime
    else
      elapse_time = timer_local() - wall_clock_initial_time

      if (proc0) then
         if (elapse_time >= avail_time - margin) then
            write(error_unit(),'(a,f12.4,a,f12.4)') &
                 & 'Elapse time ',elapse_time, &
                 & ' exceeds available time',avail_time-margin
            write(error_unit(),'(a,f12.4,a,f12.4,a)') &
                 & '  (Given CPU time: ',avail_time, &
                 & '  Margin: ',margin,')'
            exit = .true.
            call EXIT_OUT_OF_TIME%write_exit_file()
         end if
      end if
    end if

    call broadcast(exit)
  end subroutine checktime