From a1c1525ecad11b57170fbf905baeda205cc7eb52 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Sat, 16 Mar 2024 16:04:15 -0700 Subject: [PATCH 1/2] Explicit Includes: MultiFab -> BaseFab (#3802) ## Summary Add includes for directly used types. ## Additional background Related to #3798, I was wondering if there might be an missing include to `BaseFab::lockAdd` and `AMReX_OpenMP.H` somewhere... In the end this is just cleaning. ## Checklist The proposed changes: - [ ] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate --- Src/Base/AMReX_FabArray.H | 7 +++++-- Src/Base/AMReX_FabArrayBase.H | 2 ++ Src/Base/AMReX_MultiFab.H | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Src/Base/AMReX_FabArray.H b/Src/Base/AMReX_FabArray.H index 56300d4cfef..70b2ba533c9 100644 --- a/Src/Base/AMReX_FabArray.H +++ b/Src/Base/AMReX_FabArray.H @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -39,14 +40,16 @@ #include #endif +#include #include #include #include +#include #include -#include -#include #include #include +#include + namespace amrex { diff --git a/Src/Base/AMReX_FabArrayBase.H b/Src/Base/AMReX_FabArrayBase.H index 21029eff840..09dfd5e22db 100644 --- a/Src/Base/AMReX_FabArrayBase.H +++ b/Src/Base/AMReX_FabArrayBase.H @@ -15,9 +15,11 @@ #include #endif +#include #include #include + namespace amrex { class MFIter; diff --git a/Src/Base/AMReX_MultiFab.H b/Src/Base/AMReX_MultiFab.H index fdf2e67cbd8..91e278308ea 100644 --- a/Src/Base/AMReX_MultiFab.H +++ b/Src/Base/AMReX_MultiFab.H @@ -4,6 +4,7 @@ #include #include +#include #include #include #include From 54e438a0b67b3cb2a8b3fc6184921e5909fbb05e Mon Sep 17 00:00:00 2001 From: David Grote Date: Sat, 16 Mar 2024 16:09:09 -0700 Subject: [PATCH 2/2] In allocateSlice, handle empty list of boxes (#3808) ## Summary In `allocateSlice` (which is called by `get_slice_data` in `Src/Base/AMReX_MultiFabUtil.cpp`) handle the case when no intersection is found between the slice and the box array. ## Additional background When no intersection is found, the `boxes` array will be empty which would cause a segfault if the `data` would be accessed. The fix is to return `nullptr` in this case. Also, `get_slice_data` is modified to return `nullptr` in this case as well. ## Checklist The proposed changes: - [x] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate --- Src/Base/AMReX_MultiFabUtil.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Src/Base/AMReX_MultiFabUtil.cpp b/Src/Base/AMReX_MultiFabUtil.cpp index 27efbffca0f..5dd97fa6536 100644 --- a/Src/Base/AMReX_MultiFabUtil.cpp +++ b/Src/Base/AMReX_MultiFabUtil.cpp @@ -46,11 +46,15 @@ namespace { boxes.push_back(is.second); slice_to_full_ba_map.push_back(is.first); } - BoxArray slice_ba(boxes.data(), static_cast(boxes.size())); - DistributionMapping slice_dmap(std::move(procs)); - - return std::make_unique(slice_ba, slice_dmap, ncomp, 0, - MFInfo(), FArrayBoxFactory()); + if (!boxes.empty()) { + BoxArray slice_ba(boxes.data(), static_cast(boxes.size())); + DistributionMapping slice_dmap(std::move(procs)); + + return std::make_unique(slice_ba, slice_dmap, ncomp, 0, + MFInfo(), FArrayBoxFactory()); + } else { + return nullptr; + } } } @@ -560,6 +564,10 @@ namespace amrex Vector slice_to_full_ba_map; std::unique_ptr slice = allocateSlice(dir, cc, ncomp, geom, coord, slice_to_full_ba_map); + if (!slice) { + return nullptr; + } + #ifdef AMREX_USE_OMP #pragma omp parallel if (Gpu::notInLaunchRegion()) #endif