Skip to content

Fix PETSc integer-width mismatches in boundary registration and JIT callbacks - #813

Merged
lmoresi merged 4 commits into
underworldcode:developmentfrom
gthyagi:feature/petsc-int64-boundary-types
Oct 6, 2026
Merged

lmoresi merged 4 commits into
underworldcode:developmentfrom
gthyagi:feature/petsc-int64-boundary-types

Conversation

@gthyagi

@gthyagi gthyagi commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

A PETSc build with 64-bit indices reads a 32-bit boundary-component buffer [0, 1] as 4294967296, causing Stokes boundary registration to fail. Boundary label scalars and generated residual/Jacobian callback signatures also assumed 32-bit integers.

This change uses the PETSc header declaration for PetscInt, allocates component and constraint-index arrays with PETSc.IntType, and gives the Cython boundary views and label storage matching types. Generated JIT callback headers include petscsystypes.h instead of redefining PETSc types.

The branch is based directly on upstream development at 1391e4aa and changes only four files. It includes no mantle-convection, SUPG, DG1/XDMF, container recipes or unrelated test-fixture changes.

Validation

  • Five new analytic Couette regressions cover inferred and legacy explicit Dirichlet components in 2D/3D, plus natural traction. The original int64 runtime failed the component dtype assertion before the fix.
  • On the integration build carrying these same fixes, both PETSc 3.25.4 integer widths passed 2,031 Level 1 tests (22 skipped, 2 expected failures each). Four-rank Stokes/HDF5 and the int64 two-node test passed; the two-node velocity matched native exactly. These are integration results, not claimed as runs of this focused branch.
  • Static checks on this focused branch: git diff --check passed; test discovery covers all 316 files, including the new test_0764* file.
  • Clean focused-source packages were compiled independently for PETSc 3.25.4 int32 and int64. The library source remains the same as 34839d9d; 391296aa changes only the regression fixture.
  • The first four-rank checks exposed a fixture issue in the enclosed 2D Couette cases, reproduced on unchanged upstream 1391e4aa with int32. The Schur RHS was approximately 5.64e-14, while its relative tolerance was 1e-10 and absolute tolerance 1e-50. The pressure block diverged (DIVERGED_DTOL), velocity subsolves encountered NaN/Inf, and SNES returned DIVERGED_LINEAR_SOLVE. Enabling the pressure nullspace alone, changing coarse/pressure preconditioners, and increasing mesh resolution did not fix it. A pressure-block absolute tolerance of 1e-12 passes all five regressions on four ranks with both widths, with the original analytic velocity bounds unchanged.
  • An additional existing Level 2 constrained-traction test timed out at 180 seconds in both focused builds and unchanged upstream int32. A guarded single-level GAMG solve spent 21,666 velocity iterations in 90 seconds. Providing a 16x16 base with one refinement, retaining the 32x32 fine grid, passed all existing traction/topography bounds in 35–40 seconds for both widths. That independent fixture correction is on gthyagi:bugfix/constrained-traction-test-hierarchy (ee7e7e98) and is deliberately excluded from this PR.
  • Final committed-file verification at 391296aa passed in Gadi job 180509622 (exit 0, 4m50s): 23 serial tests for each width, including the separately corrected constrained fixture; all five new regressions on two and four ranks for each width. The hierarchy fixture also passed against the unchanged upstream int32 library in 32.72 seconds. The 23-test serial set contains 22 focused/adjacent cases plus the separately corrected existing constrained test; that correction is not in this PR. GitHub CI is running on 391296aa; its deprecated-pattern scan passed.

Adversarial review

We checked the diff for remaining hard-coded np.int32 component arrays and int component views in the affected solver module: none remain. Boundary data, solver settings and collective ordering are unchanged. The analytic velocity oracle checks the solve as well as dtype, so a buffer-only correction with mismatched callback signatures cannot satisfy the tests. Existing guide recommendations still hold because this is an ABI correction, with no public boundary-condition semantic change.

