Skip to content

Commit 50ff9f2

Browse files
authored
SUNDIALS: Fix N_VInvTest_MultiFab (#5236)
The operation should be done on all components. This also fixes another issue. N_VInvTest should return MPI-reduced result, not local result. If we want local reduction result, that should be N_InvTestLocal. Close #5039.
1 parent 4b7cf9c commit 50ff9f2

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

Src/Extern/SUNDIALS/AMReX_NVector_MultiFab.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -532,26 +532,25 @@ int N_VInvTest_MultiFab(N_Vector x, N_Vector z)
532532
auto const& ma1 = mf_x->const_arrays();
533533
auto const& ma2 = mf_z->arrays();
534534

535-
GpuTuple<bool> mm = ParReduce(TypeList<ReduceOpLogicalAnd>{},
536-
TypeList<bool>{},
537-
*mf_x, amrex::IntVect::TheZeroVector(),
538-
[=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept
539-
-> GpuTuple<bool>
540-
{
541-
bool result = !(ma1[box_no](i,j,k) == amrex::Real(0.0));
542-
ma2[box_no](i,j,k) = result ? amrex::Real(1.0) / ma1[box_no](i,j,k) : 0.0;
543-
return { result };
544-
});
535+
bool val = ParReduce(TypeList<ReduceOpLogicalAnd>{},
536+
TypeList<int>{}, // We use int for logical and on device.
537+
*mf_x, amrex::IntVect::TheZeroVector(),
538+
mf_x->nComp(),
539+
[=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
540+
-> GpuTuple<int>
541+
{
542+
auto xx = ma1[box_no](i,j,k,n);
543+
bool result = xx != Real(0.0);
544+
ma2[box_no](i,j,k,n) = result ? Real(1.0)/xx : Real(0.0);
545+
return { static_cast<int>(result) };
546+
});
545547

546-
bool val = amrex::get<0>(mm);
548+
ParallelAllReduce::And(val, ParallelContext::CommunicatorSub());
547549

548-
if (val == false)
549-
{
550-
return SUNFALSE;
551-
}
552-
else
553-
{
554-
return SUNTRUE;
550+
if (val) {
551+
return SUNTRUE;
552+
} else {
553+
return SUNFALSE;
555554
}
556555
}
557556

0 commit comments

Comments
 (0)