Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symmetric scaling #46

Open
amontoison opened this issue Jan 26, 2024 · 1 comment
Open

Add symmetric scaling #46

amontoison opened this issue Jan 26, 2024 · 1 comment

Comments

@amontoison
Copy link
Member

No description provided.

@amontoison
Copy link
Member Author

@michel2323 @frapac @sshin23
I discussed with Mike about symmetric scaling and I quickly implemented a Julia version of his MATLAB code:

function scaleSID(A::SparseMatrixCSC, iprint::Bool=false)
    n, m = size(A)
    if iprint
        println("\n scaleSID: Symmetric scaling of SID matrix.   n = $n   nnz = $(nnz(A))")
    end
    if n != m
        println("A must be square")
        return nothing, nothing
    end

    scale = maximum(abs.(A), dims=1)[:]
    Iz = findall(scale .== 0)
    lenz = length(Iz)
    if lenz > 0
        println("A contains $lenz empty columns")
        scale[Iz] .= 1
    end

    d = diag(A)            # dense column vector
    scale .= 1.0 ./ scale  # dense column vector
    d .= scale .* d        # dense diagonal of DAD
    scale .= sqrt.(scale)  # dense elements of D
    D = Diagonal(scale)    # sparse diagonal D
    AL = tril(A, -1)
    AL2 = copy(AL)
    mul!(AL2, AL, D)
    mul!(AL, D, AL2)
    DAD = AL + AL' + spdiagm(0 => d)

    if iprint
        jmin = argmin(scale)
        jmax = argmax(scale)
        smin = scale[jmin]
        smax = scale[jmax]
        println("\n\n  Min scale                     Max scale")
        println("  Col $jmin $smin    Col $jmax $smax")
    end

    return DAD, D
end

I tested with Krylov methods and it's quite efficient!
It should not be hard to do a GPU version and add it in MadNLP.jl.

Related issue: MadNLP/MadNLP.jl#294

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant