-
-
Notifications
You must be signed in to change notification settings - Fork 79
Fix SUNDIALS v7.4 Krylov solver segfaults on macOS #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add missing SUNContext parameter to Krylov iterative linear solver constructors. SUNDIALS 7.x requires a SUNContext parameter for thread safety, but the Julia wrappers were calling these functions with only 3 parameters, causing immediate segmentation faults on macOS. Affected solvers: - SUNLinSol_SPGMR (GMRES) - SUNLinSol_SPFGMR (FGMRES) - SUNLinSol_SPBCGS (BCG) - SUNLinSol_PCG (PCG) - SUNLinSol_SPTFQMR (TFQMR) Changes: - Update all Krylov solver calls in src/simple.jl to pass ctx parameter - Update all Krylov solver calls in src/common_interface/solve.jl for CVODE, CVODES, IDA - Fix library wrapper definitions in lib/libsundials_api.jl to include SUNContext in ccall This resolves segmentation faults when using Krylov solvers with KINSOL, CVODE, and IDA on macOS with SUNDIALS v7.4. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
@ViralBShah Mac should be fine now. Not sure how other tests worked without it 😅 but the memory context is local now on those. |
|
Still failing on mac. I have been using Julia 1.11.6 (but fails on 1.10 and 1.12 as well): |
|
Minimal reproducer: |
|
Tests on mac pass on my computer, and pass in #489 |
|
The SUNSparseMatrix constructors are missing the Suncontext in the sundials_api. I don't quite understand why it is working on linux and CI, but it is probably getting lucky with some default code paths. I am able to consistently crash with that one liner on my mac. |
|
It is interesting that it doesn't consistently segfault, but it can if the context is missing. This new SunContext is pretty silly. |
|
Since we are calling it with fewer arguments, it is either somehow getting a context luckily or NULL is acceptable or something else that is acceptable is getting picked up. |
…UNContext parameter ## Problem SUNSparseMatrix constructors were missing the required SUNContext parameter in their ccall, causing segmentation faults on macOS when using functions like: - Sundials.SUNSparseMatrix(3, 3, 3, Sundials.CSC_MAT) ## Root Cause The underlying SUNDIALS 7.x library requires a SUNContext parameter for SUNSparseMatrix constructors, but the Julia wrapper was: 1. Missing SUNContext in the ccall signature 2. Not creating a proper context for non-context versions 3. Had incorrect comments claiming SUNSparseMatrix doesn't need context ## Solution - Updated primary constructor to include SUNContext parameter in ccall - Modified non-context version to create and use a proper SUNContext - Fixed wrapper functions to properly pass context parameter - Removed incorrect comments and duplicate function definitions ## Testing - Verified SUNSparseMatrix(3, 3, 3, Sundials.CSC_MAT) no longer segfaults - Confirmed test suite handle_tests.jl now passes - Maintains backward compatibility for existing code Fixes segmentation fault reported in SciML#488 (comment) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
This PR fixes segmentation faults that occur when using Krylov iterative linear solvers with SUNDIALS v7.4 on macOS.
Problem
The Julia wrappers for SUNDIALS Krylov solvers were missing the required
SUNContextparameter introduced in SUNDIALS 6.0+. This caused immediate segmentation faults on macOS when attempting to use GMRES, FGMRES, BCG, PCG, or TFQMR linear solvers with KINSOL, CVODE, or IDA.Solution
SUNContextparameter to all Krylov solver constructor callsChanges Made
Files Modified:
src/simple.jl- Addedctxparameter to all Krylov solver constructors in KINSOL interfacesrc/common_interface/solve.jl- Addedctxparameter for CVODE, CVODES, and IDA Krylov solver callslib/libsundials_api.jl- Fixed ccall signatures to include SUNContext parameterAffected Solvers:
SUNLinSol_SPGMR(GMRES)SUNLinSol_SPFGMR(FGMRES)SUNLinSol_SPBCGS(BCG)SUNLinSol_PCG(PCG)SUNLinSol_SPTFQMR(TFQMR)Testing
Tested on macOS (Darwin 24.6.0, Apple Silicon) with SUNDIALS v7.4.1:
✅ All 5 Krylov solvers now work with KINSOL
✅ All 5 Krylov solvers now work with CVODE
✅ All 5 Krylov solvers now work with IDA
✅ No more segmentation faults
Test script confirming all solvers work:
Impact
This fix is critical for macOS users as it resolves crashes when using any Krylov iterative solver. The changes are backward compatible and follow the SUNDIALS 7.x API requirements.
Fixes segmentation faults reported when running test suite on macOS with SUNDIALS v7.4.
🤖 Generated with Claude Code