Skip to content

Commit

Permalink
Try to keep a reference to permutation
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Apr 6, 2024
1 parent 9b04271 commit af2430f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/MadNLPGPU/src/cudss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SparseArrays
# Use LDLᵀ by default in CUDSS as Cholesky can lead to undefined behavior.
cudss_algorithm::MadNLP.LinearFactorization = MadNLP.LDL
ordering::ORDERING = DEFAULT_ORDERING
permutation::Vector{Cint} = Cint[]
end

mutable struct CUDSSSolver{T} <: MadNLP.AbstractLinearSolver{T}
Expand Down Expand Up @@ -49,15 +50,16 @@ function CUDSSSolver(
if opt.ordering == AMD_ORDERING
A = SparseMatrixCSC(csc)
G = Metis.graph(A, check_hermitian=false)
perm, iperm = Metis.permutation(G)
cudss_set(solver, "user_perm", perm)
opt.perm, _ = Metis.permutation(G)
elseif opt.ordering == METIS_ORDERING
A = SparseMatrixCSC(csc)
perm = AMD.amd(A)
cudss_set(solver, "user_perm", perm)
opt.perm = AMD.amd(A)
elseif opt.ordering == USER_ORDERING
(!isempty(opt.perm) && isperm(opt.perm)) || error("The vector opt.perm is not a valable permutation.")
else
error("The ordering $(opt.ordering) is not supported.")
end
cudss_set(solver, "user_perm", opt.perm)
end

x_gpu = CUDA.zeros(T, n)
Expand Down
1 change: 1 addition & 0 deletions lib/MadNLPGPU/src/cusolverrf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ MadNLP.introduce(M::GLUSolver) = "GLU"
DEFAULT_ORDERING = 0
METIS_ORDERING = 1
AMD_ORDERING = 2
USER_ORDERING = 3
end
@kwdef mutable struct CuCholeskySolverOptions <: MadNLP.AbstractOptions
ordering::ORDERING = METIS_ORDERING
Expand Down

0 comments on commit af2430f

Please sign in to comment.