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
BarycentricPolynomial::value() optimizations - get rid of pow
#14117
Comments
Hello. I would like to try to implement this, however I don't understand the problem completely. If the goal is to eliminate std::pow, would it be enough to use a for loop? As for a Horner-like implementation, it would be necessary to have a Horner representation of the polynomial. This could be computed at the beginning, when the polynomial is instantiated, is that a correct approach? Thank you, and apologies for the dumb questions, I am only stating to get familiar with the project. |
Glad to hear you're interested!
That might not be the optimal solution since the loop bounds won't be known at compile-time. Another possibility would be to use some kind of switch statement on the exponent and then call the correct version of
I have no idea. I've looked in the past and I don't know what the optimal way to evaluate these kinds of multivariate polynomials is. Something like Horner might be excessively difficult since there are multiple independent variables. I don't think either of those are dumb questions. If this fix was obvious someone else probably would have done it. |
I think the underlying reason why A separate optimization is probably that we compute powers of |
In this case could we not make our own run-time pow(double,int) implementation that is specialized for integers? That's relatively easy to code and would give us significant benefits. I think there is a reason why this is not in the standard, but I remember benchmark a simple case where calculating a*a vs std::pow(a,2.) led to a 50-70x different in the runtime. |
Yes, that's why we already have #13321 :-) |
I even commented on this issue last year... Damn... |
You mean something else than |
Well question is do we need something else than Utilities::pow and Utilities::fixed_power. Both should be able to do the trick no? Fixed at compile time and utilities::pow at run time |
Yes, |
We currently do this:
dealii/include/deal.II/base/polynomials_barycentric.h
Lines 682 to 690 in 5559d13
Notice
std::pow
. Since the power is not known at compile time, the code steps into the very slowpow
function. I believe there is some equivalent to Horner that applies powers by multiplication one at a time, probably also without unrolling the indices inindex_to_indices
, to avoid this bottleneck.Found while looking at the simplex benchmark mentioned in #14068.
The text was updated successfully, but these errors were encountered: