Skip to content

Commit c7bf2ed

Browse files
Sébastien LoiselSébastien Loisel
authored andcommitted
Update documentation with correct type signatures
- SparseMatrixMPI now shows all 3 type parameters: {T,Ti,AV} - VectorMPI and MatrixMPI show array type parameter - CLAUDE.md updated with current struct fields (rowptr, colval, nzval) - MUMPSFactorizationMPI shows {Tin,AVin,Tinternal} parameters - Remove obsolete test_gpu.jl reference (tests now parameterized) - Fix internal API references (_get_csc instead of A.A.parent)
1 parent 9d5ac82 commit c7bf2ed

4 files changed

Lines changed: 32 additions & 23 deletions

File tree

CLAUDE.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ mpiexec -n 4 julia --project=. test/test_local_constructors.jl
2222
mpiexec -n 4 julia --project=. test/test_indexing.jl
2323
mpiexec -n 4 julia --project=. test/test_factorization.jl
2424

25-
# Run GPU tests (requires Metal.jl on macOS)
26-
mpiexec -n 2 julia --project=. test/test_gpu.jl
25+
# GPU tests run automatically when Metal.jl is available
26+
# Tests are parameterized over (scalar type, backend) configurations
2727

2828
# Precompile the package
2929
julia --project=. -e 'using Pkg; Pkg.precompile()'
@@ -37,7 +37,8 @@ GPU acceleration is supported via Metal.jl (macOS) as a package extension.
3737

3838
- `VectorMPI{T,AV}` where `AV` is `Vector{T}` (CPU) or `MtlVector{T}` (GPU)
3939
- `MatrixMPI{T,AM}` where `AM` is `Matrix{T}` (CPU) or `MtlMatrix{T}` (GPU)
40-
- Type aliases: `VectorMPI_CPU{T}`, `MatrixMPI_CPU{T}` for CPU-backed types
40+
- `SparseMatrixMPI{T,Ti,AV}` where `AV` is `Vector{T}` (CPU) or `MtlVector{T}` (GPU) for the `nzval` array
41+
- Type aliases: `VectorMPI_CPU{T}`, `MatrixMPI_CPU{T}`, `SparseMatrixMPI_CPU{T,Ti}` for CPU-backed types
4142

4243
### CPU Staging
4344

@@ -88,18 +89,21 @@ Many operations in this module are collective and should not be run on a subset
8889
- `SparseMatrixCSC(A::SparseMatrixCSR)` converts CSR to CSC representing the **same** matrix
8990
- For `B = SparseMatrixCSR(A)`, `B[i,j] == A[i,j]` (same matrix, different storage)
9091

91-
**SparseMatrixMPI{T}**
92+
**SparseMatrixMPI{T,Ti,AV}**
9293
- Rows are partitioned across MPI ranks
93-
- `A::SparseMatrixCSR{T,Int}`: Local rows in CSR format for efficient row-wise iteration
94-
- `A.parent` is the underlying CSC storage with shape `(length(col_indices), local_nrows)`
95-
- `A.parent.colptr` acts as row pointers for the CSR format
96-
- `A.parent.rowval` contains LOCAL column indices (1:length(col_indices)), not global
97-
- Storage is **compressed** to avoid hypersparse issues
94+
- Type parameters: `T` = element type, `Ti` = index type, `AV` = array type for values (`Vector{T}` or `MtlVector{T}`)
95+
- Local rows stored in CSR-like format with separate arrays:
96+
- `rowptr::Vector{Ti}` - row pointers (always CPU)
97+
- `colval::Vector{Ti}` - LOCAL column indices (1:ncols_compressed, always CPU)
98+
- `nzval::AV` - nonzero values (can be CPU or GPU)
99+
- `nrows_local::Int` - number of local rows
100+
- `ncols_compressed::Int` - = length(col_indices)
98101
- `row_partition`: Array of size `nranks + 1` defining which rows each rank owns (1-indexed boundaries)
99102
- `col_partition`: Array of size `nranks + 1` defining column partition (used for transpose operations)
100103
- `col_indices`: Sorted global column indices that appear in the local part (local→global mapping)
101104
- `structural_hash`: Optional Blake3 hash of the matrix structure (computed lazily via `_ensure_hash`)
102105
- `cached_transpose`: Cached materialized transpose (invalidated on modification)
106+
- `cached_symmetric`: Cached result of `issymmetric` check
103107

