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

Replace std::pow where possible #6055

Merged
merged 3 commits into from
Oct 7, 2024
Merged

Conversation

gassmoeller
Copy link
Member

I saw by chance that we still have a number of places in the code where we do std::pow(x,2). This is pretty slow (similar to the cost of allocating a std::vector), and although most of the occurrences are not performance critical, at least a few are.
This PR is a bit of regular expression substitutions magic and a bit of manual substitutions. I think I replaced all cases of std::pow with:

  • Utilities::fixed_power if the exponent is integer and known at compile time
  • Utilities::pow if the exponent is integer and known at run time

@gassmoeller
Copy link
Member Author

Ah, it looks like Utilities::pow only supports double as a base after deal.II 9.5 thus the tester fails. Will get back to this.

@gassmoeller
Copy link
Member Author

It turns out Utilities::fixed_power, Utilities::pow and std::pow return (marginally) different results due to floating point accuracy and the used algorithms. I had to update a few test results, although all of them only cause small changes in iteration counts or final residuals. I am pretty certain this is not a problem for practical models. @tjhei are you still ok with the change?

@tjhei tjhei merged commit c8475b3 into geodynamics:main Oct 7, 2024
8 checks passed
@gassmoeller gassmoeller deleted the avoid_pow branch October 8, 2024 08:32
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

Successfully merging this pull request may close these issues.

2 participants