Skip to content

Correct the thread-safety docs and stress test separate factorizations - #42

Merged
ViralBShah merged 2 commits into
mainfrom
global-libklu-lock
Oct 31, 2026
Merged

ViralBShah merged 2 commits into
mainfrom
global-libklu-lock

Conversation

@ViralBShah

@ViralBShah ViralBShah commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Corrects the thread-safety docs and strengthens the stress test for separate factorizations. It changes no behaviour.

Changes

  • Docs: they said that batching right-hand sides into one solve! call runs them in parallel, but that call runs on one thread. Solving in parallel takes a factorization per task, such as copy(F), and the docs now give that cost. This is in the README, docs/src/index.md, and the klu docstring.
  • README: adds the sections on reusing and checking a factorization from Test more error paths and refactorization, and update the docs #54, which only went into docs/src/index.md.
  • Stress test: the test for separate factorizations factored once and then solved, with Float64 values and one index type. It now also refactors and repeatedly factors and frees, for each element and index type, with finalizers running meanwhile. It stays in the existing concurrency testset.
  • Formatting: adds the missing space in isok =$call from Fix crashes on unfactored objects and bad permutations, and keep the singular status #53.

History

Refs #38. This PR originally added a process-wide lock around every libklu call, so the earlier comments here are about that. The lock has been removed because it stopped separate factorizations from running in parallel, with 2,814 solves/s against 23,217 at 8 threads, and SparseArrays.jl has no such lock either. The code is preserved in d79cbd5 in case a repro shows that it's needed.

Testing

The full suite passes locally on Linux with Julia 1.13 at -t 1, -t 4 and -t 8, and on 1.10 at -t 2. Aqua and the docs build also pass.

The stress test guards against regressions. It passes without any source change, so it doesn't show a new bug.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.31%. Comparing base (92f6b8f) to head (0d0ea27).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #42   +/-   ##
=======================================
  Coverage   97.31%   97.31%           
=======================================
  Files           1        1           
  Lines         372      372           
=======================================
  Hits          362      362           
  Misses         10       10           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ViralBShah

Copy link
Copy Markdown
Member Author

Review fix in 4dd6047. When the lock was busy, the finalizer re-registered itself and only retried after a later GC. Under contention it kept failing, and the GC cannot see libklu memory: factor-and-discard on all 8 threads reached 12.5 GB in 30s on Linux, against about 600 MB on main. That contradicts the "memory growth matches main" line in the description. The finalizer now hands the free to a task that waits for the lock, and memory stays at about 570 MB.

Not fixed, and one more reason to keep this as a draft: ReentrantLock is not fair. With 7 tasks solving in a loop, a task that was factoring finished 5 factorizations in 30s, against 573 on main.

@ViralBShah
ViralBShah marked this pull request as ready for review October 30, 2026 21:13
@ViralBShah ViralBShah changed the title Serialize all libklu calls with a global lock Test concurrent use of separate factorizations, and correct the thread-safety docs Oct 31, 2026
@ViralBShah ViralBShah changed the title Test concurrent use of separate factorizations, and correct the thread-safety docs Correct the thread-safety docs and stress test separate factorizations Oct 31, 2026
ViralBShah and others added 2 commits October 31, 2026 04:30
…d-safety docs

Extend the stress test of separate factorizations to analyze, factor, refactor, solve, and free,
for each element and index type, with finalizers running meanwhile.

Batching right-hand sides into one call doesn't run them in parallel, as the docs said. Only
giving each task its own factorization does.

Refs #38.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ViralBShah
ViralBShah merged commit 62685a7 into main Oct 31, 2026
8 checks passed
@ViralBShah
ViralBShah deleted the global-libklu-lock branch October 31, 2026 04:33
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