104108
**MatrixMPI{T,AM}**
105109
- Distributed dense matrix partitioned by rows across MPI ranks
@@ -139,9 +143,11 @@ Many operations in this module are collective and should not be run on a subset
139143

140144
Factorization uses MUMPS (MUltifrontal Massively Parallel Solver) with distributed matrix input (ICNTL(18)=3).
141145

142-
**MUMPSFactorizationMPI{T}** (internal type, not exported)
146+
**MUMPSFactorizationMPI{Tin, AVin, Tinternal}** (internal type, not exported)
143147
- Wraps a MUMPS object for distributed factorization
148+
- Type parameters: `Tin` = input element type, `AVin` = input array type, `Tinternal` = MUMPS-compatible type (Float64 or ComplexF64)
144149
- Created by `lu(A)` for general matrices or `ldlt(A)` for symmetric matrices
150+
- Automatically converts input to MUMPS-compatible types and back (e.g., Float32 GPU → Float64 CPU → solve → Float32 GPU)
145151
- Stores COO arrays (irn_loc, jcn_loc, a_loc) to prevent GC while MUMPS holds pointers
146152

147153
```julia
@@ -179,7 +185,7 @@ For `y = A * x` where `A::SparseMatrixMPI` and `x::VectorMPI`:
179185

180186
1. **Plan creation** (`VectorPlan` constructor): Uses `Alltoall` to exchange element request counts, then point-to-point to exchange indices
181187
2. **Value exchange** (`execute_plan!`): Point-to-point `Isend`/`Irecv` to gather `x[A.col_indices]` into a local `gathered` vector
182-
3. **Local computation**: Compute `transpose(A.A.parent) * gathered` (A.A.parent already uses local indices)
188+
3. **Local computation**: Compute `transpose(_get_csc(A)) * gathered` where `_get_csc(A)` reconstructs a SparseMatrixCSC from the internal CSR arrays
183189
4. **Result construction**: Result vector `y` inherits `A.row_partition`
184190

185191
Note: Uses `transpose()` (not adjoint `'`) to correctly handle complex values without conjugation.
@@ -195,7 +201,7 @@ Note: Uses `transpose()` (not adjoint `'`) to correctly handle complex values wi
195201

196202
### Lazy Transpose
197203

198-
`transpose(A)` returns `Transpose{T, SparseMatrixMPI{T}}` (lazy wrapper). Materialization happens automatically when needed:
204+
`transpose(A)` returns `Transpose{T, SparseMatrixMPI{T,Ti,AV}}` (lazy wrapper). Materialization happens automatically when needed:
199205
- `transpose(A) * transpose(B)``transpose(B * A)` (stays lazy)
200206
- `transpose(A) * B` or `A * transpose(B)` → materializes via `TransposePlan`
201207
- `SparseMatrixMPI(transpose(A))` → explicitly materialize the transpose (cached bidirectionally)

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Distributed sparse matrix and vector operations using MPI for Julia. This packag
1111

1212
## Features
1313

14-
- **Distributed sparse matrices** (`SparseMatrixMPI{T}`) with row-partitioning across MPI ranks
15-
- **Distributed dense vectors** (`VectorMPI{T}`) with flexible partitioning
14+
- **Distributed sparse matrices** (`SparseMatrixMPI{T,Ti,AV}`) with row-partitioning across MPI ranks
15+
- **Distributed dense vectors** (`VectorMPI{T,AV}`) with flexible partitioning
1616
- **Matrix-matrix multiplication** (`A * B`) with memoized communication plans
1717
- **Matrix-vector multiplication** (`A * x`, `mul!(y, A, x)`)
1818
- **Sparse direct solvers**: LU and LDLT factorization using MUMPS
@@ -106,7 +106,8 @@ v_gpu = VectorMPI_local(local_data)
106106
### How it works
107107

