Skip to content

Commit

Permalink
fix recursion-related nvlink warning in RandomGamma
Browse files Browse the repository at this point in the history
  • Loading branch information
atmyers committed Feb 5, 2025
1 parent 69f1ac8 commit 6d7b889
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Src/Base/AMReX_Random.H
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ namespace amrex
*/
Real RandomGamma (Real alpha, Real beta);

template <int depth = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
Real RandomGamma (Real alpha, Real beta, RandomEngine const& random_engine)
{
Expand All @@ -141,8 +142,12 @@ namespace amrex
AMREX_IF_ON_DEVICE((
if (alpha < 1)
{
Real u = amrex::Random(random_engine);
return RandomGamma(1.0_rt + alpha, beta, random_engine) * std::pow(u, 1.0_rt / alpha);
if constexpr (depth == 0)
{
// note that alpha is assumed to be > 0, so this function will recurse at most once.
Real u = amrex::Random(random_engine);
return RandomGamma<1>(1.0_rt + alpha, beta, random_engine) * std::pow(u, 1.0_rt / alpha);
}
}

{
Expand Down

0 comments on commit 6d7b889

Please sign in to comment.