-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[documentation] Iterative refinement and user permutation
- Loading branch information
1 parent
6e7eb01
commit 3a091bc
Showing
3 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
## Iterative refinement | ||
|
||
```julia | ||
using CUDA, CUDA.CUSPARSE | ||
using CUDSS | ||
using LinearAlgebra | ||
using SparseArrays | ||
|
||
T = Float64 | ||
n = 100 | ||
p = 5 | ||
A_cpu = sprand(T, n, n, 0.01) | ||
A_cpu = A_cpu + I | ||
B_cpu = rand(T, n, p) | ||
|
||
A_gpu = CuSparseMatrixCSR(A_cpu) | ||
B_gpu = CuMatrix(B_cpu) | ||
X_gpu = similar(B_gpu) | ||
|
||
solver = CudssSolver(A_gpu, "G", 'F') | ||
|
||
# Perform one step of iterative refinement | ||
ir = 1 | ||
cudss_set(solver, "ir_n_steps", ir) | ||
|
||
cudss("analysis", solver, X_gpu, B_gpu) | ||
cudss("factorization", solver, X_gpu, B_gpu) | ||
cudss("solve", solver, X_gpu, B_gpu) | ||
|
||
R_gpu = B_gpu - CuSparseMatrixCSR(A_cpu) * X_gpu | ||
norm(R_gpu) | ||
``` | ||
|
||
## User permutation | ||
|
||
```julia | ||
using CUDA, CUDA.CUSPARSE | ||
using CUDSS | ||
using LinearAlgebra | ||
using SparseArrays | ||
using AMD | ||
|
||
T = ComplexF64 | ||
n = 100 | ||
A_cpu = sprand(T, n, n, 0.01) | ||
A_cpu = A_cpu' * A_cpu + I | ||
b_cpu = rand(T, n) | ||
|
||
A_gpu = CuSparseMatrixCSR(A_cpu) | ||
b_gpu = CuVector(b_cpu) | ||
x_gpu = similar(b_gpu) | ||
|
||
solver = CudssSolver(A_gpu, "HPD", 'F') | ||
|
||
# Provide a user permutation | ||
permutation = amd(A_cpu) |> Vector{Cint} | ||
cudss_set(solver, "user_perm", permutation) | ||
|
||
cudss("analysis", solver, x_gpu, b_gpu) | ||
cudss("factorization", solver, x_gpu, b_gpu) | ||
cudss("solve", solver, x_gpu, b_gpu) | ||
|
||
r_gpu = b_gpu - CuSparseMatrixCSR(A_cpu) * x_gpu | ||
norm(r_gpu) | ||
``` |