108108
- **Vectors**: `VectorMPI{T,AV}` where `AV` is `Vector{T}` (CPU) or `MtlVector{T}` (GPU)
109-
- **Matrices**: Currently remain on CPU; GPU vectors are staged through CPU for matrix operations
109+
- **Sparse matrices**: `SparseMatrixMPI{T,Ti,AV}` where `AV` determines storage for nonzero values
110+
- **Dense matrices**: `MatrixMPI{T,AM}` where `AM` is `Matrix{T}` (CPU) or `MtlMatrix{T}` (GPU)
110111
- **MPI communication**: Always uses CPU buffers (no Metal-aware MPI exists)
111112
- **Element type**: Metal requires `Float32` (no `Float64` support)
112113

docs/src/api.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,19 @@ io0
8181

8282
| Native Type | MPI Type | Description |
8383
|-------------|----------|-------------|
84-
| `Vector{T}` | `VectorMPI{T}` | Distributed vector |
85-
| `Matrix{T}` | `MatrixMPI{T}` | Distributed dense matrix |
86-
| `SparseMatrixCSC{T,Ti}` | `SparseMatrixMPI{T,Ti}` | Distributed sparse matrix |
84+
| `Vector{T}` | `VectorMPI{T,AV}` | Distributed vector |
85+
| `Matrix{T}` | `MatrixMPI{T,AM}` | Distributed dense matrix |
86+
| `SparseMatrixCSC{T,Ti}` | `SparseMatrixMPI{T,Ti,AV}` | Distributed sparse matrix |
87+
88+
The `AV` and `AM` type parameters specify the underlying storage (`Vector{T}`/`Matrix{T}` for CPU, `MtlVector{T}`/`MtlMatrix{T}` for Metal GPU).
8789

8890
### MPI to Native Conversions
8991

9092
| MPI Type | Native Type | Function |
9193
|----------|-------------|----------|
92-
| `VectorMPI{T}` | `Vector{T}` | `Vector(v)` |
93-
| `MatrixMPI{T}` | `Matrix{T}` | `Matrix(A)` |
94-
| `SparseMatrixMPI{T,Ti}` | `SparseMatrixCSC{T,Ti}` | `SparseMatrixCSC(A)` |
94+
| `VectorMPI{T,AV}` | `Vector{T}` | `Vector(v)` |
95+
| `MatrixMPI{T,AM}` | `Matrix{T}` | `Matrix(A)` |
96+
| `SparseMatrixMPI{T,Ti,AV}` | `SparseMatrixCSC{T,Ti}` | `SparseMatrixCSC(A)` |
9597

9698
## Supported Operations
9799

docs/src/guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ LinearAlgebraMPI provides three distributed types:
1010
|------|-------------|---------|
1111
| `VectorMPI{T,AV}` | Distributed vector | Row-partitioned |
1212
| `MatrixMPI{T,AM}` | Distributed dense matrix | Row-partitioned |
13-
| `SparseMatrixMPI{T,Ti}` | Distributed sparse matrix | Row-partitioned CSR |
13+
| `SparseMatrixMPI{T,Ti,AV}` | Distributed sparse matrix | Row-partitioned CSR |
1414

1515
The type parameters are:
1616
- `T`: Element type (`Float64`, `Float32`, `ComplexF64`, etc.)
17-
- `AV<:AbstractVector{T}`: Underlying storage for vectors (`Vector{T}` for CPU, `MtlVector{T}` for Metal GPU)
17+
- `AV<:AbstractVector{T}`: Underlying storage for vectors and sparse matrix values (`Vector{T}` for CPU, `MtlVector{T}` for Metal GPU)
1818
- `AM<:AbstractMatrix{T}`: Underlying storage for dense matrices (`Matrix{T}` for CPU, `MtlMatrix{T}` for Metal GPU)
1919
- `Ti`: Index type for sparse matrices (typically `Int`)
2020

0 commit comments

Comments
 (0)