! iteration.f90 ! ! iteration control for timing measurements ! use this module with the pattern below to get reasonable ! timing measurements ! ! 11/7/96 JSS adapted from ACM SIGAda Performance Issues Working Group ! module iteration implicit none integer :: global ! visible to calling program public global public initialize, start_control, stop_control, start_test, stop_test, & test_stable, increment, feature_times private integer :: local_iteration_count integer :: local_check_times integer :: control_time_initial integer :: control_time_final integer :: control_duration integer :: test_time_initial integer :: test_time_final integer :: test_duration integer :: a_one integer :: count, count_rate, count_max ! for system_clock contains subroutine initialize(iteration_count, check_times) integer, intent(out) :: iteration_count integer, intent(in) :: check_times a_one = 1 iteration_count = 1 local_iteration_count = 1 local_check_times = check_times end subroutine initialize subroutine start_control call system_clock(count, count_rate, count_max) control_time_initial = count end subroutine start_control subroutine stop_control call system_clock(count, count_rate, count_max) control_time_final = count if (global /= local_check_times) then print *, "global not incremented check_times in control" stop end if end subroutine stop_control subroutine start_test call system_clock(count, count_rate, count_max) test_time_initial = count end subroutine start_test subroutine stop_test call system_clock(count, count_rate, count_max) test_time_final = count if (global /= local_check_times) then print *, "global not incremented check_times in test" stop end if end subroutine stop_test subroutine test_stable(iteration_count, stable) integer, intent(inout) :: iteration_count logical, intent(out) :: stable if(iteration_count < 1024) then iteration_count = iteration_count * 2 local_iteration_count = local_iteration_count * 2 stable = .false. else stable = .true. end if end subroutine test_stable subroutine increment(global) integer, intent(inout) :: global global = global + a_one end subroutine increment subroutine feature_times(cpu_time, tolerance, feature_time, executions) real, intent(out) :: cpu_time real, intent(out) :: tolerance real, intent(out) :: feature_time real, intent(out) :: executions executions = real(local_check_times) * real(local_iteration_count) control_duration = control_time_final - control_time_initial test_duration = test_time_final - test_time_initial cpu_time = real(test_duration - control_duration) / real(count_rate) feature_time = cpu_time / executions tolerance = 0.05 * feature_time end subroutine feature_times end module iteration