Skip to content

Commit

Permalink
Disable optimization for computeRoundOffDomain
Browse files Browse the repository at this point in the history
It appears dangerous to have optimization on when compiling the
Geometry::computeRoundOffDomain function. In the past, we had to change the
source code for Intel compilers. Recently, there appears to be issues with
ROCm 6.0 when optimization is on. Thus, we disable optimization for that
function.

Inline functions outsideRoundoffDomain and insideRoundoffDomain.
  • Loading branch information
WeiqunZhang committed Dec 29, 2023
1 parent 75571e2 commit 9b0d63e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
18 changes: 16 additions & 2 deletions Src/Base/AMReX_Geometry.H
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,27 @@ public:
* are sure to be mapped to cells inside the Domain() box. Note that
* the same need not be true for all points inside ProbDomain().
*/
[[nodiscard]] bool outsideRoundoffDomain (AMREX_D_DECL(ParticleReal x, ParticleReal y, ParticleReal z)) const;
[[nodiscard]] bool outsideRoundoffDomain (AMREX_D_DECL(ParticleReal x, ParticleReal y, ParticleReal z)) const
{
bool outside = AMREX_D_TERM(x < roundoff_lo[0]
|| x > roundoff_hi[0],
|| y < roundoff_lo[1]
|| y > roundoff_hi[1],
|| z < roundoff_lo[2]
|| z > roundoff_hi[2]);
return outside;
}

/**
* \brief Returns true if a point is inside the roundoff domain.
* All particles with positions inside the roundoff domain
* are sure to be mapped to cells inside the Domain() box. Note that
* the same need not be true for all points inside ProbDomain().
*/
[[nodiscard]] bool insideRoundoffDomain (AMREX_D_DECL(ParticleReal x, ParticleReal y, ParticleReal z)) const;
[[nodiscard]] bool insideRoundoffDomain (AMREX_D_DECL(ParticleReal x, ParticleReal y, ParticleReal z)) const
{
return !outsideRoundoffDomain(AMREX_D_DECL(x, y, z));
}

/**
* \brief Compute the roundoff domain. Public because it contains an
Expand All @@ -426,6 +438,8 @@ public:

private:
void read_params ();
void computeCellSize ();
void assertRoundoffDomain () const;

// is_periodic and RealBox used to be static
bool is_periodic[AMREX_SPACEDIM] = {AMREX_D_DECL(false,false,false)};
Expand Down
47 changes: 28 additions & 19 deletions Src/Base/AMReX_Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,37 @@ Geometry::growPeriodicDomain (int ngrow) const noexcept
return growPeriodicDomain(IntVect(ngrow));
}

void
Geometry::computeRoundoffDomain ()
void Geometry::computeCellSize ()
{
for (int k = 0; k < AMREX_SPACEDIM; k++)
{
offset[k] = prob_domain.lo(k);
dx[k] = prob_domain.length(k)/(Real(domain.length(k)));
inv_dx[k] = 1.0_rt/dx[k];
}
}

void Geometry::assertRoundoffDomain () const
{
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
auto const idxlo = int(std::floor((roundoff_lo[idim]-ProbLo(idim)) * InvCellSize(idim)));
auto const idxhi = int(std::floor((roundoff_hi[idim]-ProbLo(idim)) * InvCellSize(idim)));
AMREX_ALWAYS_ASSERT(idxlo == 0 && idxhi == domain.length(idim)-1);
}
}

#if defined(__clang__)
[[clang::optnone]]
#elif defined(__GNUC__)
__attribute__ ((optimize(0)))
#elif defined(_WIN32)
#define AMREX_WIN32_OPTIMIZE_OFF
#pragma optimize("", off)
#endif
void
Geometry::computeRoundoffDomain ()
{
computeCellSize();

constexpr int maxiters = 200;

Expand Down Expand Up @@ -684,24 +706,11 @@ Geometry::computeRoundoffDomain ()
&& iters < maxiters);
}
}
}

bool
Geometry::outsideRoundoffDomain (AMREX_D_DECL(ParticleReal x, ParticleReal y, ParticleReal z)) const
{
bool outside = AMREX_D_TERM(x < roundoff_lo[0]
|| x > roundoff_hi[0],
|| y < roundoff_lo[1]
|| y > roundoff_hi[1],
|| z < roundoff_lo[2]
|| z > roundoff_hi[2]);
return outside;
}

bool
Geometry::insideRoundoffDomain (AMREX_D_DECL(ParticleReal x, ParticleReal y, ParticleReal z)) const
{
return !outsideRoundoffDomain(AMREX_D_DECL(x, y, z));
assertRoundoffDomain();
}
#if defined(AMREX_WIN32_OPTIMIZE_OFF)
#pragma optimize("", on)
#endif

}

0 comments on commit 9b0d63e

Please sign in to comment.