kryst
High-performance Krylov subspace and preconditioned iterative solvers for dense and sparse linear systems, with shared and distributed memory parallelism.
Features
Solvers
- Krylov Methods: GMRES, BiCGStab, CG, PCG, MINRES, CGS, QMR, TFQMR, CGNR
- Advanced Variants: Flexible GMRES (FGMRES), Pipelined Communication-Avoiding GMRES (PCA-GMRES)
- Direct Methods: LU and QR factorization via PREONLY solver type
- Parallel Implementations: Shared-memory (Rayon) and distributed-memory (MPI) support
Preconditioners
- Basic: Jacobi (diagonal scaling), Block Jacobi, SOR/SSOR
- Incomplete Factorizations: ILU(0), ILU(k), ILUT, ILUP
- Polynomial: Chebyshev smoothing
- Multilevel: Algebraic Multigrid (AMG)
- Domain Decomposition: Additive Schwarz Method (ASM)
- Approximate Inverse: SPAI-type approximate inverse
Architecture
- PETSc-style API: Unified KSP context for runtime solver selection
- Command-line Options: Complete options database like PETSc
- Trait-based Design: Extensible for custom matrices and preconditioners
- Memory Efficiency: In-place operations and configurable storage
- High Performance: Optimized inner kernels with SIMD and parallelization
Installation
Add to your Cargo.toml:
[]
= "0.6"
Feature Flags
[]
= ["rayon"] # Shared-memory parallelism
= ["dep:rayon"] # Rayon-based parallel execution
= ["dep:mpi"] # Distributed-memory parallelism via MPI
= ["dep:log"] # Iteration monitoring and profiling
Quick Start
Basic Solver Usage
use GmresSolver;
use ;
// Set up your matrix A and vectors b, x
let mut solver = new;
let stats = solver.solve.unwrap;
println!;
PETSc-style Unified Interface
use KspContext;
// Configure solver and preconditioner at runtime
let mut ksp = new;
ksp.set_type_from_str?
.set_pc_type_from_str?
.set_tolerances;
let stats = ksp.solve?;
Command-line Options (PETSc-style)
use parse_all_options;
use KspContext;
// Parse command-line options
let args: = args.collect;
let = parse_all_options?;
// Configure from options
let mut ksp = new;
ksp.set_from_all_options?;
let stats = ksp.solve?;
Run your program with PETSc-style options:
Supported Command-line Options
KSP (Krylov Solver) Options
-ksp_type <solver>- Solver type:cg,pcg,gmres,fgmres,bicgstab,cgs,qmr,tfqmr,minres,cgnr,preonly-ksp_rtol <float>- Relative convergence tolerance (default: 1e-6)-ksp_atol <float>- Absolute convergence tolerance (default: 1e-12)-ksp_dtol <float>- Divergence tolerance (default: 1e3)-ksp_max_it <int>- Maximum number of iterations (default: 1000)-ksp_gmres_restart <int>- GMRES restart parameter (default: 50)-ksp_pc_side <side>- Preconditioning side:left,right,symmetric
PC (Preconditioner) Options
-pc_type <pc>- Preconditioner type:jacobi,ilu0,ilu,ilut,ilup,chebyshev,amg,asm,lu,qr,none-pc_ilu_levels <int>- ILU fill levels (default: 0)-pc_chebyshev_degree <int>- Chebyshev polynomial degree (default: 3)-pc_ilut_drop_tol <float>- ILUT drop tolerance (default: 1e-3)-pc_ilut_max_fill <int>- ILUT maximum fill per row (default: 10)
Usage Examples
# GMRES with Jacobi preconditioning
# Direct LU solver (single iteration)
# Direct QR solver (single iteration)
# CG solver with ILU(0) preconditioning
# BiCGStab with no preconditioning
# GMRES with AMG preconditioning
# Flexible GMRES with ILUT preconditioning
Monitoring and Profiling
Iteration Monitoring
Register callbacks to track solver progress at each iteration:
use ;
let mut ksp = new;
// Register a monitor to print iteration progress
ksp.add_monitor;
// Register multiple monitors for different purposes
let max_residual = new;
let max_residual_clone = clone;
ksp.add_monitor;
ksp.set_type?
.set_pc_type?;
let stats = ksp.solve?;
Profiling and Logging
Enable detailed timing information with the logging feature:
[]
= { = "0.7", = ["logging"] }
Run with environment variable to see detailed profiling:
# Trace-level logging shows detailed stage timing
RUST_LOG=trace
# Debug-level shows major operations
RUST_LOG=debug
# Info-level shows high-level progress
RUST_LOG=info
Profiling output includes:
- KSPSetup: Preconditioner setup and workspace allocation timing
- KSPSolve: Complete solve time breakdown
- PCSetup: Individual preconditioner setup timing
- WorkspaceAllocation: Memory allocation timing
- KSPSolveKrylov: Core iteration timing
Monitor Management
// Check number of active monitors
println!;
// Clear all monitors
ksp.clear_monitors;
// Add monitors conditionally
if debug_mode
Solver Details
Krylov Methods
- GMRES: Generalized Minimal Residual with restart
- FGMRES: Flexible GMRES for variable preconditioning
- PCA-GMRES: Pipelined Communication-Avoiding GMRES
- BiCGStab: Bi-Conjugate Gradient Stabilized
- CG/PCG: Conjugate Gradient (preconditioned)
- MINRES: Minimal Residual for symmetric indefinite systems
- CGS: Conjugate Gradient Squared
- QMR/TFQMR: Quasi-Minimal Residual methods
- CGNR: CG on Normal Equations
Direct Methods
- PREONLY: Single-step direct solve using LU or QR factorization
- Supports both
-pc_type luand-pc_type qr - Ideal for well-conditioned systems where direct methods are preferred
Preconditioners
- Jacobi: Diagonal scaling
M⁻¹ = diag(A)⁻¹ - Block Jacobi: Block-wise diagonal inverse
- ILU(k): Incomplete LU with k levels of fill
- ILUT: ILU with threshold dropping
- ILUP: ILU with partial pivoting
- SOR/SSOR: Successive Over-Relaxation methods
- Chebyshev: Polynomial smoothing
- AMG: Algebraic Multigrid (V-cycle)
- ASM: Additive Schwarz Method (overlapping domain decomposition)
Performance Features
Parallelization
- Shared Memory: Rayon-based parallel execution for matrix operations, vector operations, and preconditioner application
- Distributed Memory: MPI support for distributed linear algebra operations
- Communication Avoiding: PCA-GMRES reduces communication costs in parallel environments
- SIMD Optimization: Leverages hardware acceleration through optimized inner kernels
Memory Management
- In-place Operations: Minimizes memory allocations during iteration
- Configurable Storage: Preallocated vs. dynamic storage options
- Block Operations: Efficient cache usage through blocked algorithms
- Sparse Patterns: Memory-efficient storage for sparse matrices and preconditioners
Matrix Support
Dense Matrices
- Full support via
faer::Mat<T>integration - Optimized BLAS-like operations
- Multiple precision types (f32, f64, complex)
Sparse Matrices
- CSR/CSC format support
- Efficient sparse matrix-vector products
- Pattern-based optimization for preconditioners
Custom Matrices
- Trait-based
MatVecinterface - Support for matrix-free methods
- Easy integration of custom matrix types
Examples
The library includes several demonstration programs:
# Basic options demonstration
# Direct solver examples
# Convergence behavior analysis
# Setup and reuse patterns
Benchmarks
Performance benchmarks are available via:
Includes comparisons between:
- Different solver types (GMRES vs BiCGStab vs CG)
- Preconditioner effectiveness
- Direct vs iterative methods
- Serial vs parallel performance
Extensions and Custom Components
Custom Solvers
use LinearSolver;
use MatVec;
Custom Preconditioners
use ;
Documentation and Resources
- API Documentation - Complete API reference
- Repository - Source code and issues
- Examples - Demonstration programs
- Benchmarks - Performance comparisons
References
- Saad, Y. (2003). Iterative Methods for Sparse Linear Systems, 2nd Edition. SIAM.
- Barrett, R. et al. (1994). Templates for the Solution of Linear Systems. SIAM.
- PETSc Documentation: https://petsc.org/release/documentation/
Testing
Run the comprehensive test suite:
# All tests
# Specific test categories
# With parallel features
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Clone the repository
- Install Rust (stable toolchain recommended)
- Optional: Install MPI library for distributed features
- Run tests:
cargo test - Run benchmarks:
cargo bench
Areas for Contribution
- Additional solver algorithms (e.g., LOBPCG, IDR)
- New preconditioner types (e.g., multigrid variants)
- GPU acceleration (CUDA/OpenCL backends)
- Additional matrix formats (coordinate, block sparse)
- Performance optimizations
- Documentation improvements
kryst aims to provide a comprehensive, high-performance linear algebra toolkit for the Rust ecosystem, with particular focus on iterative methods for large-scale scientific computing applications.