Skip to content

Fix per-thread workspace overlap with user-supplied work[] (lwork > 0) - #1

Merged
xiaoyeli merged 1 commit into
masterfrom
claude/nifty-noether-m4f0vh
Oct 5, 2026
Merged

xiaoyeli merged 1 commit into
masterfrom
claude/nifty-noether-m4f0vh

Conversation

@xiaoyeli

@xiaoyeli xiaoyeli commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Summary

Port of xiaoyeli/superlu_mt#36 (merged) to the macro base file trunk/SRC/pxmemory.base, so the fix is not lost the next time the precision-dependent sources are regenerated.

Problem

When the caller supplies work[] (lwork > 0), each factorization thread allocates its private iwork/dwork from the TAIL of that stack in p@(pre)gstrf_WorkInit(). But p@(pre)gstrf_WorkFree() reset the whole TAIL (stack.top2 = stack.size) as soon as any one thread finished, releasing the work arrays of threads still running. A thread that started afterwards then got TAIL memory overlapping a live thread's marker[]/dense[] and overwrote them during its ifill()/@(pre)fill() initialization. The result was spurious zero pivots: the intermittent failures in p[cz]test_4_{10,19}_2_100000000_LA reported in xiaoyeli/superlu_mt#34.

Fix

  • p@(pre)gstrf_WorkInit() counts the threads holding TAIL work arrays (nwork_users), under the existing stack lock.
  • p@(pre)gstrf_WorkFree() resets the TAIL only when that count drops to 0.
  • The counter is reset wherever the user stack is (re)initialized: p@(pre)gstrf_SetupSpace() and the refactorization path in p@(pre)gstrf_MemInit().

Verification

The extract tool is not available in my environment, so I did not regenerate the .c files here. Instead I compared the added/removed lines of this diff against the diffs of all four merged files (SRC/p{s,d,c,z}memory.c in superlu_mt commit 2d564a6): they are identical in every case. The changed lines contain no precision macros, so extraction will produce exactly the files already merged in superlu_mt. Stress-test results for the fix itself are in xiaoyeli/superlu_mt#36.

Only trunk/ is changed, per the README. The copy under SuperLU_MT_base-branch/SRC/pxmemory.base is left as is.

🤖 Generated with Claude Code

https://claude.ai/code/session_017GsYX7J15S6uvtUoRMWYwi


Generated by Claude Code

Port of xiaoyeli/superlu_mt#36 to the macro base file. When the caller
supplies work[] (lwork > 0), each factorization thread allocates its
private iwork/dwork from the TAIL of that stack in p@(pre)gstrf_WorkInit(),
but p@(pre)gstrf_WorkFree() reset the whole TAIL (top2 = size) as soon as
any one thread finished, releasing the work arrays of threads that were
still running. A thread that started afterwards then got TAIL memory
overlapping a live thread's marker[]/dense[] and overwrote them during
its ifill()/@(pre)fill() initialization, producing spurious zero pivots
(intermittent failures in p[cz]test_4_{10,19}_2_100000000_LA).

Count the threads holding TAIL work arrays and reset the TAIL only when
the last one frees its arrays. The added lines contain no precision
macros, so the extracted p{s,d,c,z}memory.c match the files merged in
superlu_mt exactly.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GsYX7J15S6uvtUoRMWYwi
@xiaoyeli
xiaoyeli merged commit aa9d13b into master Oct 5, 2026
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.

2 participants