简体   繁体   中英

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

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 ?

I have a github project that measures the performance of passing various arrays at https://github.com/jlokimlin/array_passing_performance.git

It uses the CpuTimer derived data type from https://github.com/jlokimlin/cpu_timer.git .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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