GeezerVison is showing github.com — Check LWORK against the blocked code's workspace for every NH in xGGHD3 by rmlarsen · Pull Request #1504 · Reference-LAPACK/lapack
Conversation
AI disclosure: This PR was prepared with Claude Code.
Summary
xGGHD3 runs its blocked code with less workspace than it needs. Its documented minimum is LWORK >= 1, but for 32 < NH <= 128 it uses about 6*N*NB entries of WORK whatever LWORK is. DGGHD3 with LWORK = 1 writes 2079 words past WORK for N = 33 and 3080 words for N = 40, and for N = 100 it stops in XERBLA inside DORM22 (parameter 12). xGGEV3 and xGGES3 hand xGGHD3 the rest of their own WORK, so they overrun in the same way at their documented minimum LWORK. With the LWORK returned by a workspace query there is no overrun.
Description
When LWORK < LWKOPT = 6*N*NB, xGGHD3 is meant to reduce NB or fall back to the unblocked code. That check sat inside IF( NX.LT.NH ), with NX = MAX( NB, ILAENV( 3, ... ) ). ILAENV returns NB = 32 and NX = 128, so for 32 < NH <= 128 the check is skipped, and since NB.GE.NH is false, the blocked code runs with the full NB.
xGEHRD has the same NB/NX/LWORK structure, but there NX is the crossover bound of its block loop, so for NX >= NH nothing blocked runs. In xGGHD3 the block loop covers the whole matrix and NX is used for nothing but this check.
Fix
The workspace check now runs whenever NB.GT.1 .AND. NB.LT.NH, and the unused NX is removed. For NX >= NH with enough workspace the blocked code is still used, exactly as before, so results for calls with enough workspace are unchanged; switching those calls to the unblocked code would change roundoff and performance for 32 < NH <= 128. The same change is made in sgghd3.f, dgghd3.f, cgghd3.f and zgghd3.f. No *> change is needed: LWORK >= 1 is now correct as documented.
Reproducer
program repro
implicit none
integer, parameter :: n = 40, lwork = 1, nguard = 100000
double precision, parameter :: s = -7.77d77
double precision :: a(n,n), b(n,n), q(n,n), z(n,n)
double precision, allocatable :: w(:)
integer :: i, j, info
call random_number(a)
call random_number(b)
do j = 1, n
do i = j+1, n
b(i,j) = 0
end do
end do
allocate(w(lwork+nguard))
w = s
call dgghd3('V', 'V', n, 1, n, a, n, b, n, q, n, z, n, w, lwork, info)
print '(a,i0,a,i0)', 'info = ', info, ', words written past WORK(LWORK): ', &
count(w(lwork+1:) /= s)
end program repro
On master: info = 0, words written past WORK(LWORK): 3080. With this change: info = 0, words written past WORK(LWORK): 0.
Regression test
Test 14 of xDRGES3 (the SGS, DGS, CGS and ZGS paths) sets NB = 4, NBMIN = 2 and NX = N+1 through XLAENV and calls xGGHD3 directly, with LWORK = 1 and then MIN( 18*N, LWORK ). The rest of WORK is a guard that must stay unchanged. The test also checks INFO, that S is upper Hessenberg and T upper triangular, the residuals of A = Q S Z' and B = Q T Z', and the orthogonality of Q and Z. It restores NB, NBMIN and NX afterwards.
The suite did not reach the blocked xGGHD3 before: the GS and GV paths run with NB = 1, so xGGES3 and xGGEV3 always used the unblocked code. On master, 104 of the 1820 tests of each of the SGS, DGS, CGS and ZGS runs (sgd.in, dgd.in, cgd.in, zgd.in) fail, all of them test 14, for N = 6, 10, 12 and 20. With this change they pass, as do the other tests of those runs (the GS driver runs report 1560 and 1820 tests and the GV driver runs 1092 in each precision).
The test takes the number 14 and leaves the existing RESULT( 13 ) alone, so NTEST becomes 14 and each matrix now adds two to the "tests run" count: the new test and slot 13, which the real drivers never compute and which therefore always passes. The totals of the SGS, DGS, CGS and ZGS runs grow by 2 per matrix; the full suite's LAPACK total grows by 1040 per API. For N = 0 the test calls xGGHD3 with LWORK = 1, and a copy of dgd.in with 0 added to the GS sizes passes in all four precisions with no XERBLA message. The test list in the header of xDRGES3 now describes tests 13 and 14.
The test is in xDRGES3 rather than xDRGEV3, and it calls xGGHD3 directly rather than through xGGES3, so that it does not depend on xLAQZ0 (see below).
Test suite
The full test suite passes, configured as in CI (CBLAS=ON, LAPACKE=ON, LAPACKE_WITH_TMG=ON) with the _64 API. All 333 CTest entries pass, with 5756228 LAPACK tests (5756230 for the _64 API), 11973112 LAPACKE tests, 319677 BLAS tests and 645492 CBLAS tests for each API, and 0 numerical errors and 0 other errors. That is 1040 LAPACK tests more per API than on master, the tests added here. A second build with CI's gfortran flags (-O2 -Wall -Wno-unused-dummy-argument -Wno-unused-variable -Wno-unused-label -Werror=conversion -fimplicit-none -frecursive -fcheck=all) passes the suite as well, and the changed files compile with the same warnings as on master. The builds used GNU Fortran and GCC 15.2.0 with CMAKE_BUILD_TYPE=Release on x86-64 Linux.
Not changed here
xLAQZ0 needs much more than its documented LWORK for N of roughly 75 and above, so xGGEV3 and xGGES3 at their documented minimum LWORK (8*N and 6*N+16) also stop in XERBLA inside xLAQZ0 for large N. That is a separate defect, handled on another branch, and it is why the test above calls xGGHD3 directly.
CDRGES3 and ZDRGES3 store the failure of their SDIM check (test 12) in RESULT( 13 ), which is never printed. With test 14 added, the printing loop now covers RESULT( 13 ) as well, so a failure of that check would now be reported as "result 13". Nothing in the suite triggers it. I left the slip alone.
Checklist
- The documentation has been updated. (Not needed:
xGGHD3 now does what it documents, LWORK >= 1.)
- If the PR solves a specific issue, it is set to be closed on merge. (No tracking issue.)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
xGGHD3 reduces the blocksize NB, or falls back to unblocked code, when
LWORK < LWKOPT = 6*N*NB. That check was nested inside IF( NX.LT.NH ),
with NX = MAX( NB, ILAENV( 3, ... ) ). With ILAENV's NB = 32 and
NX = 128, any 32 < NH <= 128 skipped the check, and because NB.GE.NH
is false there, the blocked code ran with the full NB and its 6*N*NB
workspace whatever LWORK was. The documented minimum is LWORK >= 1.
DGGHD3 with LWORK = 1 wrote 2079 words past WORK for N = 33 and 3080
words for N = 40, and for N = 100 stopped in XERBLA inside DORM22
(parameter 12). xGGEV3 and xGGES3 pass xGGHD3 the workspace left in
their own WORK, so they overran the same way when called with their
documented minimum LWORK. With the LWORK returned by a workspace query
there was no overrun.
Unlike xGEHRD, where NX is the crossover bound of the block loop, NX
was used here only to gate this check; the block loop covers the whole
matrix. The check now runs whenever NB.GT.1 .AND. NB.LT.NH, and the
unused NX is removed. With enough workspace the blocked code is still
used for NH <= NX, exactly as before, so results for such calls are
unchanged. Switching to unblocked code there would change roundoff and
performance for 32 < NH <= 128, which is not wanted here. The same
change is made in the s, c and z versions.
Found by calling xGGHD3 with a guard region after LWORK.
Test: test 14 of xDRGES3 (all four precisions, DGS/SGS/CGS/ZGS paths)
sets NB = 4, NBMIN = 2 and NX = N+1 and calls xGGHD3 directly with
LWORK = 1 and with MIN( 18*N, LWORK ). The rest of WORK is a guard that
must stay unchanged. It also checks INFO, that S is upper Hessenberg and
T upper triangular, and the residuals of A = Q S Z' and B = Q T Z' and
the orthogonality of Q and Z. On the parent commit 104 of the 1820
tests of each of the DGS, SGS, CGS and ZGS runs of sgd.in, dgd.in,
cgd.in and zgd.in fail, all of them test 14, for N = 6, 10, 12 and 20;
with this change they pass. Test 14 leaves the unused slot 13 of
RESULT alone, so each matrix now adds two to the tests-run count.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This was referenced Nov 22, 2026
codecov
Bot
commented
Nov 22, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
❌ Patch coverage is 92.66055% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.68%. Comparing base (ef55c9b) to head (1fc2a21).
✅ All tests successful. No failed tests found.
Additional details and impacted files

@@ Coverage Diff @@
## master #1504 +/- ##
==========================================
+ Coverage 70.63% 70.68% +0.04%
==========================================
Files 6243 6243
Lines 501290 501472 +182
Branches 23516 23516
==========================================
+ Hits 354100 354478 +378
+ Misses 146327 146131 -196
Partials 863 863
... and 4 files with indirect coverage changes
Continue to review full report in Codecov by Harness.
Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef55c9b...1fc2a21. Read the comment docs.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|