From 9ef35c8804dfb5a0cc383abf159bcb88ab8b4b13 Mon Sep 17 00:00:00 2001 From: nataraj2 Date: Tue, 16 Jun 2026 12:12:48 -0700 Subject: [PATCH 1/2] Update routine with nan info --- Source/ERF.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/Source/ERF.cpp b/Source/ERF.cpp index 182b43ce0..29acbf42f 100644 --- a/Source/ERF.cpp +++ b/Source/ERF.cpp @@ -3221,21 +3221,69 @@ ERF::writeNow(double cur_time, const int nstep, const int plot_int, const Real p } void -ERF::check_state_for_nans(MultiFab const& S) +ERF::check_state_for_nans (MultiFab const& S) { - bool any_have_nans = false; + amrex::Gpu::DeviceScalar d_found(0); + + // comp, i, j, k + amrex::Gpu::DeviceVector d_info(4, -1); + + for (MFIter mfi(S,TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + const Box& bx = mfi.tilebox(); + auto const& s_arr = S.const_array(mfi); + + const int ncomp = S.nComp(); - for (int i = 0; i < S.nComp(); i++) { + int* found = d_found.dataPtr(); + int* info = d_info.dataPtr(); - if (S.contains_nan(i,1,0)) + ParallelFor(bx, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { - amrex::Print() << "Component " << i << " of conserved variables contains NaNs" << '\n'; - any_have_nans = true; - } + // Somebody already found a NaN + if (*found) return; + + for (int n = 0; n < ncomp; ++n) + { + Real val = s_arr(i,j,k,n); + + if (val != val) // NaN test + { + // Only one thread wins + if (amrex::Gpu::Atomic::CAS(found,0,1) == 0) + { + info[0] = n; + info[1] = i; + info[2] = j; + info[3] = k; + } + return; + } + } + }); } - if (any_have_nans) { - exit(0); + amrex::Gpu::streamSynchronize(); + + if (d_found.dataValue()) + { + amrex::Vector h_info(4); + amrex::Print() << "Found flag = " << d_found.dataValue() << "\n"; + + amrex::Gpu::copy( + amrex::Gpu::deviceToHost, + d_info.begin(), + d_info.end(), + h_info.begin()); + + std::cout << "NaN found in component " << h_info[0] + << " at (i,j,k) = (" + << h_info[1] << ", " + << h_info[2] << ", " + << h_info[3] << ")\n"; + + amrex::Abort("NaN detected in state"); } } From ed8c408b31f3193ab1c4e1caa5ab4912d64e8a3b Mon Sep 17 00:00:00 2001 From: nataraj2 Date: Tue, 16 Jun 2026 15:09:07 -0700 Subject: [PATCH 2/2] Protecting against multiple inputs options --- Source/ERF.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Source/ERF.cpp b/Source/ERF.cpp index 29acbf42f..037c80f73 100644 --- a/Source/ERF.cpp +++ b/Source/ERF.cpp @@ -2901,6 +2901,50 @@ ERF::ReadParameters () ParameterSanityChecks(); } +void CheckForDuplicateInputs () +{ + amrex::ParmParse pp; + const auto& tbl = pp.table(); + + bool found = false; + + for (const auto& [full_name, entry] : tbl) + { + std::string prefix; + std::string name; + + auto pos = full_name.find('.'); + + if (pos != std::string::npos) + { + prefix = full_name.substr(0, pos); + name = full_name.substr(pos + 1); + } + else + { + prefix = "global"; + name = full_name; + } + + if (entry.m_vals.size() > 1) + { + found = true; + + amrex::Print() << "Duplicate input: "; + + if (prefix == "global") + amrex::Print() << name; + else + amrex::Print() << prefix << "." << name; + + amrex::Print() << " (" << entry.m_vals.size() << " occurrences)\n"; + } + } + + if (found) + amrex::Abort("Duplicate inputs detected"); +} + // Read in some parameters from inputs file void ERF::ParameterSanityChecks () @@ -2966,6 +3010,8 @@ ERF::ParameterSanityChecks () if (solverChoice.coupling_type == CouplingType::TwoWay && cf_width > 0) { Abort("For two-way coupling you must set cf_width = 0"); } + + CheckForDuplicateInputs(); } // Create horizontal average quantities for 5 variables: