View previous topic :: View next topic |
Author |
Message |
sospel
Joined: 26 Apr 2013 Posts: 31
|
Posted: Wed Jan 23, 2019 5:43 pm Post subject: How to count function "CALL" ? |
|
|
Hello
Having written with Silverfrost FTN95 a (large) program of astronomical calculations, I use it to calculate a number of characteristics of the Solar System. The results obtained are excellent, compared to those of the Official Data Centres (e.g. the C.D.S of Strasbourg), and furthermore, fast : the calculation of the characteristics of the Sun and all planets for the 365 days of a year takes only 1.8 seconds on a little amateur HP computer !
That said, just out of intellectual curiosity, I would like to know how many times this program calls trigonometric functions over multiple calculations of essential parameters and numerous iterations to solve certain differential equations.
Hence my question : is there an utility function or programming method to detect "on the fly" and increment the number of calls to a COS(), a SIN(), and another ARCTG() ?
Thanks in advance for any suggestions or link
Cordially,
Sospel |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7932 Location: Salford, UK
|
Posted: Wed Jan 23, 2019 9:50 pm Post subject: |
|
|
Sospel
There is no automatic way to count the number of calls. In a sense this is particularly true for functions like COS and SIN that don't require any external code.
You would need to do your own counting which would add a significant overhead. |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2556 Location: Sydney
|
Posted: Thu Jan 24, 2019 3:24 am Post subject: |
|
|
You should experiment with the FTN95 /timing option.
I am a big fan of this.
you need to divide the code into routines:
# you want to time (sim_ver1_tim.f90)
# you don't want to time (called too many times) (sutil.f90)
# and other un-timed utility routines (util.f90)
My batch file to achieve this to generate sim_tim.exe is:
Code: | set program=sim_tim
set trace=ftn95_tim.tce
now > %trace%
del *.obj >> %trace%
del *.mod >> %trace%
SET TIMINGOPTS=/TMO /DLM ,
ftn95 sim_ver1_tim /timing >> %trace%
ftn95 sutil /debug >> %trace%
ftn95 util /debug >> %trace%
slink main_tim.txt >> %trace%
dir *.exe >> %trace%
type %trace%
%program% test_xx.txt > %program%.tce
|
My file main_tim.txt is Code: | lo sim_ver1_tim.obj
lo sutil.obj
lo util.obj
le \clearwin\saplib.mem\saplib.lib
map sim_tim.map
file sim_tim.exe |
My file "sim_ver1_tim.f90" consists of lots of include of .f90 files for the code to be tested for call counts and elapse times. Code: | ! Last change: JDC 11 Sep 2009 10:47 am
include 'sim_data.f95'
include 'yrdplt.f95'
include 'get_historical_ships.f95'
include 'sim_ver1.f95'
include 'read_data.f95'
include 'read_swell_history.f95'
include 'initialise.f95'
include 'open.f95'
include 'stem_gen.f95'
include 'next.f95'
include 'day.f95'
include 'vessel_move.f95'
include 'vessel_ab.f95'
include 'channel.f95'
include 'tide.f95'
include 'debal_calc.f95'
include 'depart.f95'
include 'train.f95'
include 'train_move.f95'
include 'pend.f95'
include 'choose.f95'
include 'choose_equip.f95'
include 'pform.f95'
include 'update.f95'
include 'report.f95'
include 'lotus.f95' |
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7932 Location: Salford, UK
|
Posted: Thu Jan 24, 2019 9:04 am Post subject: |
|
|
I should have mentioned that FTN95 has the /PROFILE option on the command line that can be used with 64 bit compilation. This provides a count of how many times each line of the code is visited.
The documentation for the 32 bit debugger SDBG also mentions a PROFILE command but I have not tested this. |
|
Back to top |
|
|
sospel
Joined: 26 Apr 2013 Posts: 31
|
Posted: Thu Jan 24, 2019 9:17 pm Post subject: |
|
|
@PaulLaidler and @JohnCampbell
hello
thank you for your quick answers ! I thought a solution was not obvious
I will try however to implement JohnCampbell�s method, but I think it will be difficult to adapt it to my software
I will also see if the /PROFILE option is taken into account by my 32 bit system ?
Thank you again !
cordially
SosPel |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Jan 24, 2019 11:56 pm Post subject: |
|
|
You can over-ride the function and count the calls using something like the following:
Code: |
function sin(x)
real, intent(in) :: x
real sin
integer n
common /sin_count/ n
intrinsic asin
n = n + 1
sin = asin(x)
end function
program main
integer n, i
common /sin_count/ n
external sin
real x, y
x = 0.0
n = 0
do i=1, 1000
y = sin(x)
end do
do i=1, 1000
y = sin(x)
end do
print *, 'number of calls = ', n
end program main
|
Not ideal, but OK if it's just to satisfy your curiosity. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
sospel
Joined: 26 Apr 2013 Posts: 31
|
Posted: Fri Jan 25, 2019 8:22 pm Post subject: |
|
|
@davidb
>>> You can over-ride the function and count the calls using something like the following:
Thank for your suggestion which seems to be easy to implement in my software: I think it will suffice for me to make a "over-ride" for each trigonometric function then to run the execution. I had forgotten this possibility of FORT95, not always allowed in other languages
I�ll execute your example first to verify if I have 2,000 uses of the SIN() function ...
This seems obvious , but I sometimes have functions with somewhat complicated arguments and we are never immune from a surprise !
Thank you again,
Cordially
Sospel |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1888
|
Posted: Sat Jan 26, 2019 1:47 am Post subject: |
|
|
In many cases, it is not necessary to hook a profiler to a library function entry point to count the number of function calls, especially if all the calls occur in source code that you have and can change.
If, for instance, you have a small number of references to sin() in your code, you can simply add statements such as "nsin = nsin + 1" if the expression is scalar, or "nsin = nsin + n" if the expression is a vector of size n, set nsin = 0 at the beginning of the program, and print nsin at the end.
This approach makes it unnecessary to reduce optimisation levels, as many compilers require in order to enable profiling. |
|
Back to top |
|
|
|