subroutine set_timer(proc_timer, obj_level)
!= Start the timer for the specified object.
!= In:
!= obj_level (optional): timing level of the procedure. Procedures with
!= a timing level above the iGlobalTimerLevel (specified in the
!= LOGGING block) are not timed. The default timing level is 30.
!= In/Out:
!= proc_timer: The procedure timer. Should contain the name of the
!= procedure and be SAVEd. On exit, proc_timer%store points to the
!= appropriate entry in the timers array, which contains the
!= timing information for this object. If the procedure is
!= called multiple times, the timer is not reinitialised, but
!= rather updated with new timing information (i.e. the current
!= timer is set).
Use LoggingData, only: iGlobalTimerLevel
type(timer) :: proc_timer
integer, optional, intent(in) :: obj_level
real(dp) :: t
integer :: timer_level
if (time_at_all) then
if (.not. global_timing_on) then
! Initialise global timer.
call init_timing()
end if
if (present(obj_level)) then
timer_level = obj_level
else
timer_level = 30
end if
if (timer_level > iGlobalTimerLevel) then
! This object is too low-level to be timed.
proc_timer%time = .false.
else
proc_timer%time = .true.
if (.not. associated(proc_timer%store)) then
! Have a new object.
itimer = itimer + 1
if (itimer > ntimer) then
call warning_neci('set_timer', 'ntimer parameter too small for the number of objects to be timed.')
proc_timer%time = .false.
timer_error = .true.
return
end if
proc_timer%store => timers(itimer)
end if
proc_timer%store%timer_name = proc_timer%timer_name
proc_timer%store%ncalls = proc_timer%store%ncalls + 1
if (.not. proc_timer%store%timing_on) then
! Not in the middle of a recursive function.
! A recursive function will have the recursive section between the
! set_timer and halt_timer calls. If we avoid refreshing the
! start time for the timer of the recursive procedure, then the
! correct timings are obtained.
! Start the clock.
t = MPI_WTIME()
proc_timer%store%time_cpu = t
proc_timer%store%timing_on = .true.
end if
end if
end if
end subroutine set_timer