简体   繁体   English

基准测试fortran循环

[英]Benchmarking fortran loop

I need to benchmark a part of a fortran program to understand and quantify the impact of specific changes (in order to make the code more maintainable we'd like to make it more OO, taking advantage of function pointers for example). 我需要对fortran程序的一部分进行基准测试,以理解和量化特定更改的影响(为了使代码更易于维护,我们希望使其更趋于面向对象(例如,利用函数指针))。

I have a loop calling several times the same subroutines to perform computations on finite elements. 我有一个循环,多次调用相同的子例程以对有限元素执行计算。 I want to see the impact of using function pointers instead of just hard-coded functions. 我想看看使用函数指针而不只是硬编码函数的影响。

do i=1,n_of_finite_elements
   ! Need to benchmark execution time of this code
end do

What would be a simple way to get the execution time of such a loop, and format it in a nic way ? 获取此类循环的执行时间并以nic方式对其进行格式化的简单方法是什么?

I have a github project that measures the performance of passing various arrays at https://github.com/jlokimlin/array_passing_performance.git 我有一个github项目,该项目在https://github.com/jlokimlin/array_passing_performance.git上测量传递各种数组的性能

It uses the CpuTimer derived data type from https://github.com/jlokimlin/cpu_timer.git . 它使用从https://github.com/jlokimlin/cpu_timer.git派生的CpuTimer数据类型。

Usage: 用法:

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM