-
Notifications
You must be signed in to change notification settings - Fork 196
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
Clang tidy CI test: add several clang-analyzer-* checks to clang tidy CI test #4684
Clang tidy CI test: add several clang-analyzer-* checks to clang tidy CI test #4684
Conversation
@@ -54,6 +54,12 @@ JFunctor::operator() (amrex::MultiFab& mf_dst, int dcomp, const int /*i_buffer*/ | |||
mypc.DepositCurrent(current_fp_temp, warpx.getdt(m_lev), 0.0); | |||
} | |||
|
|||
InterpolateMFForDiag(mf_dst, *m_mf_src, dcomp, warpx.DistributionMap(m_lev), | |||
m_convertRZmodes2cartesian); | |||
if (m_mf_src != nullptr){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function get_pointer_current_fp
should throw instead of having to check the return value in user code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to address this issue, would it be okay to restructure this part of WarpX.H
[[nodiscard]] amrex::MultiFab * get_pointer_Efield_aux (int lev, int direction) const { return Efield_aux[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_Bfield_aux (int lev, int direction) const { return Bfield_aux[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_Efield_fp (int lev, int direction) const { return Efield_fp[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_Bfield_fp (int lev, int direction) const { return Bfield_fp[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_current_fp (int lev, int direction) const { return current_fp[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_current_fp_nodal (int lev, int direction) const { return current_fp_nodal[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_rho_fp (int lev) const { return rho_fp[lev].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_F_fp (int lev) const { return F_fp[lev].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_G_fp (int lev) const { return G_fp[lev].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_phi_fp (int lev) const { return phi_fp[lev].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_vector_potential_fp (int lev, int direction) const { return vector_potential_fp_nodal[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_Efield_cp (int lev, int direction) const { return Efield_cp[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_Bfield_cp (int lev, int direction) const { return Bfield_cp[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_current_cp (int lev, int direction) const { return current_cp[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_rho_cp (int lev) const { return rho_cp[lev].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_F_cp (int lev) const { return F_cp[lev].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_G_cp (int lev) const { return G_cp[lev].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_edge_lengths (int lev, int direction) const { return m_edge_lengths[lev][direction].get(); }
[[nodiscard]] amrex::MultiFab * get_pointer_face_areas (int lev, int direction) const { return m_face_areas[lev][direction].get(); }
with something like:
enum class FieldType
{
Efield_aux,
Bfield_aux
// ...
};
template <FieldType Type>
[[nodiscard]] amrex::MultiFab * get_pointer (int lev, int direction)
{
if (auto* ptr = m_multifabs[lev][direction][Type].get(); ptr != nullptr)
return ptr;
else
WARPX_ABORT_WITH_MESSAGE("...");
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, maybe we can call it get_mf_pointer
or get_field_pointer
?
Not sure the FieldType
must be a template - this is not used in hot loops so it can be a regular argument, no?
@@ -1202,7 +1202,7 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int | |||
const bool rz_random_theta = m_rz_random_theta; | |||
#endif | |||
amrex::ParallelForRNG(overlap_box, | |||
[=] AMREX_GPU_DEVICE (int i, int j, int k, amrex::RandomEngine const& engine) noexcept | |||
[=] AMREX_GPU_DEVICE (int i, int j, int k, amrex::RandomEngine const& engine) noexcept //NOLINT(clang-analyzer-optin.performance.Padding) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this belong in AMReX or at least an AMReX issue instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it is something that can happen with any lambda function (e.g., you can have a look here: https://godbolt.org/z/fK6PhvdsG). I suppose it depends on the order in which the variables captured by the lambda function are actually used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's open this as an issue in AMReX, could be interesting for @WeiqunZhang.
Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp
Outdated
Show resolved
Hide resolved
Maybe adding a throw to the end of the assert function could help.
…On Mon, Feb 12, 2024, 6:57 PM Luca Fedeli ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp
<#4684 (comment)>:
> @@ -60,13 +60,20 @@ BackTransformFunctor::operator ()(amrex::MultiFab& mf_dst, int /*dcomp*/, const
const int scomp = 0;
// Generate slice of the cell-centered multifab containing boosted-frame field-data
// at current z-boost location for the ith buffer
- slice = amrex::get_slice_data(moving_window_dir,
- m_current_z_boost[i_buffer],
- *m_mf_src,
- geom,
- scomp,
- m_mf_src->nComp(),
- interpolate);
+ if (m_mf_src != nullptr){
Same as above. Unfortunately using WARPX_ALWAYS_ASSERT_WITH_MESSAGE does
not work here....
—
Reply to this email directly, view it on GitHub
<#4684 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB37TYOPCD5XQGZH2AODC73YTLJBPAVCNFSM6AAAAABDBDO5BWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQNZWG44TGNRTGM>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
Very indirectly there is an assert: |
I don't think it will help, especially when MPI is on, we call MPI_Abort eventually. |
for more information, see https://pre-commit.ci
@lucafedeli88 when you rebase against the latest development, your new AMReX assume should be available now. There is also a small merge conflict right now. |
@ax3l , I should have fixed the merge conflict |
ping, @ax3l :-) ! |
|
||
enum struct PatchType : int | ||
{ | ||
fine, | ||
coarse | ||
}; | ||
|
||
enum struct FieldType : int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok for now, but we should make it a runtime construct so we can add more multifabs later on at runtime and also easily name them.
This PR adds several
clang-analyzer-*
checks toclang-tidy
CI test:-
clang-analyzer-optin.mpi.MPI-Checkerclang-analyzer-optin.performance.PaddingThe following checks are explicitly excluded (
osx
checks are not relevant for WarpX):Also this check is excluded, since it generates a non-relevant warning:
Finally, padding check is excluded because it generates warning for lambda functions, which require a verbose
NOLINT
to be silenced:Notable changes
Use new
AMREX_ASSUME
feature to silence warningsIn WarpX we can enforce a given condition by using
WARPX_ALWAYS_ASSERT_WITH_MESSAGE
. However, the compiler can't see throughWARPX_ALWAYS_ASSERT_WITH_MESSAGE
andclang-tidy
may therefore generate warnings for scenarios that can't actually take place.A possible solution is to use a newly introduced feature in AMReX:
AMREX_ASSUME
:After
AMREX_ASSUME(m_mf_src != nullptr);
most compilers (includinggcc
,clang
, andnvcc
) should be able to assume thatm_mf_src != nullptr
.Using this feature requires to update the AMReX version.
Change getters of fields and field pointers in WarpX
As discussed with @ax3l (see #4684 (comment)), this PR also changes the getters of the fields and field pointers in the WarpX class:
getFieldPointerUnchecked
does not check if the requested pointer is!= nullptr
. This function is conceived to be used internally by the other getters, which check if the pointer is valid and, in case it isn't, they abort.