High-performance implementation, mathematical convergence analysis, and Numba JIT acceleration of iterative algorithms (Jacobi, Gauss-Seidel, Gradient Descent, Conjugate Gradient) for solving large sparse linear systems
$Ax = b$ .
- Project Overview
- Mathematical Foundation & Solvers
- Numba JIT Acceleration
- Benchmark Sparse Matrices
- Execution & Experiments
- Repository Structure
- Authors & Academic Context
Solving large, sparse linear systems of equations of the form:
This project investigates iterative solvers across two implementations:
- Baseline Implementation: Vectorized routines built on SciPy Compressed Sparse Row (
csr_matrix) structures. - Numba JIT-Accelerated Implementation: Low-level, cache-friendly C-speed loops compiled via
@njitleveraging multi-threaded sparse matrix-vector kernels.
Let
Updates each unknown using only values from the previous iteration:
- Highly parallelizable since component updates are decoupled.
- Converges if
$A$ is strictly diagonally dominant.
Immediately uses updated components within the current iteration:
- Typically exhibits twice the asymptotic convergence rate of Jacobi for positive-definite systems.
Applicable when
Steps along the negative gradient (residual
Searches along
- Theoretical convergence in at most
$n$ iterations (in exact arithmetic). - Highly effective for ill-conditioned sparse systems when combined with preconditioning.
Iterative solvers with forward/backward triangular sweeps (like Gauss-Seidel) cannot be easily vectorized with pure NumPy because of sequential loop dependencies.
The linear_solvers/numba/ implementation compiles explicit loops over the CSR indices (row_ptr, col_indices, data) directly to native machine instructions via LLVM, delivering speedups of 10x to 50x over pure Python implementations.
The repository includes real-world and synthetic sparse benchmark matrices stored in Matrix Market format (.mtx in data/):
| Matrix | Origin / Application | Dimensions ( |
Non-Zeros ( |
Properties |
|---|---|---|---|---|
vem1.mtx |
Virtual Element Method | Discretization mesh 1 | Sparse | SPD, Poisson equation |
vem2.mtx |
Virtual Element Method | Refined mesh 2 | Large sparse | SPD, high condition number |
spa1.mtx |
Structural Analysis | Structural mesh 1 | Sparse | Symmetric |
spa2.mtx |
Structural Analysis | Structural mesh 2 | Highly sparse | Symmetric |
The suite inspects structural properties:
- Spectral radius
$\rho(B)$ of the iteration matrix - Condition number
$\kappa(A)$ - Non-zero density (
$nnz / n^2$ ) - Relative residual convergence:
$|b - A x_k|_2 / |b|_2 \le \text{tol}$
git clone https://github.com/mbroglio/sparse-linear-solvers.git
cd sparse-linear-solvers
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt- Run Baseline Solvers:
python3 runner/run_baseline.py
- Run Numba JIT Solvers:
python3 runner/run_numba.py
- Analyze Matrix Properties:
python3 runner/matrix_analysis.py
- Generate Convergence & Performance Plots:
python3 runner/generate_plots.py
├── Assignment1_Report.pdf # Full academic report (PDF)
├── README.md # Project documentation (English)
├── pyproject.toml # Project configuration
├── requirements.txt # Python dependencies (NumPy, SciPy, Numba, Matplotlib)
│
├── data/ # Sparse Matrix Market test files (.mtx)
│ ├── vem1.mtx
│ ├── vem2.mtx
│ ├── spa1.mtx
│ └── spa2.mtx
│
├── linear_solvers/ # Core solver implementations
│ ├── baseline/ # Vectorized SciPy/NumPy implementations
│ │ ├── base.py # Abstract solver base class
│ │ └── iterative_methods.py # Jacobi, Gauss-Seidel, Gradient, CG
│ └── numba/ # JIT-compiled accelerated implementations
│ ├── base.py
│ └── iterative_methods.py # Fast CSR loop solvers
│
└── runner/ # Experiment runners and evaluation tools
├── run_baseline.py # Baseline benchmark runner
├── run_numba.py # Numba accelerated benchmark runner
├── matrix_analysis.py # Matrix condition and spectral analysis
├── generate_plots.py # Matplotlib convergence curve exporter
├── plot_results.py # Comparative visualization tools
└── results/ # Stored metrics, CSVs, and generated plots
Project developed for the Scientific Computing Methods (Metodi del Calcolo Scientifico) course (Academic Year 2025/2026), Master's Degree in Computer Science, Università degli Studi di Milano - Bicocca:
- Matteo Broglio - Matricola
899562 - Lorenzo Caputo - Matricola
894528 - Daniel Giuggioli - Matricola
894415
Full report available in Assignment1_Report.pdf.