Skip to content

Commit 06729c3

Browse files
authored
some cleaning of check_for_negative_density (#3191)
in particular, pack the 2 AllReduces into a single vectorized reduction
1 parent b86720d commit 06729c3

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Source/driver/Castro.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,17 +3325,17 @@ Castro::check_for_negative_density ()
33253325
for (MFIter mfi(S_new, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
33263326
const Box& bx = mfi.tilebox();
33273327

3328-
auto S_old_arr = S_old.array(mfi);
3329-
auto S_new_arr = S_new.array(mfi);
3328+
const auto S_old_arr = S_old.array(mfi);
3329+
const auto S_new_arr = S_new.array(mfi);
33303330

33313331
reduce_op.eval(bx, reduce_data,
3332-
[=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
3332+
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept -> ReduceTuple
33333333
{
33343334
int rho_check_failed = 0;
33353335
int X_check_failed = 0;
33363336

3337-
Real rho = S_new_arr(i,j,k,URHO);
3338-
Real rhoInv = 1.0_rt / rho;
3337+
const Real rho = S_new_arr(i,j,k,URHO);
3338+
const Real rhoInv = 1.0_rt / rho;
33393339

33403340
// Optionally, the user can ignore this if the starting
33413341
// density is lower than a certain threshold. This is useful
@@ -3349,7 +3349,7 @@ Castro::check_for_negative_density ()
33493349
rho_check_failed = 1;
33503350
}
33513351

3352-
if (S_new_arr(i,j,k,URHO) >= castro::abundance_failure_rho_cutoff) {
3352+
if (rho >= castro::abundance_failure_rho_cutoff) {
33533353

33543354
for (int n = 0; n < NumSpec; ++n) {
33553355
Real X = S_new_arr(i,j,k,UFS+n) * rhoInv;
@@ -3383,17 +3383,17 @@ Castro::check_for_negative_density ()
33833383
int rho_check_failed = amrex::get<0>(hv);
33843384
int X_check_failed = amrex::get<1>(hv);
33853385

3386-
ParallelDescriptor::ReduceIntMax(rho_check_failed);
3387-
ParallelDescriptor::ReduceIntMax(X_check_failed);
3386+
int fails[] = {rho_check_failed, X_check_failed};
3387+
ParallelDescriptor::ReduceIntMax(fails, 2);
33883388

33893389
advance_status status {};
33903390

3391-
if (rho_check_failed == 1) {
3391+
if (fails[0] == 1) {
33923392
status.success = false;
33933393
status.reason = "invalid density";
33943394
}
33953395

3396-
if (X_check_failed == 1) {
3396+
if (fails[1] == 1) {
33973397
status.success = false;
33983398
status.reason = "invalid X";
33993399
}

0 commit comments

Comments
 (0)