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

[WIP] Replace sin(theta), cos(theta) with amrex::Math::sincos(theta) when appropriate #4587

Closed
wants to merge 20 commits into from

Conversation

lucafedeli88
Copy link
Member

This PR mirrors what was done for ImpactX in ECP-WarpX/impactx#493 by @ax3l

@lucafedeli88 lucafedeli88 added Performance optimization cleaning Clean code, improve readability labels Jan 8, 2024
@lucafedeli88 lucafedeli88 changed the title [WIP] Replace sin(theta), cos(theta) with amrex::Math::sincos(theta) when appropriate Replace sin(theta), cos(theta) with amrex::Math::sincos(theta) when appropriate Jan 8, 2024
@ax3l ax3l self-requested a review January 8, 2024 16:10
@ax3l ax3l self-assigned this Jan 8, 2024
ax3l
ax3l previously approved these changes Jan 8, 2024
Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM! 👍

Note that as linked in the other PR, and tested when I added the function to AMReX, most optimizing compilers should find this automatically. But this way it is done also in all optimization levels, and cleaner if the results are needed multiple times.

@ax3l ax3l self-requested a review January 8, 2024 16:22
@ax3l ax3l dismissed their stale review January 8, 2024 16:22

see qs

@ax3l
Copy link
Member

ax3l commented Feb 1, 2024

Restarting CI, all Azure tests failed...?

@ax3l ax3l closed this Feb 1, 2024
@ax3l ax3l reopened this Feb 1, 2024
@ax3l
Copy link
Member

ax3l commented Feb 20, 2024

CI still not happy, huh. Can you please rebase?

Copy link
Member

@RevathiJambunathan RevathiJambunathan left a comment

Choose a reason for hiding this comment

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

cool! Thanks for this PR, @lucafedeli88

@ax3l
Copy link
Member

ax3l commented Mar 15, 2024

Looks like CI is not happy.

Can you rebase @lucafedeli88 ?

@ax3l
Copy link
Member

ax3l commented Apr 1, 2024

There seem to be percent-level changes for momenta in checksum files 🤔

@lucafedeli88 lucafedeli88 changed the title Replace sin(theta), cos(theta) with amrex::Math::sincos(theta) when appropriate [WIP] Replace sin(theta), cos(theta) with amrex::Math::sincos(theta) when appropriate Apr 2, 2024
@ax3l
Copy link
Member

ax3l commented Apr 25, 2024

@lucafedeli88 I think there might be a bug here if the results change.

Potentially, one could systematically pick one test and bisect which file change introduces the differences?

@ax3l
Copy link
Member

ax3l commented Aug 12, 2024

@lucafedeli88 can you rebase this?
Potentially, it is worth submitting this piece wise if it is hard to spot which line changes cause the checksum changes.

@lucafedeli88
Copy link
Member Author

@lucafedeli88 can you rebase this? Potentially, it is worth submitting this piece wise if it is hard to spot which line changes cause the checksum changes.

@ax3l , I've merged the newest version of WarpX into this branch. I'll try to understand which substitution is causing the bug.

@lucafedeli88
Copy link
Member Author

@lucafedeli88 can you rebase this? Potentially, it is worth submitting this piece wise if it is hard to spot which line changes cause the checksum changes.

@ax3l , I've merged the newest version of WarpX into this branch. I'll try to understand which substitution is causing the bug.

I am testing the hypothesis that the small discrepancies come from using sincospi instead of sincos(pi*arg). The former should be more precise (sincospi does not use pi internally), while sincos(pi*arg) uses pi in single or double precision. This could explain discrepancies at roughly machine precision. In case this hypothesis turns out to be correct, I think that we should switch to sincospi, since it is more precise and more performant.

@lucafedeli88
Copy link
Member Author

Actually not all the discrepancies are small, so maybe there's something else.

@lucafedeli88
Copy link
Member Author

Implementing this feature without introducing discrepancies seems to be very difficult, and I am not sure that I will have time to work on that on the foreseeable future. Since the priority of this feature is very low, I will close the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleaning Clean code, improve readability Performance optimization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants