-
Notifications
You must be signed in to change notification settings - Fork 8
Fix VE_Stokes first-solve parallel deadlock (#130) #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """ | ||
| MPI regression test for VE_Stokes first-solve deadlock (issue #130). | ||
|
|
||
| The bug: the first ``VE_Stokes.solve()`` call on a fresh in-memory mesh | ||
| deadlocked at specific ``(np, mesh)`` partition geometries (e.g. np=4 | ||
| with a 16x8 StructuredQuadBox → 4x2 rank partition). Root cause was | ||
| lazy invocation of ``mesh._get_coords_for_basis`` (DMClone + | ||
| createInterpolation + globalToLocal collectives) from rank-local code | ||
| paths in ``global_evaluate_nd``: ranks whose migrated particles were | ||
| all interior skipped the RBF path and never entered the collective, | ||
| while ranks with exterior particles did — deadlocking forever. | ||
|
|
||
| The fix pre-populates each variable's coordinate cache at the end of | ||
| ``_BaseMeshVariable.__init__`` (a collective context), so subsequent | ||
| rank-local lookups always hit the cache. | ||
|
|
||
| This test runs the canonical failure case at np=4, 16x8 and fails fast | ||
| via the pytest timeout rather than blocking indefinitely. | ||
| """ | ||
|
|
||
| import sympy | ||
| import pytest | ||
| import underworld3 as uw | ||
| from underworld3.function import expression | ||
|
|
||
|
|
||
| pytestmark = [ | ||
| pytest.mark.level_2, | ||
| pytest.mark.tier_a, | ||
| pytest.mark.mpi(min_size=4), | ||
| pytest.mark.timeout(60), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.mpi(min_size=4) | ||
| def test_ve_stokes_first_solve_does_not_deadlock(): | ||
| """ | ||
| First VE_Stokes.solve() must complete under MPI on a partition-sensitive | ||
| mesh (16x8 -> 4x2 rank partition at np=4). Before the fix for issue #130, | ||
| this hung at the first solve indefinitely. | ||
| """ | ||
| mesh = uw.meshing.StructuredQuadBox(elementRes=(16, 8)) | ||
| v = uw.discretisation.MeshVariable("V", mesh, mesh.dim, degree=2) | ||
| p = uw.discretisation.MeshVariable("P", mesh, 1, degree=1) | ||
|
|
||
| stokes = uw.systems.VE_Stokes( | ||
| mesh, velocityField=v, pressureField=p, order=2 | ||
| ) | ||
| stokes.constitutive_model = ( | ||
| uw.constitutive_models.ViscoElasticPlasticFlowModel | ||
| ) | ||
| stokes.constitutive_model.Parameters.shear_viscosity_0 = 1.0 | ||
| stokes.constitutive_model.Parameters.shear_modulus = 1.0 | ||
| stokes.constitutive_model.Parameters.dt_elastic = 0.02 | ||
|
|
||
| V_top = expression("V_top", 0.5, "Top BC") | ||
| stokes.add_dirichlet_bc((V_top, 0.0), "Top") | ||
| stokes.add_dirichlet_bc((0.0, 0.0), "Bottom") | ||
| stokes.add_dirichlet_bc((sympy.oo, 0.0), "Left") | ||
| stokes.add_dirichlet_bc((sympy.oo, 0.0), "Right") | ||
|
|
||
| stokes.solve(timestep=0.02) | ||
|
|
||
| # Velocity must carry the top BC. If the solve returned without diverging | ||
| # (pre-fix deadlock would hit the pytest timeout) but with zero velocity, | ||
| # something else went wrong. | ||
| import numpy as np | ||
| v_max = float(np.abs(v.data).max()) if v.data.size else 0.0 | ||
| gathered = uw.mpi.comm.allgather(v_max) | ||
| assert max(gathered) > 1.0e-6, ( | ||
| f"Velocity field is effectively zero after solve; max|v|={gathered}" | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new eager call to mesh._get_coords_for_var(self) will invoke PETSc createInterpolation paths. In discretisation_mesh._get_coords_for_basis, the returned matInterp/vecScale objects are not explicitly destroyed, so calling this for every variable construction can accumulate PETSc objects until GC runs (and may increase memory usage in long runs / adaptive loops). Consider updating _get_coords_for_basis to destroy matInterp (and vecScale when non-null) after use, similar to src/underworld3/function/field_projection.py which does explicit cleanup.