|
| 1 | +# routines that implement reorderings |
| 2 | + |
| 3 | +export color |
| 4 | + |
| 5 | +""" |
| 6 | + color(A::CuSparseMatrixCSC, index::SparseChar; percentage::Number=1.0) |
| 7 | + color(A::CuSparseMatrixCSR, index::SparseChar; percentage::Number=1.0) |
| 8 | +
|
| 9 | +This function performs the coloring of the adjacency graph associated with the matrix A. |
| 10 | +The coloring is an assignment of colors (integer numbers) to nodes, such that neighboring nodes have distinct colors. |
| 11 | +An approximate coloring algorithm is used in this routine, and is stopped when a certain percentage of nodes has been colored. |
| 12 | +The rest of the nodes are assigned distinct colors (an increasing sequence of integers numbers, starting from the last integer used previously). |
| 13 | +The reordering is such that nodes that have been assigned the same color are reordered to be next to each other. |
| 14 | +
|
| 15 | +The matrix A passed to this routine, must be stored as a general matrix and have a symmetric sparsity pattern. |
| 16 | +If the matrix is non-symmetric the user should pass A + Aᵀ as a parameter to this routine. |
| 17 | +""" |
| 18 | +function color end |
| 19 | + |
| 20 | +for (fname, subty, elty) in ((:cusparseScsrcolor, :Float32, :Float32), |
| 21 | + (:cusparseDcsrcolor, :Float64, :Float64), |
| 22 | + (:cusparseCcsrcolor, :Float32, :ComplexF32), |
| 23 | + (:cusparseZcsrcolor, :Float64, :ComplexF64)) |
| 24 | + @eval begin |
| 25 | + function color(A::Union{CuSparseMatrixCSR{$elty},CuSparseMatrixCSC{$elty}}, index::SparseChar; percentage::Number=1.0) |
| 26 | + desc = CuMatrixDescriptor('G', 'L', 'N', index) |
| 27 | + m, n = size(A) |
| 28 | + (m != n) && throw(DimensionMismatch("A must be square, but has dimensions ($m,$n)!")) |
| 29 | + |
| 30 | + info = cusparseColorInfo_t[0] |
| 31 | + cusparseCreateColorInfo(info) |
| 32 | + |
| 33 | + ncolors = Ref{Cint}(-1) |
| 34 | + coloring = CuVector{Cint}(undef, m) |
| 35 | + reordering = CuVector{Cint}(undef, m) |
| 36 | + |
| 37 | + if isa(A, CuSparseMatrixCSR) |
| 38 | + $fname(handle(), m, nnz(A), desc, nonzeros(A), A.rowPtr, A.colVal, Ref{$subty}(percentage), ncolors, coloring, reordering, info[1]) |
| 39 | + else |
| 40 | + $fname(handle(), m, nnz(A), desc, nonzeros(A), A.colPtr, A.rowVal, Ref{$subty}(percentage), ncolors, coloring, reordering, info[1]) |
| 41 | + end |
| 42 | + cusparseDestroyColorInfo(info[1]) |
| 43 | + ncolors[], coloring, reordering |
| 44 | + end |
| 45 | + end |
| 46 | +end |
0 commit comments