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

Clean up BeamRelevant with TypeMultiplier #4798

Merged

Conversation

n01r
Copy link
Member

@n01r n01r commented Mar 22, 2024

The BeamRelevant reduced diagnostics had a lot of code where amrex::ReduceOps were constructed from lists of types. This PR cleans it up with the TypeMultiplier utility that makes it more legible.

Credit goes to @AlexanderSinn's work in Hi-PACE/hipace#1052 and AMReX-Codes/amrex#3718.

The BeamRelevant reduced diagnostics had a lot of code where `amrex::ReduceOps`
were constructed from lists of types. It is hard to see immediately how many
types are in that list. The `TypeMultiplier` utility can reduce this to make
it more legible and this was done here.
The variables `num_red_ops_*` are used for the TypeMultiplier and also for
the length of the output vectors for the reduced diagnostics.
This commit changes their type from `const int` to `constexpr size_t` because
this is more appropriate for a vector length, and with constexpr we indicate
that the value is constant and can be evaluated at compile time already.
@ax3l ax3l added cleaning Clean code, improve readability component: diagnostics all types of outputs labels Mar 25, 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.

Very nice :)

And maybe as a follow-up, we can make this a one-time pass reduction :)

@ax3l ax3l merged commit 91f3ff1 into ECP-WarpX:development Mar 25, 2024
45 checks passed
@ax3l ax3l self-assigned this Mar 25, 2024
* ux_mean, uy_mean, uz_mean, gm_mean
*/
amrex::constexpr_for<0, num_red_ops_1> ([&](auto i) {
values_per_rank_1st[i] = amrex::get<i>(r1);
Copy link
Member

@ax3l ax3l Mar 25, 2024

Choose a reason for hiding this comment

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

For some reason, @AlexanderSinn uses this syntax in HiPACE++:

Suggested change
values_per_rank_1st[i] = amrex::get<i>(r1);
values_per_rank_1st[i.value] = amrex::get<i.value>(r1);

* charge
*/
amrex::constexpr_for<0, num_red_ops_2> ([&](auto i) {
values_per_rank_2nd[i] = amrex::get<i>(r2);
Copy link
Member

Choose a reason for hiding this comment

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

see above

@n01r n01r deleted the topic-useTypeMultiplierInReducedDiags branch March 27, 2024 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleaning Clean code, improve readability component: diagnostics all types of outputs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants