Skip to content

Fix segfault when managed memory is not used. - #147

Merged
asalmgren merged 1 commit into
AMReX-Fluids:developmentfrom
WeiqunZhang:fix_segfault
Jul 28, 2023
Merged

asalmgren merged 1 commit into
AMReX-Fluids:developmentfrom
WeiqunZhang:fix_segfault

Conversation

@WeiqunZhang

Copy link
Copy Markdown
Member

No description provided.

@WeiqunZhang
WeiqunZhang requested a review from asalmgren July 28, 2023 17:46
@asalmgren
asalmgren merged commit 92f0e72 into AMReX-Fluids:development Jul 28, 2023
@WeiqunZhang
WeiqunZhang deleted the fix_segfault branch July 28, 2023 19:28
asalmgren added a commit that referenced this pull request Oct 12, 2026
Fixes #233.

`NavierStokesBase::init_eb` has no caller anywhere in `Source/`, `Exec/`
or `Tutorials/`, and it is the only caller of `initialize_eb2_structs`,
which is in turn the only writer of `ebmask` and the only place that
clears `no_eb_in_domain`. With `no_eb_in_domain` stuck at its default of
`true`, `define_body_state` and `set_body_state` return on their first
line, and the two `set_body_state(S_new)` calls in `NavierStokes.cpp`
were commented out anyway.

Besides being dead, the code was a hazard if revived: the `singlevalued`
branch of `initialize_eb2_structs` and the point search in
`define_body_state` walk an `EBCellFlagFab` and a `BaseFab<int>` with a
`BoxIterator` on the host, which is invalid for the device-resident data
of a GPU build (the bug class fixed in 92f0e72 / #147), and the rank
search would `Bcast` with `body_rank == -1`, guarded only by an
`AMREX_ASSERT`, if no rank found an uncovered cell.

Removed `init_eb`, `initialize_eb2_structs`, `define_body_state`,
`set_body_state`, `ebInitialized`, and the `ebmask`, `body_state`,
`body_state_set`, `no_eb_in_domain` and `eb_initialized` members.
`Source/NSB_K.H` held only `set_body_state_k`, so the header is deleted
along with its four `#include`s. `facecent` goes too —
`initialize_eb2_structs` held its only assignment and nothing reads it.
`volfrac` and `areafrac` stay: they are set on the live path in
`NavierStokesBase.cpp:774-775` and used by the reflux and diffusion
code.

The `NavierStokes.cpp` comments that pointed at `set_body_state` are
updated. `initData`'s `EB_set_covered(S_new, COVERED_VAL)` is unchanged
and remains how covered cells get their values.

## Verification

- `Exec/run2d`, `Exec/run3d`, `Exec/eb_run2d` and `Exec/eb_run3d` all
build clean.
- EB regtest `regtest.2d.flow_past_cylinder-x` (2 MPI ranks, 10 steps)
agrees bit-for-bit with the pre-change build on all fields including
`vfrac` (`fcompare`: PLOTFILE AGREE).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants