Skip to content

small_kkt_large_factor: k = 50 only with MKL Pardiso, k = 10 elsewhere - #561

Merged
bodono merged 1 commit into
masterfrom
claude/faster-small-kkt-test
Nov 24, 2026
Merged

bodono merged 1 commit into
masterfrom
claude/faster-small-kkt-test

Conversation

@bodono

@bodono bodono commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

small_kkt_large_factor (#538) exists for one branch of the MKL Pardiso backend, but every backend solved its 2500 x 2500 instance. It now solves k = 50 (n = m = 2500) only with MKL Pardiso, and the same problem at k = 10 (n = m = 100) everywhere else.

Request (maintainer, 2026-11-24): "Let's make the valgrind test faster as you suggest".

Why

  • What the test is for. With MKL Pardiso, a KKT matrix below PARDISO_MIN_THREADED_NNZ (5e4 nonzeros) gets its symbolic phase on one thread. If the factor Pardiso then reports (iparm[17]) has 5e4 nonzeros or more, the handle is released and the symbolic phase is redone on MKL's threads (linsys/mkl/direct/private.c). The test checks that the solve is still right after that. No other backend has this branch.
  • What it cost. On master 82a5383f it took 10.3 of the Valgrind job's 27.2 minutes (dense 478 s, CG 137 s, QDLDL 2 s), more than any other test there. The job had taken 11-13 minutes before MKL Pardiso: run small linear systems on one thread #538 merged. It also took about 23 s of the Windows dense step's 28-32 s (inferred from a gap in the log, because Windows output is fully buffered), and 12.3 s of the simulated GPU CG run's 61 s.

What changes

Only test/problems/small_kkt_large_factor.h changes:

  • k = strstr(scs_get_lin_sys_method(), "mkl") ? 50 : 10. The backend is fixed when the test binary is linked, so each binary always runs the same instance. Other tests already branch on the method string this way. Only sparse-direct-mkl-pardiso contains "mkl".
  • The residual line now prints the backend and k (small_kkt_large_factor: sparse-direct-mkl-pardiso, k = 50: ...), so the MKL jobs' logs show which instance ran.
  • The comment explains each size, with the numbers below.

No other test, workflow or setting changes, and MU_TOTAL_TESTS stays the same.

Why MKL keeps k = 50

The branch needs two things: the KKT matrix below 5e4 nonzeros, and Pardiso's factor at or above 5e4. The KKT matrix has 7k^2 - 4k nonzeros, which is below 5e4 up to k = 84. The factor comes from Pardiso's own nested dissection ordering (iparm[1] = 3). That cannot be computed without MKL, and it can change with the MKL version. Here is AMD's factor, computed with SCS's bundled AMD on the same pattern:

k KKT nnz AMD factor nnz (with diagonal)
10 660 1,908
34 7,956 48,882
35 8,435 51,632
50 17,300 127,040

By AMD, the smallest k that takes the branch is 35. Pardiso's ordering is different, so its smallest k cannot be derived here. Keeping k = 50 keeps #538's exact instance, with a margin of about 2.5x over the threshold. MKL is not run under Valgrind or on Windows in CI, so the large instance costs nothing in those jobs.

What k = 10 loses on the other backends

Nothing measured:

  • Coverage on the Mac. We compared clang source-based coverage of src/ and linsys/ for the whole suite, master against this branch. QDLDL, CG, dense and Accelerate each cover the same library lines (6140, 5196, 4778 and 4854), and no branch that was taken before is lost.
  • Size rules of the other backends. The only one is cuDSS's CUDSS_MIN_PRODUCT_NNZ. Both sizes (660 and 17,300 KKT nonzeros) fall on the same side of it at its default (6e4) and in the CI build that sets it to 0. GPU CG has no size rule.

Measurements

Mac M4 with Apple clang: median of 3 interleaved runs, with per-test times from line timestamps.

backend test before (s) test after (s) suite before (s) suite after (s)
QDLDL 0.037 0.0002 0.84 0.80
CG 0.934 0.0021 6.34 5.44
dense 1.228 0.0003 2.24 0.98
Accelerate 0.052 0.0005 1.09 1.06

Expected in CI: the Valgrind/Mac ratios measured per test on master are about 55-75x for QDLDL, 45-145x for CG and 400-1000x for dense. At those ratios the test costs under 1 s under Valgrind. Measured in this PR's CI: the Valgrind job took 14m42s (PR run) and 16m48s (push run), against 27.2 min on master, and the Windows dense step took 8 s or less, against 28-32 s.

Verification

  • Mac (clang): all suites pass on QDLDL, CG, dense and Accelerate. They also pass with DLONG=1 (QDLDL, CG, dense), with the clang++ build, and with SFLOAT, where the test is skipped as before. There are no new warnings.
  • Selection: we made a scratch build in which the QDLDL method string contained "mkl". It ran k = 50, which passed.
  • MKL: not built locally (Apple Silicon). The MKL instance is unchanged, so it detects whatever it detected before. This PR's Build and Test MKL and Build and Test OpenMP with MKL jobs print sparse-direct-mkl-pardiso, k = 50 (residual 3.2e-15, as before). The CMake MKL jobs also run it, through ctest, which prints nothing for passing tests.
  • Mutation check: not run, because it needs MKL. MKL Pardiso: run small linear systems on one thread #538 added the branch together with the test, so the test has no failing state from before MKL Pardiso: run small linear systems on one thread #538. Mutants of the branch itself, such as reusing the handle without clearing it after the release, only run with MKL, where this PR leaves the instance as it was.

🤖 Generated with Claude Code

The test is there for MKL Pardiso's PARDISO_MIN_THREADED_NNZ branch (#538):
the symbolic phase is redone on MKL's threads when a small KKT matrix has a
large factor. Only MKL has that branch, but every backend solved the
2500 x 2500 instance. Under Valgrind that was 10.3 of the job's 27 minutes
(478 s dense, 137 s CG, 2 s QDLDL), and about 23 s of the Windows dense
step.

MKL Pardiso keeps k = 50: the KKT matrix has 1.7e4 nonzeros and AMD's factor
1.27e5, a 2.5x margin over the 5e4 threshold for Pardiso's own ordering,
which the test cannot see. The other backends solve the same problem at
k = 10. The backend is fixed at link time (scs_get_lin_sys_method, as other
tests use it). On the Mac the suite covers the same library lines and
branches with either size on QDLDL, CG, dense and Accelerate, and the test
takes under 3 ms on each (was 37, 934, 1228 and 52 ms). The residual line
now prints the backend and k, so the MKL jobs' logs show k = 50.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bodono
bodono marked this pull request as ready for review November 24, 2026 18:44
@bodono
bodono merged commit 769782f into master Nov 24, 2026
95 checks passed
@bodono
bodono deleted the claude/faster-small-kkt-test branch November 24, 2026 18:44
bodono added a commit that referenced this pull request Nov 24, 2026
master adds #558 (eigCG deflation in the GPU indirect solver, shared
linsys/eigcg.{c,h}, test_deflation.h) and #561 (small_kkt_large_factor
size per backend).

One conflict, test/run_tests.c MU_TOTAL_TESTS: this branch had 108 (106 +
test_g_rollback, test_factor_rollback), master 109 (106 + test_eigcg_gram_factor,
test_eigcg_core, test_lin_sys_deflation). Both sides' tests are kept, so it is
111, the number of mu_run_test calls in all_tests(). Everything else merged
without conflict (docs/src/linear_solver/index.rst, include/glbopts.h: the
two sides edit different paragraphs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant