print_timing_report Subroutine

public subroutine print_timing_report(ntimer_objects, iunit)

Arguments

Type IntentOptional Attributes Name
integer, intent(in), optional :: ntimer_objects
integer, intent(in), optional :: iunit

Contents

Source Code


Source Code

    subroutine print_timing_report(ntimer_objects, iunit)
        != Output a timing report.
        != If the global timer has been turned off (ie end_timing has been
        != called), then also deallocate the timers array).
        != In:
        !=    ntimer_objects (optional): the timing report prints out the objects
        !=    took the largest amount of time in total.  ntimer_objects gives the
        !=    number of objects to print out, in descending order of total time.
        !=    Default value: 10, as set in Logging module.
        !=    iunit (optional): file unit to which the timing  report is printed.
        !=    Default value: 6 (stdout).
        Use LoggingData, only: nPrintTimer
        integer, optional, intent(in) :: ntimer_objects
        integer, optional, intent(in) :: iunit
        integer :: io = 6
        integer :: nobjs
        integer :: i, it, id(1)
        real(dp) :: t
        real(dp) :: sum_times(ntimer), total_cpu
        integer :: date_values(8)

        if (time_at_all) then

            ! Add on a small perturbation for the cases where the total time is
            ! zero to single-precision.  This forces the procedure times to be printed
            ! out, if required, even if they are 0.0000, by avoiding issues with
            ! maxloc as the elements of the sum_times array are set to zero.
            sum_times = timers(:)%sum_time_cpu + 1.e-4_dp

            if (present(iunit)) io = iunit
            if (present(ntimer_objects)) then
                nobjs = ntimer_objects
            else
                nobjs = nPrintTimer
            end if

            write (io, '(/a65)') '================================================================'

            write (io, '(a15/)') 'Timing report.'
            if (timer_error) write (io, '(a61/)') 'Timer encountered errors.  The following might be incorrect.'
            if (min(itimer, nobjs) > 0) then
                write (io, '(a37)') 'Timing of most expensive procedures.'
                write (io, '(a65)') 'Procedure                                 Calls       total time'
                write (io, '(a65)') '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '

                total_cpu = 0.0_dp
                do i = 1, min(itimer, nobjs)
                    ! Find i-th most expensive procedure.
                    id = maxloc(sum_times)
                    it = id(1)
                    sum_times(it) = 0.0_dp ! Don't find this object again.
                    if (timers(it)%ncalls > 0) then
                        write (io, '(1X,a25,12X,i9,1f10.2)') adjustl(timers(it)%timer_name), timers(it)%ncalls, &
                            timers(it)%sum_time_cpu
                    endif
                    total_cpu = total_cpu + timers(it)%sum_time_cpu
                end do
                write (io, '(a65)') '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '
                write (io, '(a35,f10.2/)') 'Total                             ', total_cpu
            end if
            if (.not. global_timing_on) then
                write (io, '(1X,a26,f10.2)') 'Global wall clock time    ', global_time
            else
                t = MPI_WTIME()
                write (io, '(1X,a26,f10.2)') 'Global wall clock time    ', t - global_time
            end if
            write (io, '(a65)') '================================================================'

            if (.not. global_timing_on) deallocate (timers) ! Assume we're done as end_timing has been called.

            call date_and_time(VALUES=date_values)
            write (io, '(1X,"Calculation ended",1X,i2.2,"/",i2.2,"/",i4.4,1X,"at",1X,i2.2,2(":",i2.2))') &
                date_values(3:1:-1), date_values(5:7)
            write (io, '(a65)') '================================================================'
        end if

    end subroutine print_timing_report