Repository navigation
r.sim: Simulate all walkers when running in parallel - #7964
Merged
Merged
Conversation
Each thread computed its own range of walkers from a chunk size rounded to the nearest integer, steps = (int)(nwalk / nthreads + 0.5). When the division rounded down, the walkers past the last range were never moved and never added their water, up to (nthreads - 1) / 2 walkers in every iteration: nwalk nthreads steps covered dropped 2205 4 551 2204 1 2206 4 552 2208 0 (last range cut at nwalk) 2211 8 276 2208 3 1000007 16 62500 1000000 7 Round the chunk size up instead, so that the ranges cover all walkers. The last range is then cut at nwalk as before, and with fewer walkers than threads, the last threads get empty ranges. Single-threaded results do not change: the depth, discharge, sediment flux and erosion/deposition maps computed from the nc_spm elevation are byte-identical to those before this change. Written with the help of Claude Code.
petrasovaa
approved these changes
Sep 28, 2026
wenzeslaus
added a commit
to wenzeslaus/grass
that referenced
this pull request
Sep 29, 2026
Each thread computed its range of walkers from a chunk size rounded to the nearest integer, steps = (int)(nwalk / nthreads + 0.5). When the division rounded down, the walkers past the last range were never moved and never added their water, up to (nthreads - 1) / 2 walkers in every iteration, e.g., 1 of 2205 walkers with 4 threads, 7 of 1000007 with 16. Round the chunk size up instead, so that the ranges cover all walkers. The last range is cut at nwalk as before, and with fewer walkers than threads, the last threads get empty ranges. Single-threaded results do not change: the depth, discharge, sediment flux and erosion/deposition maps computed from the nc_spm elevation are byte-identical to those before this change. Written with the help of Claude Code.
wenzeslaus
added a commit
to wenzeslaus/grass
that referenced
this pull request
Sep 29, 2026
Each thread computed its range of walkers from a chunk size rounded to the nearest integer, steps = (int)(nwalk / nthreads + 0.5). When the division rounded down, the walkers past the last range were never moved and never added their water, up to (nthreads - 1) / 2 walkers in every iteration, e.g., 1 of 2205 walkers with 4 threads, 7 of 1000007 with 16. Round the chunk size up instead, so that the ranges cover all walkers. The last range is cut at nwalk as before, and with fewer walkers than threads, the last threads get empty ranges. Single-threaded results do not change: the depth, discharge, sediment flux and erosion/deposition maps computed from the nc_spm elevation are byte-identical to those before this change. Written with the help of Claude Code.
This was referenced Oct 1, 2026
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.
With nprocs > 1, r.sim.water and r.sim.sediment skipped some walkers in every iteration: up to (nthreads - 1) / 2 walkers were never moved and never added their water. This rounds the per-thread chunk size up instead of to the nearest integer, a two-line change. Single-threaded results do not change.
Details (AI generated)
Each thread computed its range of walkers from a chunk size rounded to the nearest integer,
steps = (int)(nwalk / nthreads + 0.5). When the division rounded down, the walkers past the last range were never moved:The chunk size is now rounded up, so the ranges cover all walkers. The last range is cut at nwalk as before, and with fewer walkers than threads the last threads get empty ranges. No other OpenMP code changes.
Verification: single-threaded depth and discharge (with and without infiltration), sediment flux and erosion/deposition on nc_spm are byte-identical to main.
The analysis, code and measurements were done with Claude Code (Opus) and reviewed by me.