Skip to content

Mesh construction crashes on empty ranks: navigation kd-tree build passes a 1-D empty array (StructuredQuadBox(elementRes=(2,2)) at np4) #399

Description

@lmoresi

Found during the #330 batch (2026-07-23): fixing the Swarm.save race unmasked this in tests/test_0003_save_load.py at np4 — the file previously hung before reaching it.

Any mesh construction where a rank ends up with zero local cells crashes:

mpirun -np 4 python -c "import underworld3 as uw; uw.meshing.StructuredQuadBox(elementRes=(2,2))"
# rank with no cells:
#   ValueError: Buffer has wrong number of dimensions (expected 2, got 1)
#   at src/underworld3/ckdtree.pyx:99, via _build_kd_tree_index
#   (discretisation_mesh.py:5154); other ranks then die on MPI_ERR_BUFFER
#   from the resulting collective divergence.

Two layers to it:

  1. _build_kd_tree_index builds numpy.array(control_points_list) / numpy.array(centroids_list) — empty lists give 1-D (0,) arrays, which the KDTree memoryview (double[:,::1]) rejects.
  2. Shaping them (0, dim) is not enough on its own: KDTree.__cinit__ takes &points[0][0] (ckdtree.pyx:104), which is invalid for zero rows — the constructor needs an explicit empty-index path (related to the fix(swarm): Track-0 stale-cache and migration-semantics fixes (BF-02/05/06/07/08 + #286) #313 empty-rank KDTree query guards, which protected callers but not construction).

Verified identical on unmodified development (54a4fc58). Reproduces with any partition that starves a rank of cells — tiny meshes are just the easy trigger; extreme partition imbalance on real meshes would hit the same wall.

Also worth noting: tests/test_0003_save_load.py runs cleanly under MPI up to this point once #330 is fixed; this is the remaining blocker to making that file part of a parallel gate.

Underworld development team with AI support from Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions