From 344504c7e175187f218f44bc1c39ce2c3cffbc99 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Thu, 3 Aug 2023 17:59:48 -0700 Subject: [PATCH] add google checks --- .clang-tidy | 4 +- Src/Base/AMReX_DistributionMapping.cpp | 4 +- Src/Base/AMReX_Lazy.cpp | 6 +- Src/Base/AMReX_ParallelDescriptor.H | 3 +- Src/Base/AMReX_ParallelDescriptor.cpp | 6 +- .../Source/Src_K/compute_flux_2D_K.H | 5 +- .../Source/Src_K/compute_flux_3D_K.H | 163 +++++++++--------- .../Exec/SingleVortex/Prob_Parm.H | 2 - .../Exec/UniformVelocity/Prob_Parm.H | 3 - Tests/EB/CNS/Source/CNS.H | 1 - 10 files changed, 94 insertions(+), 103 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 565062895ec..4d954067db6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,7 +10,6 @@ Checks: > clang-diagnostic-*, cppcoreguidelines-*, -cppcoreguidelines-avoid-c-arrays, - -cppcoreguidelines-avoid-goto, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-init-variables, @@ -20,6 +19,9 @@ Checks: > -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-*, + google-build-explicit-make-pair, + google-build-namespaces, + google-global-names-in-headers, misc-*, -misc-const-correctness, -misc-non-private-member-variables-in-classes, diff --git a/Src/Base/AMReX_DistributionMapping.cpp b/Src/Base/AMReX_DistributionMapping.cpp index ee0c32c26fa..9350f9203d1 100644 --- a/Src/Base/AMReX_DistributionMapping.cpp +++ b/Src/Base/AMReX_DistributionMapping.cpp @@ -692,7 +692,7 @@ top: ; max_weight = static_cast(bl_top->weight()); efficiency = sum_weight / (static_cast(nprocs)*max_weight); - goto top; + goto top; // NOLINT } } } @@ -1017,7 +1017,7 @@ DistributionMapping::KnapSackProcessorMap (const DistributionMapping& olddm, max_weight = static_cast(bl_top->weight()); new_efficiency = avg_weight / max_weight; - goto top; + goto top; // NOLINT } } } diff --git a/Src/Base/AMReX_Lazy.cpp b/Src/Base/AMReX_Lazy.cpp index 7e4d6e5bd7a..9f2fae500bd 100644 --- a/Src/Base/AMReX_Lazy.cpp +++ b/Src/Base/AMReX_Lazy.cpp @@ -9,8 +9,9 @@ namespace amrex::Lazy #ifdef BL_USE_MPI reduction_queue.push_back(f); const int max_queue_size = 64; - if (reduction_queue.size() >= max_queue_size) + if (reduction_queue.size() >= max_queue_size) { EvalReduction(); + } #else f(); #endif @@ -22,8 +23,9 @@ namespace amrex::Lazy static int count = 0; ++count; if (count == 1) { - for (auto&& f : reduction_queue) + for (auto&& f : reduction_queue) { f(); + } reduction_queue.clear(); count = 0; } diff --git a/Src/Base/AMReX_ParallelDescriptor.H b/Src/Base/AMReX_ParallelDescriptor.H index 3bf72ca3852..46ca0f99fc3 100644 --- a/Src/Base/AMReX_ParallelDescriptor.H +++ b/Src/Base/AMReX_ParallelDescriptor.H @@ -898,8 +898,7 @@ ParallelDescriptor::Bcast (T* t, #ifdef BL_LAZY int r; MPI_Comm_compare(comm, Communicator(), &r); - if (r == MPI_IDENT) - Lazy::EvalReduction(); + if (r == MPI_IDENT) { Lazy::EvalReduction(); } #endif BL_ASSERT(n < static_cast(std::numeric_limits::max())); diff --git a/Src/Base/AMReX_ParallelDescriptor.cpp b/Src/Base/AMReX_ParallelDescriptor.cpp index 764bdfd243d..4e959504158 100644 --- a/Src/Base/AMReX_ParallelDescriptor.cpp +++ b/Src/Base/AMReX_ParallelDescriptor.cpp @@ -471,8 +471,7 @@ Barrier (const MPI_Comm &comm, const std::string &message) #ifdef BL_LAZY int r; MPI_Comm_compare(comm, Communicator(), &r); - if (r == MPI_IDENT) - Lazy::EvalReduction(); + if (r == MPI_IDENT) { Lazy::EvalReduction(); } #endif BL_PROFILE_S("ParallelDescriptor::Barrier(comm)"); @@ -1130,8 +1129,7 @@ Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) #ifdef BL_LAZY int r; MPI_Comm_compare(comm, Communicator(), &r); - if (r == MPI_IDENT) - Lazy::EvalReduction(); + if (r == MPI_IDENT) { Lazy::EvalReduction(); } #endif BL_PROFILE_S("ParallelDescriptor::Bcast(viMiM)"); diff --git a/Tests/Amr/Advection_AmrCore/Source/Src_K/compute_flux_2D_K.H b/Tests/Amr/Advection_AmrCore/Source/Src_K/compute_flux_2D_K.H index 57d6a13aa82..51bda7f35ed 100644 --- a/Tests/Amr/Advection_AmrCore/Source/Src_K/compute_flux_2D_K.H +++ b/Tests/Amr/Advection_AmrCore/Source/Src_K/compute_flux_2D_K.H @@ -1,9 +1,8 @@ #ifndef compute_flux_2d_H_ #define compute_flux_2d_H_ -#include -#include -#include +#include +#include AMREX_GPU_DEVICE AMREX_FORCE_INLINE diff --git a/Tests/Amr/Advection_AmrCore/Source/Src_K/compute_flux_3D_K.H b/Tests/Amr/Advection_AmrCore/Source/Src_K/compute_flux_3D_K.H index d80666e1b2e..10caf821788 100644 --- a/Tests/Amr/Advection_AmrCore/Source/Src_K/compute_flux_3D_K.H +++ b/Tests/Amr/Advection_AmrCore/Source/Src_K/compute_flux_3D_K.H @@ -1,20 +1,17 @@ #ifndef compute_flux_3d_H_ #define compute_flux_3d_H_ -#include -#include -#include - -using namespace amrex; +#include +#include AMREX_GPU_DEVICE AMREX_FORCE_INLINE void flux_x(int i, int j, int k, - Array4 const& px, - Array4 const& phi, - Array4 const& vx, - Array4 const& slope, - Real dtdx) + amrex::Array4 const& px, + amrex::Array4 const& phi, + amrex::Array4 const& vx, + amrex::Array4 const& slope, + amrex::Real dtdx) { px(i,j,k) = ( (vx(i,j,k) < 0) ? phi(i ,j,k) - slope(i ,j,k)*(0.5 + 0.5*dtdx*vx(i,j,k)) : @@ -24,11 +21,11 @@ void flux_x(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void flux_y(int i, int j, int k, - Array4 const& py, - Array4 const& phi, - Array4 const& vy, - Array4 const& slope, - Real dtdy) + amrex::Array4 const& py, + amrex::Array4 const& phi, + amrex::Array4 const& vy, + amrex::Array4 const& slope, + amrex::Real dtdy) { py(i,j,k) = ( (vy(i,j,k) < 0) ? phi(i,j ,k) - slope(i,j ,k)*(0.5 + 0.5*dtdy*vy(i,j,k)) : @@ -38,11 +35,11 @@ void flux_y(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void flux_z(int i, int j, int k, - Array4 const& pz, - Array4 const& phi, - Array4 const& vz, - Array4 const& slope, - Real dtdz) + amrex::Array4 const& pz, + amrex::Array4 const& phi, + amrex::Array4 const& vz, + amrex::Array4 const& slope, + amrex::Real dtdz) { pz(i,j,k) = ( (vz(i,j,k) < 0) ? phi(i,j,k ) - slope(i,j,k )*(0.5 + 0.5*dtdz*vz(i,j,k)) : @@ -52,12 +49,12 @@ void flux_z(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void flux_xy(int i, int j, int k, - Array4 const& pxy, - Array4 const& vx, - Array4 const& vy, - Array4 const& px, - Array4 const& py, - Real dtdy) + amrex::Array4 const& pxy, + amrex::Array4 const& vx, + amrex::Array4 const& vy, + amrex::Array4 const& px, + amrex::Array4 const& py, + amrex::Real dtdy) { pxy(i,j,k) = ( (vx(i,j,k) < 0) ? px(i,j,k) - dtdy/3.0 * ( 0.5*(vy(i, j+1,k) + vy(i ,j,k)) * (py(i ,j+1,k) - py(i ,j,k))) : @@ -67,12 +64,12 @@ void flux_xy(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void flux_xz(int i, int j, int k, - Array4 const& pxz, - Array4 const& vx, - Array4 const& vz, - Array4 const& px, - Array4 const& pz, - Real dtdz) + amrex::Array4 const& pxz, + amrex::Array4 const& vx, + amrex::Array4 const& vz, + amrex::Array4 const& px, + amrex::Array4 const& pz, + amrex::Real dtdz) { pxz(i,j,k) = ( (vx(i,j,k) < 0) ? px(i,j,k) - dtdz/3.0 * ( 0.5*(vz(i, j,k+1) + vz(i ,j,k)) * (pz(i ,j,k+1) - pz(i ,j,k))) : @@ -82,12 +79,12 @@ void flux_xz(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void flux_yx(int i, int j, int k, - Array4 const& pyx, - Array4 const& vx, - Array4 const& vy, - Array4 const& px, - Array4 const& py, - Real dtdx) + amrex::Array4 const& pyx, + amrex::Array4 const& vx, + amrex::Array4 const& vy, + amrex::Array4 const& px, + amrex::Array4 const& py, + amrex::Real dtdx) { pyx(i,j,k) = ( (vy(i,j,k) < 0) ? py(i,j,k) - dtdx/3.0 * ( 0.5*(vx(i+1,j ,k) + vx(i,j ,k)) * (px(i+1,j ,k) - px(i,j ,k))) : @@ -97,12 +94,12 @@ void flux_yx(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void flux_yz(int i, int j, int k, - Array4 const& pyz, - Array4 const& vy, - Array4 const& vz, - Array4 const& py, - Array4 const& pz, - Real dtdz) + amrex::Array4 const& pyz, + amrex::Array4 const& vy, + amrex::Array4 const& vz, + amrex::Array4 const& py, + amrex::Array4 const& pz, + amrex::Real dtdz) { pyz(i,j,k) = ( (vy(i,j,k) < 0) ? py(i,j,k) - dtdz/3.0 * ( 0.5*(vz(i, j,k+1) + vz(i,j ,k)) * (pz(i,j ,k+1) - pz(i,j ,k))) : @@ -112,12 +109,12 @@ void flux_yz(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void flux_zx(int i, int j, int k, - Array4 const& pzx, - Array4 const& vx, - Array4 const& vz, - Array4 const& px, - Array4 const& pz, - Real dtdx) + amrex::Array4 const& pzx, + amrex::Array4 const& vx, + amrex::Array4 const& vz, + amrex::Array4 const& px, + amrex::Array4 const& pz, + amrex::Real dtdx) { pzx(i,j,k) = ( (vz(i,j,k) < 0) ? pz(i,j,k) - dtdx/3.0 * ( 0.5*(vx(i+1,j,k ) + vx(i,j,k )) * (px(i+1,j,k ) - px(i,j,k ))) : @@ -127,12 +124,12 @@ void flux_zx(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void flux_zy(int i, int j, int k, - Array4 const& pzy, - Array4 const& vy, - Array4 const& vz, - Array4 const& py, - Array4 const& pz, - Real dtdy) + amrex::Array4 const& pzy, + amrex::Array4 const& vy, + amrex::Array4 const& vz, + amrex::Array4 const& py, + amrex::Array4 const& pz, + amrex::Real dtdy) { pzy(i,j,k) = ( (vz(i,j,k) < 0) ? pz(i,j,k) - dtdy/3.0 * ( 0.5*(vy(i,j+1,k ) + vy(i,j,k )) * (py(i,j+1,k ) - py(i,j,k ))) : @@ -142,16 +139,16 @@ void flux_zy(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void create_flux_x(int i, int j, int k, - Array4 const& fx, - Array4 const& vx, - Array4 const& vy, - Array4 const& vz, - Array4 const& px, - Array4 const& pyz, - Array4 const& pzy, - Real dtdy, Real dtdz) + amrex::Array4 const& fx, + amrex::Array4 const& vx, + amrex::Array4 const& vy, + amrex::Array4 const& vz, + amrex::Array4 const& px, + amrex::Array4 const& pyz, + amrex::Array4 const& pzy, + amrex::Real dtdy, amrex::Real dtdz) { - Real f = ( (vx(i,j,k) < 0) ? + amrex::Real f = ( (vx(i,j,k) < 0) ? px(i,j,k) - 0.5*dtdy * ( 0.5*(vy(i ,j+1,k ) + vy(i ,j,k)) * (pyz(i ,j+1,k )-pyz(i ,j,k))) - 0.5*dtdz * ( 0.5*(vz(i ,j ,k+1) + vz(i ,j,k)) * (pzy(i ,j ,k+1)-pzy(i ,j,k))) : px(i,j,k) - 0.5*dtdy * ( 0.5*(vy(i-1,j+1,k ) + vy(i-1,j,k)) * (pyz(i-1,j+1,k )-pyz(i-1,j,k))) @@ -163,16 +160,16 @@ void create_flux_x(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void create_flux_y(int i, int j, int k, - Array4 const& fy, - Array4 const& vx, - Array4 const& vy, - Array4 const& vz, - Array4 const& py, - Array4 const& pxz, - Array4 const& pzx, - Real dtdx, Real dtdz) + amrex::Array4 const& fy, + amrex::Array4 const& vx, + amrex::Array4 const& vy, + amrex::Array4 const& vz, + amrex::Array4 const& py, + amrex::Array4 const& pxz, + amrex::Array4 const& pzx, + amrex::Real dtdx, amrex::Real dtdz) { - Real f = ( (vy(i,j,k) < 0) ? + amrex::Real f = ( (vy(i,j,k) < 0) ? py(i,j,k) - 0.5*dtdx * ( 0.5*(vx(i+1,j ,k ) + vx(i,j ,k)) * (pxz(i+1,j ,k )-pxz(i,j ,k))) - 0.5*dtdz * ( 0.5*(vz(i, j ,k+1) + vz(i,j ,k)) * (pzx(i, j ,k+1)-pzx(i,j ,k))) : py(i,j,k) - 0.5*dtdx * ( 0.5*(vx(i+1,j-1,k ) + vx(i,j-1,k)) * (pxz(i+1,j-1,k )-pxz(i,j-1,k))) @@ -184,16 +181,16 @@ void create_flux_y(int i, int j, int k, AMREX_GPU_DEVICE AMREX_FORCE_INLINE void create_flux_z(int i, int j, int k, - Array4 const& fz, - Array4 const& vx, - Array4 const& vy, - Array4 const& vz, - Array4 const& pz, - Array4 const& pxy, - Array4 const& pyx, - Real dtdx, Real dtdy) + amrex::Array4 const& fz, + amrex::Array4 const& vx, + amrex::Array4 const& vy, + amrex::Array4 const& vz, + amrex::Array4 const& pz, + amrex::Array4 const& pxy, + amrex::Array4 const& pyx, + amrex::Real dtdx, amrex::Real dtdy) { - Real f = ( (vz(i,j,k) < 0) ? + amrex::Real f = ( (vz(i,j,k) < 0) ? pz(i,j,k) - 0.5*dtdx * ( 0.5*(vx(i+1,j ,k ) + vx(i,j,k )) * (pxy(i+1,j ,k )-pxy(i,j,k ))) - 0.5*dtdy * ( 0.5*(vy(i, j+1,k ) + vy(i,j,k )) * (pyx(i, j+1,k )-pyx(i,j,k ))) : pz(i,j,k) - 0.5*dtdx * ( 0.5*(vx(i+1,j ,k-1) + vx(i,j,k-1)) * (pxy(i+1,j ,k-1)-pxy(i,j,k-1))) diff --git a/Tests/Amr/Advection_AmrLevel/Exec/SingleVortex/Prob_Parm.H b/Tests/Amr/Advection_AmrLevel/Exec/SingleVortex/Prob_Parm.H index a562656c6e4..8594d8e76b8 100644 --- a/Tests/Amr/Advection_AmrLevel/Exec/SingleVortex/Prob_Parm.H +++ b/Tests/Amr/Advection_AmrLevel/Exec/SingleVortex/Prob_Parm.H @@ -3,8 +3,6 @@ #include -using namespace amrex::literals; - // Define the struct to contain problem-specific variables here. // For this case, since we don't need any, the struct is empty. struct ProbParm {}; diff --git a/Tests/Amr/Advection_AmrLevel/Exec/UniformVelocity/Prob_Parm.H b/Tests/Amr/Advection_AmrLevel/Exec/UniformVelocity/Prob_Parm.H index e285ddaa8f4..bbb0b87d0f9 100644 --- a/Tests/Amr/Advection_AmrLevel/Exec/UniformVelocity/Prob_Parm.H +++ b/Tests/Amr/Advection_AmrLevel/Exec/UniformVelocity/Prob_Parm.H @@ -2,9 +2,6 @@ #define PROB_PARM_H_ #include -#include - -using namespace amrex::literals; // Define the struct to contain problem-specific variables here. struct ProbParm diff --git a/Tests/EB/CNS/Source/CNS.H b/Tests/EB/CNS/Source/CNS.H index af216738f58..feab3469d98 100644 --- a/Tests/EB/CNS/Source/CNS.H +++ b/Tests/EB/CNS/Source/CNS.H @@ -5,7 +5,6 @@ #include #include -using namespace amrex; class CNS : public amrex::AmrLevel