Skip to content

bugfix for spurious reflections caused by single-precision rounding errors - #1882

Merged
danielpeter merged 1 commit into
SPECFEM:develfrom
bch0w:devel
Oct 9, 2026
Merged

danielpeter merged 1 commit into
SPECFEM:develfrom
bch0w:devel

Conversation

@bch0w

@bch0w bch0w commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Fix MPI interface point mismatch in xgenerate_databases (fixes #1866)

Hi @danielpeter, I think I have found the numerical reflection issue that was affecting my simulations. The PR text below as well as the bugfix were generated by Claude but I have reviewed them and tested the new bugfix. I did the testing on our institute GPU cluster, but also saw the issue when running in CPU mode. I'm not sure why I didn't catch this on the CPU version before, I don't think I was testing the exact same setup so perhaps that prevented me from running into the issue.

Re-compiling and re-running xgenerate_databases appears to have fixed the issue. I have confirmed that there are no longer spurious reflections along partition boundaries when looking at wavefield snapshots of the bugfixed code. The changes are minimal but I am not sure if the modifications have any unexpected effects, hope you can review and decide if this is a good approach. Happy to run further tests or modify as you see fit.


Problem

Simulations with large mesh coordinates (e.g., UTM, ~10⁶ m) could show spurious reflections along partition boundaries. These artifacts moved when NPROC changed, appeared in both CPU and GPU runs that used the same databases, and were absent with a single process.

Cause

get_MPI_interface() sorts each interface's points by x, then y, then z, so that both neighboring partitions list shared points in the same order. The solver then pairs points purely by their position in that list during assembly.

The coordinates were taken from the CUSTOM_REAL arrays (x/y/zstore_unique). In single precision, a coordinate of ~4.6e6 m is only resolved to ~0.5 m, while the sort tolerance (SMALLVAL_TOL * (x_max - x_min)) is ~1e-5 m. If the same physical point rounded to different single-precision values on two partitions, the sort grouped it differently on each side. From that point on, the two interface lists no longer lined up, and physically different points (tens of km apart, in our case) were assembled together.

The existing assembly test in xgenerate_databases can't detect this. Assembly is symmetric, so both sides still end up with identical sums.

Fix

Sort the interface points using the double-precision GLL coordinates (xstore/ystore/zstore from generate_databases_par), mapped onto the global points through ibool. In double precision the two partitions' copies of a point differ by ~1e-9 m, well within the tolerance, so both sides produce the same order.

Only the sort input changes. The output database format is the same, and no solver or mesher changes are needed. Existing meshes only need xgenerate_databases to be rerun.

Verification

Tested on an affected mesh (xmeshfem3D, 2 doubling layers, 16 processes, UTM coordinates). A temporary check compared the coordinates of shared interface points across neighboring ranks:

  • Before the fix: maximum mismatch of 5.09e4 m.
  • After the fix: maximum mismatch of 0.5 m, which is one single-precision rounding step at these coordinate values.

After the fix, the boundary artifacts are gone in both CPU and GPU runs.

🤖 Generated with Claude Code

@bch0w bch0w changed the title bugfix for UTM mesh numerical scatterers caused by single-precision rounding errors bugfix for spurious reflections caused by single-precision rounding errors Oct 9, 2026
@danielpeter

Copy link
Copy Markdown
Member

looks good - although it breaks the fault examples for now, i'll figure out a way to fix that later.

@danielpeter
danielpeter merged commit bf0f79b into SPECFEM:devel Oct 9, 2026
48 of 49 checks passed
@bch0w

bch0w commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

As I help others check if they were affected by this issue, I have learned a bit more and will keep that info updated here incase others run into this issue in the future.

  • Not GPU-specific: this affects CPU and GPU runs equally, at any NPROC.
  • Why it happens:
    • Neighboring partitions exchange forces on their shared boundary points every time step. The points are matched only by their position in a list that each partition builds on its own, by sorting the points by x, then y, then z.
    • In single precision, large UTM values (~10^6 m) can only be stored to ~0.5 m. A point that falls exactly halfway between two storable values can be rounded differently by two partitions.
    • The sort treats a 0.5 m difference as two separate points. The two partitions' lists then fall out of step for that column of points, so forces get added between the wrong points, in my case up to 51 km apart.
    • Those points act like small spurious sources along the partition boundary, which shows up as reflections.
  • A mesh is at risk only if all of these are true:
    • the code is a single-precision build (the default)
    • the mesh uses large coordinate values (e.g. UTM)
    • the databases were generated before the fix
  • Most likely trigger: a mesh with round UTM boundaries and a "nice" element size (e.g. a 190 km span / 64 elements = 2968.75 m). Element corners then land on values like ...281.25 that sit exactly halfway between two single-precision values.
  • Less likely to be affected: meshes defined in lat/lon and projected to UTM, which tend to have arbitrary fractional coordinates.

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