Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lgamma slow with defaults #241

Open
wds15 opened this issue Aug 13, 2019 · 5 comments
Open

lgamma slow with defaults #241

wds15 opened this issue Aug 13, 2019 · 5 comments

Comments

@wds15
Copy link

wds15 commented Aug 13, 2019

The boost::math::lgamma implementation is about 2-3x slower than the std::lgamma implementation when used with standard doubles.

When turning off the do the propagation from double to long double the boost implementation is comparable in speed to std::lgamma, but still 10-20% slower.

However, when turning off propagation to long double problems with early overflow are the price to pay... see the next issue.

@jzmaddock
Copy link
Collaborator

We need to look at this - when that function was written (and the library started), there was negligible performance difference between double and the old x87 long double, so it was worth using internal promotion for accuracy. However, as you rightly point out, things have moved on and there is now a very significant difference between x64 floating point and x87 code.

It's a one line change to change the default, but it would break all our tests as the expected errors are predicated on internal promotion taking place.

What does everyone else feel about this as a breaking change?

@wds15
Copy link
Author

wds15 commented Aug 13, 2019

If your thought is to use std::lgamma... then that is not really an option. The std::lgamma has issues with threaded programs where the sign of the result is stored in a global signgam variable, which is locked on macOS during the function call leading to terrible performance. You could use the lgamma_r function which is reentrant safe (available by defining _REENTRANT before including cmath)... but this is not a C++ standard.

(performance issues with threaded programs using std::lgamma made me investigate all this)

@jzmaddock
Copy link
Collaborator

If your thought is to use std::lgamma

No there's too much variation between platforms IMO.

@NAThompson
Copy link
Collaborator

What does everyone else feel about this as a breaking change?

I think it should be done, and there should be a slow but steady commitment to doing the same with every function in the library. I don't think the breaking change will really affect many people-half ULP accuracy which can be achieved with long double promotion is not an expectation many people have.

@wds15
Copy link
Author

wds15 commented Aug 13, 2019

uh... I misread... you are suggesting to change the default policy to avoid the promotion. Sounds good to me given that functions still work fine.

(FYI, the digamma functions runs about 2x faster)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants