Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Aug 1, 2023
1 parent ef636cd commit 0138481
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Checks: >
modernize-*,
-modernize-avoid-c-arrays,
-modernize-macro-to-enum,
-modernize-return-braced-init-list,
-modernize-use-trailing-return-type,
performance-*,
portability-*,
Expand All @@ -36,6 +37,7 @@ Checks: >
-readability-function-size,
-readability-identifier-length,
-readability-implicit-bool-conversion,
-readability-isolate-declaration,
-readability-magic-numbers,
-readability-named-parameter,
-readability-simplify-boolean-expr,
Expand Down
6 changes: 3 additions & 3 deletions Src/Base/AMReX_Array.H
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ namespace amrex
template <class T, typename = typename T::FABType>
std::array<T*,AMREX_SPACEDIM> GetArrOfPtrs (std::array<T,AMREX_SPACEDIM>& a) noexcept
{
return {{AMREX_D_DECL(&a[0], &a[1], &a[2])}};
return {{AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
}

template <class T>
Expand All @@ -865,13 +865,13 @@ namespace amrex
template <class T>
std::array<T const*,AMREX_SPACEDIM> GetArrOfConstPtrs (const std::array<T,AMREX_SPACEDIM>& a) noexcept
{
return {{AMREX_D_DECL(&a[0], &a[1], &a[2])}};
return {{AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
}

template <class T>
std::array<T const*,AMREX_SPACEDIM> GetArrOfConstPtrs (const std::array<T*,AMREX_SPACEDIM>& a) noexcept
{
return {{AMREX_D_DECL(a[0], a[1], a[2])}};
return {{AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
}

template <class T>
Expand Down
9 changes: 5 additions & 4 deletions Src/Base/AMReX_GpuComplex.H
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ T abs (const GpuComplex<T>& a_z) noexcept
T y = a_z.imag();

const T s = amrex::max(std::abs(x), std::abs(y));
if (s == T())
return s;
if (s == T()) { return s; }
x /= s;
y /= s;
return s * std::sqrt(x * x + y * y);
Expand Down Expand Up @@ -414,8 +413,9 @@ template <typename T>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
GpuComplex<T> pow (const GpuComplex<T>& a_z, const T& a_y) noexcept
{
if (a_z.imag() == T() && a_z.real() > T())
if (a_z.imag() == T() && a_z.real() > T()) {
return std::pow(a_z.real(), a_y);
}

GpuComplex<T> t = amrex::log(a_z);
return amrex::polar<T>(std::exp(a_y * t.real()), a_y * t.imag());
Expand All @@ -432,8 +432,9 @@ namespace detail
while (a_n >>= 1)
{
a_z *= a_z;
if (a_n % 2)
if (a_n % 2) {
y *= a_z;
}
}

return y;
Expand Down
13 changes: 7 additions & 6 deletions Src/Base/AMReX_Math.H
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,20 @@ template <int Power, typename T,
AMREX_FORCE_INLINE
constexpr T powi (T x) noexcept
{
if constexpr (Power < 0)
if constexpr (Power < 0) {
return T(1)/powi<-Power>(x);
else if constexpr (Power == 0)
} else if constexpr (Power == 0) {
//note: 0^0 is implementation-defined, but most compilers return 1
return T(1);
else if constexpr (Power == 1)
} else if constexpr (Power == 1) {
return x;
else if constexpr (Power == 2)
} else if constexpr (Power == 2) {
return x*x;
else if constexpr (Power%2 == 0)
} else if constexpr (Power%2 == 0) {
return powi<2>(powi<Power/2>(x));
else
} else {
return x*powi<Power-1>(x);
}
}

}
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_ParallelDescriptor.H
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ while ( false )
{
int rb, re;
{
if (rit < 0) rit = ParallelDescriptor::MyRankInTeam();
if (nworkers == 0) nworkers = ParallelDescriptor::TeamSize();
if (rit < 0) { rit = ParallelDescriptor::MyRankInTeam(); }
if (nworkers == 0) { nworkers = ParallelDescriptor::TeamSize(); }
BL_ASSERT(rit<nworkers);
if (nworkers == 1) {
rb = begin;
Expand Down

0 comments on commit 0138481

Please sign in to comment.