Dear PETSc developers, With -pc_type gamg, SNESVINEWTONRSLS rebuilds the whole GAMG hierarchy every time the active set changes. On a 3D elastic contact problem, keeping one hierarchy on the full space instead cuts the total solve time by 51–69% with respect to RSLS with rigid body modes on the reduced matrix, and by 78–82% with respect to RSLS with default options. Newton iterations and contact force are unchanged. I measured two ways to do it and would like to know which one, if either, you would accept. What happens now (PETSc 3.26.1)
* When the inactive set changes, SNESSolve_VINEWTONRSLS() calls SNESVIResetPCandKSP(), which resets the KSP and its PC. GAMG then does a full setup, and -pc_gamg_reuse_interpolation does not survive the reset. On src/snes/tutorials/ex9.c every Newton iteration is a full GAMG setup, and PCSetUp is 66–72% of SNESSolve. * The reduced matrix from MatCreateSubMatrix() has no near null space. Draft MR !9886<https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/9886__;!!G_uCfscf7eWS!bM8r3-zbuOI9LVNzxiXUMudNXG724_OG09RlLLHtKZRbYDeuldJgn-0PC18Zg_N_akyqt5-ZkaX3PSvke-l_M5b7pTSZBoeZyA$ > restricts it to the inactive set; it remains useful for the default path. MR !9885<https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/9885__;!!G_uCfscf7eWS!bM8r3-zbuOI9LVNzxiXUMudNXG724_OG09RlLLHtKZRbYDeuldJgn-0PC18Zg_N_akyqt5-ZkaX3PSvke-l_M5b7pTQrT7pwrA$ > fixes a crash of the Fischer guess with RSLS. The two options Both use JZ: the Jacobian with the off-diagonal entries of the active rows and columns zeroed and the original diagonal kept, so size and nonzero pattern never change. With a zero right-hand side on the active set, JZ gives the same Newton step as the reduced system in exact arithmetic. * A, full-space solve in RSLS: solve JZ δ = −F, then zero the active components of δ (they are zero only to the KSP tolerance). No KSP or PC reset; GAMG reuses its interpolation with existing options. * B, preconditioner for the reduced system: RSLS is unchanged. A new PC keeps a GAMG hierarchy of JZ and survives the reset; it extends the reduced residual with zeros, applies the hierarchy, and restricts the result. More conservative, since the Newton method is untouched. Measurements 3D Signorini contact: unit cube, Q1 hexahedra on a DMDA, clamped top face, rigid paraboloid punch on the bottom face (uz ≥ d − r²/(2R)), 10 load steps. Contrast cases: Young's modulus 10³ times larger for x < 0.5, so the contact zone crosses the interface. CG with rtol 10−8, GAMG defaults, rigid body modes. petsc4py prototypes, MPICH, one 32-core machine. Total time in seconds, Krylov iterations in parentheses: variant linear 353k dof, 8 ranks linear, contrast 10³ 353k dof, 8 ranks linear, contrast 10³ 824k dof, 16 ranks neo-Hookean, contrast 10³ 353k dof, 8 ranks RSLS + GAMG, default 192.9 (3420) RSLS + GAMG + rigid body modes (!9886) 115.3 (583) 123.5 (806) 308.4 (1154) 277.1 (1537) A 35.5 (576) 49.4 (832) 133.3 (1124) 113.3 (1600) B 41.8 (576) 57.1 (832) 150.2 (1124) 125.5 (1600) * A and B give the same Krylov and Newton iterations and the same contact force. A is 11–15% faster here, partly because B pays a Python callback per Krylov iteration; in C they should be closer. * The diagonal matters. Replacing Jii by 1, by 100, or by the mean of diag(J) costs 3% to 87% more iterations. Truncating the finest interpolation on the active set removes this sensitivity, but with Jii it brings no further gain, so GAMG itself needs no change. * The reused interpolation was enough in these tests (no rebuild needed over 53 Newton iterations in the neo-Hookean case). Questions 1. Do you prefer A (in RSLS) or B (as a PC)? Could it later become the default for iterative PCs? 2. Should the option have its own rule for rebuilding the hierarchy, or are existing mechanisms enough (e.g. -snes_lag_preconditioner, or an explicit reset)? 3. For A: RSLS already works on copies. A would keep one full-size copy of Pmat, updated in place. Should Amat be a shell applying ΠI J ΠI + DA (ΠI = 0/1 projection on the inactive set), which would also cover matrix-free Jacobians? And is there an existing operation that zeroes off-diagonal row and column entries while keeping the original diagonal? I used MatZeroRowsColumns() followed by MatDiagonalSet(). 4. How should this coexist with the DM path (DMCreateInterpolation_SNESVI())? I would keep the option off when PCMG takes its interpolation from the DM. 5. Where should a small vector-valued VI test go? ex9 is scalar. Limitations: one machine with poor parallel scaling (4 to 8 ranks gives only about 20%); axis-aligned obstacle, no friction; with strong material drift the reused interpolation degrades (in earlier 2D tests with large deformations a rebuild was needed about 12 times in 253 solves); the full space also works on the active rows, which costs little only while the active set is small. Separately, RSLS needs 44 Newton iterations against 30 for a penalty method on the neo-Hookean case; line search types and SNESVINEWTONSSLS (74) do not close this gap. Scripts and raw data are available on request. Best regards, Luca Viggiano I prepared the prototypes and measurements with the help of an AI assistant (Claude). I have reviewed the code and the results and I am responsible for them.
