forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to count function "CALL" ?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
sospel



Joined: 26 Apr 2013
Posts: 31

PostPosted: Wed Jan 23, 2019 5:43 pm    Post subject: How to count function "CALL" ? Reply with quote

Hello Smile

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6039
Location: Salford, UK

PostPosted: Wed Jan 23, 2019 9:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2135
Location: Sydney

PostPosted: Thu Jan 24, 2019 3:24 am    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6039
Location: Salford, UK

PostPosted: Thu Jan 24, 2019 9:04 am    Post subject: Reply with quote

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
View user's profile Send private message
sospel



Joined: 26 Apr 2013
Posts: 31

PostPosted: Thu Jan 24, 2019 9:17 pm    Post subject: Reply with quote

@PaulLaidler and @JohnCampbell

hello Smile

thank you for your quick answers ! I thought a solution was not obvious Sad

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
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 557
Location: UK

PostPosted: Thu Jan 24, 2019 11:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
sospel



Joined: 26 Apr 2013
Posts: 31

PostPosted: Fri Jan 25, 2019 8:22 pm    Post subject: Reply with quote

@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
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1191

PostPosted: Sat Jan 26, 2019 1:47 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group