GRVY-0.38.0
Performance Timing Example using Fortran API

An illustrative code example in F90 using the performance timer API is shown below (and is also available in the examples directory from a top-level install). This example illustrates basic timer usage.

!!-----------------------------------------------------------------------bl-
!!--------------------------------------------------------------------------
!!
!! libGRVY - a utility library for scientific computing.
!!
!! Copyright (C) 2008-2013,2018-2022 The PECOS Development Team
!! Additional Copyright (C) 2018 individual authors
!!
!! This library is free software; you can redistribute it and/or
!! modify it under the terms of the Version 2.1 GNU Lesser General
!! Public License as published by the Free Software Foundation.
!!
!! This library is distributed in the hope that it will be useful,
!! but WITHOUT ANY WARRANTY; without even the implied warranty of
!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
!! Lesser General Public License for more details.
!!
!! You should have received a copy of the GNU Lesser General Public
!! License along with this library; if not, write to the Free Software
!! Foundation, Inc. 51 Franklin Street, Fifth Floor,
!! Boston, MA 02110-1301 USA
!!
!!-----------------------------------------------------------------------el-
!!
!! Fortran example illustrating performance timing via libGRVY..
!!
!!--------------------------------------------------------------------------
!!--------------------------------------------------------------------------
program main
use grvy
implicit none
integer :: Foo_Sleep = 1
integer :: Bar_Sleep = 2
integer :: Boo_Sleep = 3
integer :: Max_Iters = 2
integer :: i
real*8 :: igot,igot2
character :: timestring*50 = ''
call grvy_asci_time(timestring)
write(*,'(a,a26)') 'Run on: ',trim(timestring)
! Initialize the timing library - the global timer will be
! initialized with this call
call grvy_timer_init('Fortran is the best!');
! Outer Test Loop
do i = 1,max_iters
! Define the beginning of the overall portion to be monitored
print*,'Main iteration loop = ',i
call foo(foo_sleep)
print*,'Elapsed time since global init is: ',igot
call bar(bar_sleep)
call boo(boo_sleep)
enddo
! Finalize the main program timer
! Print performance summary to stdout
print*,' '
print*,'Expecting ',max_iters*(foo_sleep+boo_sleep+bar_sleep),' secs '
! Example use of timer directly
igot = grvy_timer()
call sleep(1)
igot2 = grvy_timer()
print*,' '
print*,'Measured ',igot2-igot,' secs (expected approximately 1.0)'
print*,' '
print*,'The total elapsed time since init is: ',igot
print*,' '
print*,'Query individual timers - should match summary'
write(*,'(1x,"boo: ",es12.5," secs")') grvy_timer_elapsedseconds("boo")
write(*,'(1x,"bar: ",es12.5," secs")') grvy_timer_elapsedseconds("bar")
write(*,'(1x,"foo: ",es12.5," secs")') grvy_timer_elapsedseconds("foo")
print*,' '
print*,'Query individual timer stats - should match summary'
write(*,'(1x,"foo-count: ",i3)') grvy_timer_stats_count("foo")
write(*,'(1x,"foo-mean: ",es12.5)') grvy_timer_stats_mean("foo")
write(*,'(1x,"foo-variance: ",es12.5)') grvy_timer_stats_variance("foo")
write(*,'(1x,"foo-min: ",es12.5)') grvy_timer_stats_min("foo")
write(*,'(1x,"foo-max: ",es12.5)') grvy_timer_stats_max("foo")
! The above queries provide eclusive timing statistics, but you can
! also query inclusive measurements as well
print*,' '
print*,'Query individual timers (inclusive values)'
write(*,'(1x,"boo: ",es12.5," secs")') grvy_timer_elapsedseconds_inc("boo")
write(*,'(1x,"bar: ",es12.5," secs")') grvy_timer_elapsedseconds_inc("bar")
write(*,'(1x,"foo: ",es12.5," secs")') grvy_timer_elapsedseconds_inc("foo")
print*,' '
print*,'Query individual timer stats (inclusive values for boo)'
write(*,'(1x,"boo-mean: ",es12.5)') grvy_timer_stats_mean_inc("boo")
write(*,'(1x,"boo-variance: ",es12.5)') grvy_timer_stats_variance_inc("boo")
write(*,'(1x,"boo-min: ",es12.5)') grvy_timer_stats_min_inc("boo")
write(*,'(1x,"boo-max: ",es12.5)') grvy_timer_stats_max_inc("boo")
! Dump current results to a historical performance logfile
call grvy_timer_save_hist("F90-Example1","",1,"hist.h5")
stop
end program main
subroutine foo(isleep)
use grvy
integer isleep
call grvy_timer_begin('foo');
call sleep(isleep);
call grvy_timer_end('foo');
return
end subroutine foo
subroutine bar(isleep)
use grvy
integer isleep
call grvy_timer_begin('bar');
call sleep(isleep);
call grvy_timer_end('bar');
return
end subroutine bar
subroutine boo(isleep)
use grvy
integer isleep
call grvy_timer_begin('boo');
call sleep(isleep);
call grvy_timer_end('boo');
return
end subroutine boo
grvy_timer_save_hist
int grvy_timer_save_hist(const char *experiment_name, const char *comment, int num_procs, const char *filename)
Save current libGRVY timing results to HDF file for logging.
grvy_timer_stats_min
double grvy_timer_stats_min(const char *id)
Returns the minimum (exclusive) measured timing (in seconds) for defined timer id.
grvy_timer
double grvy_timer()
Basic wallclock timer which provides the time since epoch in seconds.
grvy_timer_finalize
void grvy_timer_finalize()
Finalize global timing process - stops the active global timer.
grvy_timer_elapsedseconds_inc
double grvy_timer_elapsedseconds_inc(const char *id)
Returns total (inclusive) elapsed time (in seconds) for defined timer id.
grvy_timer_begin
void grvy_timer_begin(const char *id)
Identify beginning of code section to time with unique id string.
grvy_timer_stats_count
int grvy_timer_stats_count(const char *id)
Returns the total number of timer calls for defined timer id.
grvy_timer_init
void grvy_timer_init(const char *description)
Initialize timer library with a description string which initiates the global timing process (the des...
grvy_timer_summarize
void grvy_timer_summarize()
Print a concise summary of all defined timers to stdout. This routine shows the relative runtime perc...
grvy_timer_elapsedseconds
double grvy_timer_elapsedseconds(const char *id)
Returns total (exclusive) elapsed time (in seconds) for defined timer id.
grvy_timer_stats_min_inc
double grvy_timer_stats_min_inc(const char *id)
Returns the minimum (inclusive) measured timing (in seconds) for defined timer id.
grvy_timer_stats_max_inc
double grvy_timer_stats_max_inc(const char *id)
Returns the largest (inclusive) measured timing (in seconds) for defined timer id.
grvy_timer_stats_mean_inc
double grvy_timer_stats_mean_inc(const char *id)
Returns the mean (inclusive) value (in seconds) for defined timer id.
grvy_timer_end
void grvy_timer_end(const char *id)
Identify end of code section to time with a matching id string.
grvy_timer_stats_variance_inc
double grvy_timer_stats_variance_inc(const char *id)
Returns the variance (inclusive) for defined timer id.
grvy_timer_elapsed_global
double grvy_timer_elapsed_global()
Returns total elapsed time (in seconds) for the global timer.
grvy_timer_stats_mean
double grvy_timer_stats_mean(const char *id)
Returns the mean (exclusive) value (in seconds) for defined timer id.
grvy_timer_stats_variance
double grvy_timer_stats_variance(const char *id)
Returns the variance (exclusive) for defined timer id.
grvy_timer_stats_max
double grvy_timer_stats_max(const char *id)
Returns the largest (exclusive) measured timing (in seconds) for defined timer id.

Generated on Wed Jul 12 2023 16:53:23 for GRVY-0.38.0 by  doxygen 1.8.17