Repository navigation
Description
Severity: low · Category: gpu-parallel · Fix order: 19 of 21 — fix this 19th.
Filenames are numbered in reverse fix order: 001 = fix last, 021 = fix first. This file is 003.
Location: Tutorials/TaylorGreen/benchmarks/ViscBench.cpp:175
Based on commit 9bf664bf (line numbers refer to that tree).
The defect
What is wrong — The loop over all global grid indices dereferences MultiFabs by global index (dataI[iGrid] here, (dataE[iLevel])[iGrid] at lines 189/196) without checking ownership, and AmrData::FillVar(FArrayBox,...,0) fills tmpFab only on rank 0.
Why it matters
Build with USE_MPI=TRUE and run on 2+ ranks: FabArray::fabPtr(K) returns m_fabs_v[localindex(K)] with localindex==-1 for non-owned grids (UB/segfault in release, assert in debug); ranks other than 0 also copy uninitialized tmpFab data, so error norms are garbage even where it does not crash.
Suggested fix
Switch to the distributed overload AmrData::FillVar(MultiFab&, level, varNames, destFillComps), which fillpatches each rank's own boxes; that is exactly what AMReX's own comparison tool does (amrex/Tools/C_util/Convergence/DiffSameGrid.cpp:151). Build varNames/destComps from the first nComp plot variables so the component ordering assumed by varNames at line 240 is unchanged. Drive FORT_VISCBENCH from MFIter mfi(*dataE[iLevel]), taking the FAB as (*dataE[iLevel])[mfi] and using mfi.index() to index baI, GridLocLo() and GridLocHi() — that metadata comes from the plotfile header and is replicated on every rank, so global indexing stays valid there.
Apply together with an ParallelDescriptor::IOProcessor() guard on the std::cout blocks, keeping the norm0/norm1/norm2 calls outside the guard: MultiFab::norm2 goes through MultiFab::Dot, an all-reduce every rank must reach or the run hangs. Maintainer decision: make the tool MPI-correct as above, or declare it serial and abort when NProcs() > 1 (the GNUmakefile ships USE_MPI = FALSE).
--- a/Tutorials/TaylorGreen/benchmarks/ViscBench.cpp
+++ b/Tutorials/TaylorGreen/benchmarks/ViscBench.cpp
@@ -162,43 +162,40 @@
MultiFab dataI(baI, dmap, nComp, 0);
- for (int iGrid=0; iGrid<baI.size(); ++iGrid)
+ for (int iComp=0; iComp<nComp; ++iComp)
{
- const Box& dataGrid = baI[iGrid];
-
- for (int iComp=0; iComp<nComp; ++iComp)
- {
- FArrayBox tmpFab(dataGrid,1);
-
- amrDataI.FillVar(&tmpFab, dataGrid,
- iLevel, derives[iComp], 0);
- dataI[iGrid].copy(tmpFab,0,iComp,1);
- }
+ amrDataI.FillVar(dataI, iLevel, derives[iComp], iComp);
+ }
+
+ for (MFIter mfi(*dataE[iLevel]); mfi.isValid(); ++mfi)
+ {
+ const int iGrid = mfi.index();
+ const Box& dataGrid = mfi.validbox();
//
// Fill exact solution
//
const int *lo = dataGrid.loVect();
const int *hi = dataGrid.hiVect();
Vector<Real> xlo = amrDataI.GridLocLo()[iLevel][iGrid];
Vector<Real> xhi = amrDataI.GridLocHi()[iLevel][iGrid];
#if (AMREX_SPACEDIM == 3)
FORT_VISCBENCH(&time, &mu, &unifDir,
lo, hi, &nComp,
- ((*dataE[iLevel])[iGrid]).dataPtr(),
+ ((*dataE[iLevel])[mfi]).dataPtr(),
AMREX_ARLIM(lo), AMREX_ARLIM(hi),
delI.dataPtr(),
xlo.dataPtr(), xhi.dataPtr());
#else
FORT_VISCBENCH(&time, &mu,
lo, hi, &nComp,
- ((*dataE[iLevel])[iGrid]).dataPtr(),
+ ((*dataE[iLevel])[mfi]).dataPtr(),
AMREX_ARLIM(lo), AMREX_ARLIM(hi),
delI.dataPtr(),
xlo.dataPtr(), xhi.dataPtr());
#endif
}
(*error[iLevel]).ParallelCopy(dataI);
(*error[iLevel]).minus((*dataE[iLevel]), 0, nComp, 0);Relies on AmrData::FillVar(MultiFab&,level,varname,destcomp) (AMReX_AmrData.cpp:1035/1048), which skips boxes whose DistributionMap entry is not this rank and copies into destcomp — same conservative interp path as the FArrayBox overload. Exact solution now filled per owned FAB via MFIter, using mfi.index() only for GridLocLo/Hi lookup. Maintainer: per-rank std::cout of norms remains pre-existing noise.
Diff(s) are against 9bf664bf, written from the current source and verified only with git apply --check — never compiled, never run, never applied to the tree. Treat them as precise intent, not tested patches.
Verification evidence
F071 — confirmed (one verifier lens)
Lens 1 (refutation attempt): Loop for (int iGrid=0; iGrid<baI.size(); ++iGrid) runs on all ranks; line 175 dataI[iGrid].copy(tmpFab,0,iComp,1) and lines 189/196 (*dataE[iLevel])[iGrid] use global-index operator[], which in AMReX_FabArray.H:2074 does m_fabs_v[localindex(K)] with localindex==-1 for non-owned grids (assert/UB). AMReX_AmrData.cpp:1291 confirms FillVar fills dest 'only on procWithFabs' (=0 here), so ranks!=0 copy uninitialized tmpFab. No NProcs guard; GNUmakefile's USE_MPI=FALSE is merely a default. No fix in git history.
Based on commit 9bf664bf, which is also the tree the audit verified against. From an automated audit of Source/, Tutorials/ and Util/. Audit finding id: F071. Reviewer unit(s): Util+Benchmarks. Nothing here was compiled or run — the failure scenarios are code reasoning, so the reaching configuration above is the cheapest way to confirm or refute it.
Activity
Fix issues AMReX-Fluids#179, AMReX-Fluids#181-AMReX-Fluids#185, AMReX…