[GRASS-git] [OSGeo/grass] 1f83c2: r.sim: Add walker weights to the water depth atomi...

Vaclav Petras noreply at github.com
Wed Sep 30 06:57:55 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: 1f83c2d27de3da3a79cd5630df854624aab3fce0
      https://github.com/OSGeo/grass/commit/1f83c2d27de3da3a79cd5630df854624aab3fce0
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2026-09-30 (Wed, 30 Sep 2026)

  Changed paths:
    A raster/r.sim/r.sim.water/tests/r_sim_water_nprocs_test.py
    M raster/r.sim/simlib/hydro.c

  Log Message:
  -----------
  r.sim: Add walker weights to the water depth atomically (#7974)

With nprocs > 1, walkers on different threads added their weights to the
same cells of the water depth (or sediment concentration) grid without
synchronization. This is a data race: of two concurrent additions to a
cell, one can be lost, so parallel runs lost water, 12% to 14% of the
total on a small bowl at nprocs=4.

Add the weight with an atomic capture, so that no addition is lost and
the diffusion decision uses the updated sum, as in the serial code.
Parallel results still depend on the order in which threads add the
weights. The atomic makes single-threaded runs about 6% slower.

Single-threaded results do not change: the depth, discharge, sediment
flux and erosion/deposition maps computed from the nc_spm elevation,
with and without infiltration, are byte-identical to those before this
change. New tests compare the total water at 4 threads with a
single-threaded run on a bowl which keeps all walkers in the region,
including a walker count which is not a multiple of the thread count.

Written with the help of Claude Code.



To unsubscribe from these emails, change your notification settings at https://github.com/OSGeo/grass/settings/notifications


More information about the grass-commit mailing list