|
1 | 1 | # routines that implement different preconditioners
|
2 | 2 |
|
3 |
| -export ic02!, ic02, ilu02!, ilu02 |
| 3 | +export ic02!, ic02, ilu02!, ilu02, gtsv2!, gtsv2 |
4 | 4 |
|
5 | 5 | """
|
6 |
| - ic02!(A::CuSparseMatrix, index::SparseChar) |
| 6 | + ic02!(A::CuSparseMatrix, index::SparseChar='O') |
7 | 7 |
|
8 | 8 | Incomplete Cholesky factorization with no pivoting.
|
9 | 9 | Preserves the sparse layout of matrix `A`.
|
10 | 10 | """
|
11 |
| -ic02!(A::CuSparseMatrix, index::SparseChar) |
| 11 | +function ic02! end |
| 12 | + |
| 13 | +""" |
| 14 | + ilu02!(A::CuSparseMatrix, index::SparseChar='O') |
| 15 | +
|
| 16 | +Incomplete LU factorization with no pivoting. |
| 17 | +Preserves the sparse layout of matrix `A`. |
| 18 | +""" |
| 19 | +function ilu02! end |
| 20 | + |
| 21 | +""" |
| 22 | + gtsv2!(dl::CuVector, d::CuVector, du::CuVector, B::CuVecOrMat, index::SparseChar='O'; pivoting::Bool=true) |
| 23 | +
|
| 24 | +Solve the linear system `A * X = B` where `A` is a tridiagonal matrix defined |
| 25 | +by three vectors corresponding to its lower (`dl`), main (`d`), and upper (`du`) diagonals. |
| 26 | +With `pivoting`, the solution is more accurate but also more expensive. |
| 27 | +Note that the solution `X` overwrites the right-hand side `B`. |
| 28 | +""" |
| 29 | +function gtsv2! end |
| 30 | + |
| 31 | +# csric02 |
12 | 32 | for (bname,aname,sname,elty) in ((:cusparseScsric02_bufferSize, :cusparseScsric02_analysis, :cusparseScsric02, :Float32),
|
13 | 33 | (:cusparseDcsric02_bufferSize, :cusparseDcsric02_analysis, :cusparseDcsric02, :Float64),
|
14 | 34 | (:cusparseCcsric02_bufferSize, :cusparseCcsric02_analysis, :cusparseCcsric02, :ComplexF32),
|
@@ -88,13 +108,7 @@ for (bname,aname,sname,elty) in ((:cusparseScsric02_bufferSize, :cusparseScsric0
|
88 | 108 | end
|
89 | 109 | end
|
90 | 110 |
|
91 |
| -""" |
92 |
| - ilu02!(A::CuSparseMatrix, index::SparseChar) |
93 |
| -
|
94 |
| -Incomplete LU factorization with no pivoting. |
95 |
| -Preserves the sparse layout of matrix `A`. |
96 |
| -""" |
97 |
| -ilu02!(A::CuSparseMatrix, index::SparseChar) |
| 111 | +# csrilu02 |
98 | 112 | for (bname,aname,sname,elty) in ((:cusparseScsrilu02_bufferSize, :cusparseScsrilu02_analysis, :cusparseScsrilu02, :Float32),
|
99 | 113 | (:cusparseDcsrilu02_bufferSize, :cusparseDcsrilu02_analysis, :cusparseDcsrilu02, :Float64),
|
100 | 114 | (:cusparseCcsrilu02_bufferSize, :cusparseCcsrilu02_analysis, :cusparseCcsrilu02, :ComplexF32),
|
@@ -280,3 +294,49 @@ for elty in (:Float32, :Float64, :ComplexF32, :ComplexF64)
|
280 | 294 | end
|
281 | 295 | end
|
282 | 296 | end
|
| 297 | + |
| 298 | +# gtsv2 |
| 299 | +for (bname_pivot,fname_pivot,bname_nopivot,fname_nopivot,elty) in ((:cusparseSgtsv2_bufferSizeExt, :cusparseSgtsv2, :cusparseSgtsv2_nopivot_bufferSizeExt, :cusparseSgtsv2_nopivot, :Float32), |
| 300 | + (:cusparseDgtsv2_bufferSizeExt, :cusparseDgtsv2, :cusparseDgtsv2_nopivot_bufferSizeExt, :cusparseDgtsv2_nopivot, :Float64), |
| 301 | + (:cusparseCgtsv2_bufferSizeExt, :cusparseCgtsv2, :cusparseCgtsv2_nopivot_bufferSizeExt, :cusparseCgtsv2_nopivot, :ComplexF32), |
| 302 | + (:cusparseZgtsv2_bufferSizeExt, :cusparseZgtsv2, :cusparseZgtsv2_nopivot_bufferSizeExt, :cusparseZgtsv2_nopivot, :ComplexF64)) |
| 303 | + @eval begin |
| 304 | + function gtsv2!(dl::CuVector{$elty}, d::CuVector{$elty}, du::CuVector{$elty}, B::CuVecOrMat{$elty}, index::SparseChar='O'; pivoting::Bool=true) |
| 305 | + ml = length(dl) |
| 306 | + m = length(d) |
| 307 | + mu = length(du) |
| 308 | + mB = size(B,1) |
| 309 | + (m ≤ 2) && throw(DimensionMismatch("The size of the linear system must be at least 3.")) |
| 310 | + !(ml == m == mu) && throw(DimensionMismatch("(dl, d, du) must have the same length, the size of the vectors is ($ml,$m,$mu)!")) |
| 311 | + (m != mB) && throw(DimensionMismatch("The tridiagonal matrix and the right-hand side B have inconsistent dimensions ($m != $mB)!")) |
| 312 | + n = size(B,2) |
| 313 | + ldb = max(1,stride(B,2)) |
| 314 | + |
| 315 | + function bufferSize() |
| 316 | + out = Ref{Csize_t}(1) |
| 317 | + if pivoting |
| 318 | + $bname_pivot(handle(), m, n, dl, d, du, B, ldb, out) |
| 319 | + else |
| 320 | + $bname_nopivot(handle(), m, n, dl, d, du, B, ldb, out) |
| 321 | + end |
| 322 | + return out[] |
| 323 | + end |
| 324 | + with_workspace(bufferSize) do buffer |
| 325 | + if pivoting |
| 326 | + $fname_pivot(handle(), m, n, dl, d, du, B, ldb, buffer) |
| 327 | + else |
| 328 | + $fname_nopivot(handle(), m, n, dl, d, du, B, ldb, buffer) |
| 329 | + end |
| 330 | + end |
| 331 | + B |
| 332 | + end |
| 333 | + end |
| 334 | +end |
| 335 | + |
| 336 | +for elty in (:Float32, :Float64, :ComplexF32, :ComplexF64) |
| 337 | + @eval begin |
| 338 | + function gtsv2(dl::CuVector{$elty}, d::CuVector{$elty}, du::CuVector{$elty}, B::CuVecOrMat{$elty}, index::SparseChar='O'; pivoting::Bool=true) |
| 339 | + gtsv2!(dl, d, du, copy(B), index; pivoting) |
| 340 | + end |
| 341 | + end |
| 342 | +end |
0 commit comments