Replace Pinv default with BackslashSolver for better performance and Windows compatibility#121
Conversation
…Windows compatibility This PR replaces the problematic `Pinv` default coarse solver with a new `BackslashSolver` that uses Julia's built-in `factorize()` and backslash operator, providing: ## Benefits - **Preserves sparsity**: No conversion to dense matrices - **Better performance**: Uses appropriate sparse factorizations (UMFPACK, CHOLMOD, etc.) - **Windows compatibility**: Eliminates LAPACK errors from `pinv` calls - **Simpler code**: Much cleaner than LinearSolve.jl wrappers - **Better accuracy**: Direct factorization vs pseudoinverse ## Changes - Add `BackslashSolver` implementation using `factorize(A)` and `A \ b` - Change default from `Pinv` to `BackslashSolver` in both Ruge-Stuben and Smoothed Aggregation - Add comprehensive tests for `BackslashSolver` - Deprecate `Pinv` with warning about inefficiency - Keep `Pinv` available for backward compatibility ## Fixes - Resolves SciML/Sundials.jl#496 (Windows LAPACK errors) - Dramatically improves memory usage and performance for coarse solves - Makes the default behavior much more intuitive for Julia users 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Why was this using |
pinv is the default on the coarse level, because for general matrices I am not against changing the defaults here, I just want to make sure that you are aware this might cause downstream issues. The failing test can be fixed by forcing these to use Pinv. |
|
but you can force a column-pivoted qr or svd factorization for that, without building the pinv. |
|
Just some more comment here, we have never run into the case when Pinv became even remotely a bottleneck, yet. I guess an alternative to this PR would be to
We still need to check if that is sufficient to be useful to get the solver for larger non-symmetric problems on track. What do you think @ChrisRackauckas ? |
|
@ChrisRackauckas-Claude Incorporate the comments above, fix the failing tests and resolve the merge conflict. |
|
Smoother interface fix is on the way here #125 . |
There was a problem hiding this comment.
@ChrisRackauckas-Claude please rebase and address the comments.
Note that we trade robustness for performance by changing the default. Note that we cannot fully guarantee here for some positive semidefinite matrix as input that the coarse matrix does not become slightly indefinite.
|
|
||
| !!! warning "Deprecated" | ||
| This solver converts sparse matrices to dense and computes the full pseudoinverse, | ||
| which is very inefficient. Consider using `BackslashSolver` instead. |
There was a problem hiding this comment.
| !!! warning "Deprecated" | |
| This solver converts sparse matrices to dense and computes the full pseudoinverse, | |
| which is very inefficient. Consider using `BackslashSolver` instead. |
pinv is fine for some corner cases. We should keep it.
There was a problem hiding this comment.
Please pass Pinv to the failing solver tests. This should fix these.
Summary
This PR replaces the problematic
Pinvdefault coarse solver with a newBackslashSolverthat uses Julia's built-infactorize()and backslash operator. This provides much better performance, preserves sparsity, and fixes Windows LAPACK compatibility issues.Problem
The current default coarse solver
Pinvhas serious issues:Matrix(A)destroys sparsity, causing memory explosionSolution
The new
BackslashSolver:factorize(A)which automatically chooses appropriate sparse factorizations (UMFPACK, CHOLMOD, etc.)A \ bImplementation
Changes
BackslashSolverimplementationPinvtoBackslashSolverin Ruge-Stuben and Smoothed AggregationBackslashSolverPinvwith performance warning (kept for backward compatibility)Testing
BackslashSolverhandles multiple RHS correctlyPerformance Impact
The new default should provide:
Backward Compatibility
Pinvis still available for users who explicitly request itFixes
This change makes AlgebraicMultigrid.jl's default behavior much more appropriate for sparse linear algebra and aligns with Julia's excellent built-in capabilities.
🤖 Generated with Claude Code