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

[Core] Optimizing code generated by sympy fe utilities #12872

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

ddiezrod
Copy link
Contributor

While we were doing the profile of our symbolic element for filling simulation (two fluid navier stokes) we found that using pow instead of just multiplying the terms was really bad for performance (I mean writing pow(x,2) instead of x*x )

It seems they are aware of this problem in sympy so that is why they added a function called "create_expand_pow_optimization" exactly to do this. We've been using in our side for a couple of years, but I'd like to use the code from the core now, so that is why Im bringing this optimization to sympy fe utilities now, so we all take advantage of this.

@ddiezrod ddiezrod self-assigned this Nov 26, 2024
@ddiezrod ddiezrod requested a review from a team as a code owner November 26, 2024 14:35
@loumalouomega
Copy link
Member

While we were doing the profile of our symbolic element for filling simulation (two fluid navier stokes) we found that using pow instead of just multiplying the terms was really bad for performance (I mean writing pow(x,2) instead of x*x )

It seems they are aware of this problem in sympy so that is why they added a function called "create_expand_pow_optimization" exactly to do this. We've been using in our side for a couple of years, but I'd like to use the code from the core now, so that is why Im bringing this optimization to sympy fe utilities now, so we all take advantage of this.

Oh, it can be done automatically. I did my own expansion at the time (I was aware of this)

Copy link
Member

@loumalouomega loumalouomega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@rubenzorrilla
Copy link
Member

Just for my curiosity, what you mean by really bad for performance?

@uxuech FYI.

@ddiezrod
Copy link
Contributor Author

@rubenzorrilla it depends on the compiler, but it seems that in most cases, compilers use a different algorithm to compute pow(x,2) and x*x, being "pow" much slower as it needs to be more generic, so if you have a code that calls this function many times you can really feel the impact.

I cant tell you exactly how much impact this has as we did several years ago, I think it was @jrubiogonzalez who found this solution.

@loumalouomega
Copy link
Member

@rubenzorrilla it depends on the compiler, but it seems that in most cases, compilers use a different algorithm to compute pow(x,2) and x*x, being "pow" much slower as it needs to be more generic, so if you have a code that calls this function many times you can really feel the impact.

I cant tell you exactly how much impact this has as we did several years ago, I think it was @jrubiogonzalez who found this solution.

Good compilers decompose pow of integer values, but unfortunately compilers sometimes are not that smart. Specially for the compiler of very big company that owns this platform.

@ddiezrod ddiezrod enabled auto-merge (squash) November 26, 2024 16:05
@matekelemen
Copy link
Contributor

Good compilers decompose pow of integer values, but unfortunately compilers sometimes are not that smart. Specially for the compiler of very big company that owns this platform.

exactly

@matekelemen
Copy link
Contributor

matekelemen commented Nov 26, 2024

I guess that very big company spends its time and money making its compiler worse.

@ddiezrod ddiezrod merged commit 8ef9268 into master Nov 26, 2024
10 of 11 checks passed
@ddiezrod ddiezrod deleted the core/optimizing-symbolic-generated-elements branch November 26, 2024 18:24
@loumalouomega
Copy link
Member

I guess that very big company spends its time and money making its compiler worse.

programmerhumor-io-backend-memes-programming-memes-aebae3b5cafff5a

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

Successfully merging this pull request may close these issues.

4 participants