Swap gsl_gamma_inc with gsl_gamma_inc_P for mass calculation #706
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @jobovy, here is the change that we discussed in (i) of #701
For test cases, I've used integrations of the Sun over 1000Gyr (in order to get a decent sample size for profiling) and MW Globular clusters over 10Gyr;
With the current
main
branch (usinggsl_sf_gamma_inc
), I findand with this change (using
gsl_sf_gamma_inc_P
), I findSo, just less than a 30% improvement for the Sun, and 80% for the collection of MW Globular Clusters, on my machine.
I also took a look at trying out
gsl_sf_gamma * (1 - gsl_sf_gamma_inc_Q)
, but found very similar runtime to with currentmain
;It looks like many of the calls to the gsl P function are diverted to a variation of the Q function (
gamma_inc_Q_large_x
), but if I call thegsl_sf_gamma_inc_Q
directly we mostly end up ingamma_inc_Q_CF => gamma_inc_F_CF
(the same place we end up viagsl_sf_gamma_inc
), which is interesting... Looking at the gsl code, to filter betweengamma_inc_Q_CF
andgamma_inc_Q_large_x
, the P function considers "large_x" asx => 5*a
, whereas the Q function usesx > 1.0e+06
. Anyway, it looks like we end up in the most efficient function for typical orbits by calling the P function.For reference, I've included some of the callmaps obtained by running with
gperftools
profiler below.gsl_sf_gamma - gsl_sf_gamma_inc
gsl_sf_gamma * gsl_sf_gamma_inc_P
gsl_sf_gamma * (1 - gsl_sf_gamma_inc_Q)