--- name: multigrid-design-notes description: "Design, development and tuning of LQCD multigrid solvers for physical-mass Möbius DWF on Frontier (AMD MI250X); covers HDCG, PVdagM two-level solver, coarse operator performance, and Lüscher deflation of the coarse solve" metadata: node_type: memory type: project originSessionId: cc1844e3-ab6f-4425-bf7e-a091b9554290 --- # LQCD Multigrid: Design, Development and Tuning ## Physical problem Physical-mass Möbius DWF: Ls=24, b=1.5, c=0.5, M5=1.8, mass=0.00078. 48³×96 lattice. MPI geometry 3.6.4.4 (288 ranks / GCDs on Frontier). Target: accelerate HMC fermion force and CG solves. ## Two solver paths ### Path 1: HDCG (TwoLevelADEF2 on MdagM) - File: `examples/Example_mdagm.cc` - Operator: MdagM (Hermitian positive definite); outer solver is ADEF2 CG. - Subspace: 60 near-null vectors via CG inverse iteration (`CreateSubspace`). - Coarse geometry: block {4,4,3,4}, coarse lattice 12×12×16×24, Ls_coarse=1. - Coarse operator: `GeneralCoarsenedMatrix` (Petrov-Galerkin, npoint=33, NextToNearestStencil). - Smoother: fixed-iteration CG on shifted operator (M†M + lo), lo=hi/80, 20 iters. - Coarse solve: CG with DeflatedGuesser using 60 chi deflation vectors. - Chi vectors: extracted BEFORE block-GS by diagonalising W_ij=<ψ_i|M†M|ψ_j>, computing chi_k = Σ_i V[i,k] ψ_i. These are global near-null combinations; block-GS destroys this. - Deflation effect: 1089 coarse CG iters (undeflated) → 329 with 60 chi vectors. - Best result: 274 outer ADEF2 iters, ~400s on 288 ranks Frontier. - Coarse MVM performance: 541.7 GFlop/s kernel, 1119.6 GB/s (70% HBM), 97% roofline. MPI latency = 1188 μs = 37% of 3.2 ms per coarse MVM call. Single-RHS is bandwidth-bound. ### Path 2: PVdagM two-level PGCR - File: `examples/Example_pvdagm.cc` and `examples/Example_pvdagm_defl.cc` - Operator: PVdagM = PV†M (non-Hermitian); outer solver is PGCR. - PV is the Pauli-Villars (mass=1) Möbius operator. PVdagM has exact zero modes. - Subspace: 60 near-null vectors via GCR inverse iteration (`CreateSubspaceGCR`). GCR setup is slow: each vector takes O(600) PGCR steps, total ~4100s setup on Frontier. - Coarse geometry: block 2^4 (lattice halved each dim), Ls_coarse=1. - Coarse operator: `GeneralCoarsenedMatrix` with non-Hermitian coarsening. - Preconditioner: `MGPreconditioner` V-cycle (pre-smooth, project, coarse solve, promote, post-smooth). - Smoother: PGCR on ShiftedPVdagM (shift=0.01). - Baseline (no deflation, 5e-2 coarse tol): 59 outer iters, 300s solve time. Coarse solve: 4.58s/call, 250 PGCR steps, NEVER converges ("did not converge" every call). - Outer iteration count vs coarse tolerance: 5e-2→59 iters, 1e-1→63 iters, 3e-2→34 iters. But at 3e-2 without deflation: 1000+ coarse PGCR steps per call (useless). ## Key implementation work: GeneralCoarsenedMatrix performance `Grid/algorithms/multigrid/GeneralCoarsenedMatrix.h`: 1. **accelerator_barrier fix**: `acceleratorBarrier()` is not a Grid macro; correct call is `accelerator_barrier(dummy)` (takes a dummy argument). This caused SIGBUS on Frontier. 2. **Coalesced FT kernel**: In `CoarsenOperator`, the loop filling A_v[sss](i,j) was serialised over j. Changed to: ```cpp accelerator_for(sss, osites, nbasis, { int j = acceleratorSIMTlane(nbasis); A_v[sss](i,j) = FT_v[sss](j); }); ``` This gives coalesced HBM access (nbasis consecutive elements per warp lane). 3. **Batched CoarsenOperator**: Used `MultiRHSBlockProject` to batch all npoint=33 stencil directions in one GEMM call per basis vector, replacing serial blockProject calls. Reduced projection from dominant bottleneck to 12% of CoarsenOperator time. mat (linop applications) now dominates at 83%. ## Lüscher deflation of the coarse solve (Example_pvdagm_defl.cc) ### Theory (Lüscher arXiv:0706.2298, Section A.3) For near-null vectors {ψ_s} of operator D, the Petrov-Galerkin initial guess is: guess = Ψ W⁻¹ Ψ† src where W_st = <ψ_s|D|ψ_t> and Ψ is the matrix of ψ columns. Condition <ψ_s | src - D*guess> = 0 gives W c = b, b_t = <ψ_t|src>. No SVD needed — W is dense, invert directly (LU). The U,V from SVD are unitaries within the ψ-basis and cancel in W⁻¹; direct inverse is cleaner. ### Diagnostic results (job 4948520, before deflation) Fine projected matrix W (60×60): - ||W|| = 0.02399 — near-null vectors are genuinely small. - Singular values: range [0.00169, 0.00529], ratio ~3:1. Well-conditioned inverse. Coarse null matrix C_kl =
:
- ||C|| = 0.02399 — **identical to ||W||**. Galerkin property is exact.
- ||C - C†|| / ||C|| = 2.59e-9 — **C is Hermitian to machine precision**.
Despite PVdagM being non-Hermitian, the projected coarse matrix is numerically Hermitian.
- C singular values match W singular values exactly (coarsening faithful).
This means: the coarse near-null vectors (projections of fine ψ_k) are exact near-null
vectors of the coarse operator, AND the deflation can use a Hermitian eigensolver.
### Implementation
**CoarseDeflatedGuesser** (in Example_pvdagm_defl.cc, before MGPreconditioner):
```cpp
template