We reviewed the regression correction again: the dtype assertions still run before the solve and still reject the old int64 component storage; the original analytic velocity bounds and positive-convergence assertions remain. The test-specific pressure absolute tolerance is smaller than the velocity error bound and does not change production defaults. No rank-dependent collective branch was introduced.

The new tests are reached by the existing test_07*py CI glob. Both integer-width builds must compile these changes; changing only the Python source cannot validate the Cython ABI. Complex scalar compatibility and empty-rank boundary behavior are not established by these new tests.

Underworld development team with AI support from Claude Code

Use the PETSc header's PetscInt rather than a private C int typedef. Allocate component and constraint-index arrays with PETSc.IntType and use PetscInt for boundary label storage and Cython component views, avoiding int32 buffers passed to an int64 PETSc API.

Add Couette regression cases for inferred and legacy explicit component lists. Both fail on the published Gadi int64 image at the component dtype assertion and pass against the existing Mac int32 installation; isolated int64 rebuild validation follows.

Underworld development team with AI support from Claude Code
Remove the generated callback header's private int32 PetscInt alias. Residual and Jacobian callbacks must use the same configured integer width as PETSc and the compiled Cython declarations.

Underworld development team with AI support from Claude Code
Verify exact Couette flow for inferred and explicit Dirichlet components in two and three dimensions, and for natural traction conditions. All five baselines pass on the existing int32 installation; the int64 isolated build exercises the same cases.

Underworld development team with AI support from Claude Code
The all-Dirichlet Couette problem has constant pressure. On four Gadi ranks the Schur right-hand side is about 5.6e-14; the default absolute tolerance of 1e-50 and relative tolerance of 1e-10 force an unattainable residual target and cause pressure divergence followed by NaN velocity subsolves. This also reproduces on unchanged upstream development with int32.

Declare the constant-pressure nullspace and use a test-specific pressure-block absolute tolerance of 1e-12. Retain the original velocity accuracy, convergence, component-value and PETSc integer-width assertions. All five analytic regressions pass on four ranks with PETSc 3.25.4 int32 and int64 on Gadi. Production solver defaults are unchanged.

Underworld development team with AI support from Claude Code
@gthyagi
gthyagi marked this pull request as ready for review October 5, 2026 03:49
@gthyagi
gthyagi requested a review from lmoresi as a code owner October 5, 2026 03:49
@lmoresi

lmoresi commented Oct 6, 2026

Copy link
Copy Markdown
Member

Issues in this branch's territory

Territory is petsc_generic_snes_solvers.pyx, petsc_types.pxd, _jitextension.py.

issue verdict
#752 JIT C-source non-determinism across ranks still live — localised to the sympy printing in JIT lowering, not to integer width. Mitigated by #753; nothing here touches it.
#547 cache=False bypassing the rank-0 compile gate closed today on a probe — no cache=False remains, and the rank-0 cold-compile branch is at _jitextension.py:799

No open issue is against the integer-width mismatch itself; this is the first.

@lmoresi lmoresi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Integer-width correctness at the PETSc boundary, with tests/test_0764_petsc_index_boundary_conditions.py covering it. A 32/64-bit mismatch in boundary registration and JIT callbacks is silent until it is not.

@lmoresi
lmoresi merged commit 9929a0a into underworldcode:development Oct 6, 2026
2 checks passed
@gthyagi

gthyagi commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@jcgraciosa, this is the PR for int64 and int32 petsc.

lmoresi added a commit to gthyagi/underworld3 that referenced this pull request Oct 12, 2026
underworldcode#813 made the generated callback header include <petscsystypes.h>, so callbacks use
PETSc's configured integer width. The generated setup.py passes no PETSc include
directory, so the build works only where PETSc's headers are on the compiler's
default path: a conda-forge PETSc in the environment, as in CI. With a custom PETSc
build every JIT compile failed with "'petscsystypes.h' file not found".

_petsc_include_dirs() reads PETSC_DIR/PETSC_ARCH from petsc4py and adds
$PETSC_DIR/include and $PETSC_DIR/$PETSC_ARCH/include (petscconf.h).
test_0021 checks that the headers are found and that a JIT solve compiles.

Underworld development team with AI support from Claude Code
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