基准测试fortran循环
我需要对fortran程序的一部分进行基准测试,以了解和量化特定更改的影响(为了使代码更易维护,我们希望使代码更加面向对象,充分利用函数指针例)。基准测试fortran循环
我有一个循环调用几次相同的子程序来执行有限元素的计算。我想看看使用函数指针而不是硬编码函数的影响。
do i=1,n_of_finite_elements
! Need to benchmark execution time of this code
end do
什么是一个简单的方法来获得这种循环的执行时间,并以一种很好的方式格式化?
我有一个测量通过各种阵列的https://github.com/jlokimlin/array_passing_performance.git
表现它使用https://github.com/jlokimlin/cpu_timer.git的CpuTimer派生数据类型的GitHub的项目。
用法:
use, intrinsic :: iso_fortran_env, only: &
wp => REAL64, &
ip => INT32
use type_CpuTimer, only: &
CpuTimer
type (CpuTimer) :: timer
real (wp) :: wall_clock_time
real (wp) :: total_processor_time
integer (ip) :: units = 0 ! (optional argument) = 0 for seconds, or 1 for minutes, or 2 for hours
! Starting the timer
call timer%start()
do i = 1, n
!...some big calculation...
end do
! Stopping the timer
call timer%stop()
! Reading the time
wall_clock_time = timer%get_elapsed_time(units)
total_processor_time = timer%get_total_cpu_time(units)
! Write time stamp to standard output
call timer%print_time_stamp()
! Write compiler info to standard output
call timer%print_compiler_info()
这很有趣,可以很好用,但很难涵盖整个话题。 –
那实际上是这样的我想要的东西。我会尽力限制我的问题,使其与我猜想的答案范围相匹配。 –
在这种情况下,您可以始终使用一组标准内部过程'system_clock()'和'cpu_time()',尽管此包在一个对象中具有更多功能。 –
你在寻找的东西,型材的需要作为一个整体多久的代码,或只是粗略时间?你使用的是什么操作系统和编译器?查看['CPU_TIME'](https://gcc.gnu.org/onlinedocs/gfortran/CPU_005fTIME.html)的简单方法来手动检查。另外[这个问题](http://scicomp.stackexchange.com/questions/6812/fortran-best-way-to-time-sections-of-your-code)可能会有用。 – Gabe
@加贝请不要使用'CPU_TIME'。它并不适合时间测量,特别是在[并行编程](https://*.com/questions/25465101/fortran-parallel-programming)中。相反,使用'SYSTEM_CLOCK'。 –
作为一个整体的时机,但基准是(我希望)不仅仅是注意系统时间。例如,[ruby基准](http://ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html)提供了一些有趣的指标,如用户,系统和总时间,在非常很好的显示,甚至解释了基准测试时需要采取的预防措施。 –