next up previous contents
Next: Calls to derivs_Schrodinger() Up: Optimization Previous: Calls to dvector() and

Calls to rk4p480()

The calls to derivs_Schrodinger() come from the inner loop of schint() calling rk4p480(). We can avoid these calls by including the derivs_Schrodinger() code directly into rk4p480() and the rk4p480() code directly into schint(). We can do this by hand, at the risk of introducing many bugs, or we can induce the compiler to do this.

To get the gnu compiler to do this you must include code for all three functions, derivs_Schrodinger(), rk4p480() and schint(), in the same file, right next to each other, and in this same sequence. Also, to allow ``in-lining'' you must compile the code with the optimization flag ``-O3''. So that we may further modify rk4p480(), please keep the original copy and call your new copy of the routine rk4p480Sch(). Also, be sure to update the call in schint() to call the new routine rk4p480Sch().

Upon our making these changes, gprof now reports the following.

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 51.90      1.91     1.91     2419     0.79     1.18  schint
 25.82      2.86     0.95 14063775     0.00     0.00  derivs_Schrodinger
 12.50      3.32     0.46       25    18.40   147.20  getg
  4.35      3.48     0.16   200050     0.00     0.00  excp
  2.45      3.57     0.09   100025     0.00     0.00  exc
  1.36      3.62     0.05       25     2.00     3.20  getphi
  0.54      3.64     0.02   150000     0.00     0.00  derivs_Poisson
  0.54      3.66     0.02       75     0.27     2.63  getPsi
  0.27      3.67     0.01    50000     0.00     0.00  rk4p480
  0.27      3.68     0.01       75     0.13    29.77  zriddrp480
  0.00      3.68     0.00     7646     0.00     0.00  dvector
  0.00      3.68     0.00     7646     0.00     0.00  free_dvector
  0.00      3.68     0.00     1880     0.00     1.18  func_Schrodinger
  0.00      3.68     0.00      389     0.00     1.18  func_SchrodingerNodes
  0.00      3.68     0.00      150     0.00     0.00  simpint
  0.00      3.68     0.00      125     0.00     3.68  rtbisp480
  0.00      3.68     0.00       30     0.00     0.00  dmatrix
  0.00      3.68     0.00       30     0.00     0.00  free_dmatrix
  0.00      3.68     0.00       25     0.00     0.00  d3tensor
  0.00      3.68     0.00       25     0.00     0.00  free_d3tensor
  0.00      3.68     0.00       10     0.00     0.00  lubksbp480
  0.00      3.68     0.00       10     0.00     0.00  ludcmpp480
  0.00      3.68     0.00        2     0.00     0.00  free_ivector
  0.00      3.68     0.00        2     0.00     0.00  ivector
  0.00      3.68     0.00        1     0.00  3680.00  main
Note that there are now far fewer calls to rk4p480() and no calls to rk4p480Sch()! This is because the compiler has in-lined rk4p480Sch() and included it explicitly into schint, avoiding all of the unnecessary associated subroutine calls. There are still, however, calls to derivs_Schrodinger().



Tomas Arias
Mon Apr 2 13:24:52 EDT 2001