Repository navigation
r.sim: Keep the diffusion coefficient in a walker-local variable - #7965
Merged
Merged
Conversation
The diffusion coefficient of a walker's move was stored in a raster-sized grid cell only to be read back by the same walker a few lines later, so concurrent walkers in the same cell could read each other's value. Keep it in a local variable instead and drop the grid. The local variable is a float, the type of the grid, rather than a double, so that single-threaded results do not change: the depth, discharge, sediment flux and erosion/deposition maps of single-threaded runs on the nc_spm elevation are byte-identical to those before this change. With more threads, results can differ from before, because a walker no longer moves with a coefficient another walker wrote. Written with the help of Claude Code.
petrasovaa
approved these changes
Sep 28, 2026
wenzeslaus
enabled auto-merge (squash)
September 29, 2026 14:36
This was referenced Sep 29, 2026
wenzeslaus
added a commit
to wenzeslaus/grass
that referenced
this pull request
Sep 29, 2026
…eo#7965) The diffusion coefficient of a walker's move was stored in a raster-sized grid cell only to be read back by the same walker a few lines later, so with nprocs > 1, concurrent walkers in the same cell could read each other's value. Keep it in a local variable instead and drop the grid, which also saves one float grid of memory. The local variable is a float, the type of the grid, rather than a double, so that single-threaded results do not change: the depth, discharge, sediment flux and erosion/deposition maps of single-threaded runs on the nc_spm elevation are byte-identical to those before this change. With more threads, results can differ from before, because a walker no longer moves with a coefficient another walker wrote. Written with the help of Claude Code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the r.sim.water and r.sim.sediment walker loop, the diffusion coefficient of a walker's move was written to a raster-sized grid and read back by the same walker a few lines later. With nprocs > 1, a walker on another thread in the same cell could overwrite it in between. This makes it a local variable and drops the grid, which also saves one float grid of memory. Single-threaded results do not change.
Details (AI generated)
grids->difwas used only inmain_loop()insimlib/hydro.c, so it is removed fromGridsand from both allocation functions insimlib/input.c.The analysis and code were done with Claude Code (Opus) and reviewed by me.