Skip to content

Conversation

ChrisRackauckas-Claude
Copy link

Summary

This PR replaces the problematic Pinv default coarse solver with a new BackslashSolver that uses Julia's built-in factorize() and backslash operator. This provides much better performance, preserves sparsity, and fixes Windows LAPACK compatibility issues.

Problem

The current default coarse solver Pinv has serious issues:

Solution

The new BackslashSolver:

  • Preserves sparsity: Uses factorize(A) which automatically chooses appropriate sparse factorizations (UMFPACK, CHOLMOD, etc.)
  • Better performance: Pre-factorizes once, solves efficiently with A \ b
  • Windows compatible: No problematic LAPACK calls
  • Intuitive: Uses Julia's excellent built-in linear algebra
  • Memory efficient: No dense matrix storage

Implementation

struct BackslashSolver{T,F} <: CoarseSolver
    factorization::F
    function BackslashSolver{T}(A) where T
        fact = factorize(A)  # Auto-picks best factorization
        new{T,typeof(fact)}(fact)
    end
end

function (solver::BackslashSolver)(x, b)
    for i  1:size(b, 2)
        x[:, i] = solver.factorization \ b[:, i]  # Efficient solve
    end
end

Changes

  • ✅ Add BackslashSolver implementation
  • ✅ Change default from Pinv to BackslashSolver in Ruge-Stuben and Smoothed Aggregation
  • ✅ Add comprehensive tests for BackslashSolver
  • ✅ Deprecate Pinv with performance warning (kept for backward compatibility)

Testing

  • ✅ All existing tests pass with new default
  • BackslashSolver handles multiple RHS correctly
  • ✅ Works with different element types (Float32, Float64)
  • ✅ Resolves the Windows LAPACK issue from Sundials.jl
  • ✅ Much better performance and memory usage

Performance Impact

The new default should provide:

  • Dramatically lower memory usage (no dense matrices)
  • Much faster coarse solves (sparse factorizations vs pseudoinverse)
  • Better numerical stability (proper factorizations vs pseudoinverse)

Backward Compatibility

  • Pinv is still available for users who explicitly request it
  • All existing APIs unchanged
  • Only the default coarse solver changes

Fixes

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

…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 <[email protected]>
@ChrisRackauckas
Copy link
Member

Why was this using pinv 😅 that is why it wasn't benchmarking well, and had so many other issues.

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.

Test failures on windows
2 participants