Skip to content

metricCreateIsotropic on an empty rank leaves a later distribute hanging #975

Open

Description

@lmoresi

On a mesh with a rank holding no cells, PETSc's metricCreateIsotropic leaves a later dm.distribute hanging. Found in the review of the #908/#909 fix, which marks it with a TODO(BUG) in Mesh.remesh.

With cells [8, 8, 0] at np 3: clone, createGlobalVec, norm, barrier, a coordinate DM clone and a new variable all pass after the call (exit 0), so it is not simply the next collective. A later dm.distribute hangs (exit 124), with or without the boundary-condition stack, and markBoundaryFaces gives MPI error 98 on rank 2. The control with cells on every rank exits 0.

So a real parallel remesh with an empty rank would still stop before the transfer loop, if the PETSc has an adapter. This conda-forge PETSc has none, so this is the metric call and the sequence after it, not a real adaptMetric. The cause inside PETSc is not confirmed.

Underworld development team with AI support from Claude Code

Activity

  1. lmoresi commented on Nov 13, 2026

    @lmoresi
    MemberAuthor

    Probe-pass verdict: LIVE on development 70b240c, narrowed. The hang still reproduces, but only when the metric field is not the mesh's first field. With the indicator as field 0, the same empty-rank sequence passes.

    Probed by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)), at np 3, with cells [8, 8, 0] on a right-triangle mesh (16 cells, shell partition), on the same conda-forge PETSc 3.25.3 as the report. That PETSc has no adapter, so adaptMetric is replaced by a stand-in. The metric call is real.

    The original sequence probes, rerun:

    sequence_full  cells [6, 5, 5]  -> metric made ... DONE                     exit 0
    sequence       cells [8, 8, 0]  -> metric made, then the next DM build hangs  exit 124
    nostack        cells [8, 8, 0]  -> same, without the boundary-condition stack exit 124
    remesh         cells [8, 8, 0]  -> [2] PETSC ERROR: MPI error 1 Invalid buffer pointer
                                       ... DMPlexMarkBoundaryFaces, error code 98   exit 124
    

    In the hang, the supervisor's stacks put every rank in the next right_triangle_of_cells(). Rank 0 is in PetscCommBuildTwoSided_Allreduce under DMPlexPartitionLabelCreateSF, and ranks 1 and 2 are in an MPI_Allreduce.

    The narrowing probe is the smallest form of the sequence:

    m = uw.discretisation.Mesh(right_triangle_of_cells(4, size - 1), degree=1, qdegree=3)   # [8, 8, 0]
    if case == "extra":
        S = uw.discretisation.MeshVariable("S", m, 1, degree=2)        # defined before H
    H = uw.discretisation.MeshVariable("H", m, 1, degree=1); H.array[:, 0, 0] = 36.
    mv = m.dm.metricCreateIsotropic(H._lvec, H.field_id)
    new = right_triangle_of_cells(6, size)                              # createFromCellList + distribute
    base   H field_id 0  -> metric made, next distribute fine     exit 0
    extra  S, then H     -> next distribute hangs (same stacks)   exit 124
    

    So the trigger is metricCreateIsotropic on a rank with no cells, with the indicator field not field 0. Each case ran once. The hang shows up one or more collectives later, in PETSc's two-sided setup, and a Invalid buffer pointer inside the same routine is the other symptom. That looks like a message left unmatched by the metric call on the empty rank, but this is inference and was not traced inside PETSc. In Mesh.remesh the indicator is any user variable, so it is usually not field 0 [read].

    Who hits it. Nobody yet: no PETSc that Underworld builds adapts on more than one rank, as the TODO(BUG) in Mesh.remesh says [read]. It will matter as soon as a parallel adapter (ParMmg) is in the build.

    Fix options.

    1. In Mesh.remesh, build the metric on a DM that holds only the indicator, as field 0 (a clone with one P1 field and the values copied), or assemble the isotropic metric h⁻² I directly. Size S to M, in discretisation_mesh.py (and adaptivity.py, line 618, which makes the same call [read]).
    2. Report it upstream to PETSc with the short reproducer above, and confirm the cause with a debug PETSc build. That needs a PETSc build, which this pass could not do.

    Option 1 is a work-around until option 2 settles it. Neither touches solver defaults, petsc_generic_snes_solvers, rotated_bc.py or the custom multigrid.

    Logs kept by the reviewer.

    Underworld development team with AI support from Claude Code

  2. lmoresi commented on Nov 20, 2026

    @lmoresi
    MemberAuthor

    Probed against PR #1271 (H5, 2026-11-20), which fixes the same mechanism elsewhere. A solver's DM clones create PETSc's coordinate DMField lazily, only on ranks with cells, so COMM_WORLD's tag counter drifts and the next two-sided exchange mismatches. #1271 forces the field in clone_dm_hierarchy. #975 is NOT fixed by it: metricCreateIsotropic creates one lazy coordinate DMField on a DM that #1271 doesn't reach, so the tags still differ by 1 and the distribute still hangs on the branch. The issue's option 1 stands. Still live.

    Underworld development team with AI support from Claude Code


    Generated by Claude Code

  3. added
    fixed-in-PR
    on Nov 20, 2026
  4. lmoresi commented on Nov 20, 2026

    @lmoresi
    MemberAuthor

    Fixed in PR #1287 (H5), which is open and in review. The coordinate field is now forced on the indicator's DM before metricCreateIsotropic, at both sites (Mesh.remesh and mesh_adapt_meshVar), so the world communicator's tag counter no longer drifts on a rank with no cells. The new test fails on development at np 3 to 5, where the tags differ and the distribute hangs; on the branch it passes and the next distribute completes. Labelled fixed-in-PR.

    Underworld development team with AI support from Claude Code


    Generated by Claude Code

  5. added a commit that references this issue on Nov 20, 2026
  6. added
    fixed-in-development
    and removed
    fixed-in-PR
    on Nov 20, 2026
  7. lmoresi commented on Nov 20, 2026

    @lmoresi
    MemberAuthor

    Fixed in development by #1287 (merge commit 07f450b). The coordinate field is forced on the indicator's DM before metricCreateIsotropic, at both sites (Mesh.remesh and mesh_adapt_meshVar). H1 measured it at np 3, 4 and 5, with the indicator as field 1 or 2: development's empty rank fell 1 tag behind and the distribute hung; with the fix the tag spread is 0 and the distribute completes. The metric is bit-identical to development. A direct user call to PETSc's metricCreateIsotropic can still hang; the PETSc report stands. The issue closes at release.

    Underworld development team with AI support from Claude Code


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed-in-development

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions