Skip to content

Commit

Permalink
[MadNLPHSL] Use HSL.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Nov 24, 2023
1 parent 6d694cd commit 2bec55d
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 512 deletions.
7 changes: 3 additions & 4 deletions lib/MadNLPHSL/Project.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name = "MadNLPHSL"
uuid = "7fb6135f-58fe-4112-84ca-653cf5be0c77"
version = "0.4"
version = "0.4.0"

[deps]
HSL_jll = "017b0a0e-03f4-516a-9b91-836bbd1904dd"
HSL = "34c5aeac-e683-54a6-a0e9-6e0fdc586c50"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MadNLP = "2621e9c9-9eb4-46b1-8089-e8c72242dfb6"
OpenBLAS32_jll = "656ef2d0-ae68-5445-9ca0-591084a874a2"

[compat]
HSL = "0.4.2"
MadNLP = "0.5,0.6,0.7"
MadNLPTests = "0.3, 0.4"
OpenBLAS32_jll = "0.3"
julia = "1.6"

[extras]
Expand Down
9 changes: 5 additions & 4 deletions lib/MadNLPHSL/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
```julia
pkg> add MadNLPHSL
```
Obtain a license and download HSL_jll.jl from https://licences.stfc.ac.uk/product/julia-hsl.
Obtain a license and download HSL_jll.jl from https://licences.stfc.ac.uk/product/libhsl.

There are two versions available: LBT and OpenBLAS. LBT is the recommended option for Julia >= v1.9.
There are two versions available: LBT and OpenBLAS.
LBT is the recommended option for Julia ≥ v1.9.

Install this download into your current environment using:

Expand All @@ -13,9 +14,9 @@ import Pkg
Pkg.develop(path = "/full/path/to/HSL_jll.jl")
```

Alternatively, one can use a custom-compiled HSL library by overriding the HSL_jll articfact.
Alternatively, one can use a custom-compiled HSL library by overriding the `HSL_jll.jl` artifact.
This can be done by editing `~/.julia/artifacts/Overrides.toml`
```
# replace HSL_jll artifact /usr/local/lib/libhsl.so
# replace HSL_jll.jl artifact /usr/local/lib/libhsl.so
ecece3e2c69a413a0e935cf52e03a3ad5492e137 = "/usr/local"
```
15 changes: 4 additions & 11 deletions lib/MadNLPHSL/src/MadNLPHSL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@ import MadNLP: @kwdef, MadNLPLogger, @debug, @warn, @error,
introduce, factorize!, solve!, improve!, is_inertia, inertia, findIJ, nnz,
get_tril_to_full, transfer!, input_type, _madnlp_unsafe_wrap,
is_supported, default_options
import HSL_jll: libhsl
import LinearAlgebra, OpenBLAS32_jll

function __init__()
if VERSION v"1.9"
config = LinearAlgebra.BLAS.lbt_get_config()
if !any(lib -> lib.interface == :lp64, config.loaded_libs)
LinearAlgebra.BLAS.lbt_forward(OpenBLAS32_jll.libopenblas_path)
end
end
end
import HSL
import HSL: mc68_control, mc68_info, ma77_control, ma77_info, ma86_control, ma86_info, ma97_control, ma97_info

import LinearAlgebra

include("common.jl")
include("mc68.jl")
include("ma27.jl")
include("ma57.jl")
include("ma77.jl")
Expand Down
33 changes: 5 additions & 28 deletions lib/MadNLPHSL/src/ma27.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,30 @@ end


for (fa, fb, fc, typ) in [
(:ma27ad_,:ma27bd_,:ma27cd_,Float64),
(:ma27a_,:ma27b_,:ma27c_,Float32)
(:ma27ad, :ma27bd, :ma27cd, Float64),
(:ma27a , :ma27b , :ma27c , Float32)
]
@eval begin
ma27a!(
n::Cint,nz::Cint,I::Vector{Cint},J::Vector{Cint},
iw::Vector{Cint},liw::Cint,ikeep::Vector{Cint},iw1::Vector{Cint},
nsteps::Vector{Cint},iflag::Cint,icntl::Vector{Cint},cntl::Vector{$typ},
info::Vector{Cint},ops::$typ
) = ccall(
($(string(fa)),libhsl),
Nothing,
(Ref{Cint},Ref{Cint},Ptr{Cint},Ptr{Cint},
Ptr{Cint},Ref{Cint},Ptr{Cint},Ptr{Cint},
Ptr{Cint},Ref{Cint},Ptr{Cint},Ptr{$typ},
Ptr{Cint},Ref{$typ}),
n,nz,I,J,iw,liw,ikeep,iw1,nsteps,iflag,icntl,cntl,info,ops
)
) = HSL.$fa(n,nz,I,J,iw,liw,ikeep,iw1,nsteps,iflag,icntl,cntl,info,ops)

ma27b!(
n::Cint,nz::Cint,I::Vector{Cint},J::Vector{Cint},
a::Vector{$typ},la::Cint,iw::Vector{Cint},liw::Cint,
ikeep::Vector{Cint},nsteps::Vector{Cint},maxfrt::Vector{Cint},iw1::Vector{Cint},
icntl::Vector{Cint},cntl::Vector{$typ},info::Vector{Cint}
) = ccall(
($(string(fb)),libhsl),
Nothing,
(Ref{Cint},Ref{Cint},Ptr{Cint},Ptr{Cint},
Ptr{$typ},Ref{Cint},Ptr{Cint},Ref{Cint},
Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Cint},
Ptr{Cint},Ptr{$typ},Ptr{Cint}),
n,nz,I,J,a,la,iw,liw,ikeep,nsteps,maxfrt,iw1,icntl,cntl,info
)
) = HSL.$fb(n,nz,I,J,a,la,iw,liw,ikeep,nsteps,maxfrt,iw1,icntl,cntl,info)

ma27c!(
n::Cint,a::Vector{$typ},la::Cint,iw::Vector{Cint},
liw::Cint,w::Vector{$typ},maxfrt::Vector{Cint},rhs::Vector{$typ},
iw1::Vector{Cint},nsteps::Vector{Cint},icntl::Vector{Cint},
info::Vector{Cint}
) = ccall(
($(string(fc)),libhsl),
Nothing,
(Ref{Cint},Ptr{$typ},Ref{Cint},Ptr{Cint},
Ref{Cint},Ptr{$typ},Ptr{Cint},Ptr{$typ},
Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Cint}),
n,a,la,iw,liw,w,maxfrt,rhs,iw1,nsteps,icntl,info
)
) = HSL.$fc(n,a,la,iw,liw,w,maxfrt,rhs,iw1,nsteps,icntl,info)
end
end

Expand Down
33 changes: 8 additions & 25 deletions lib/MadNLPHSL/src/ma57.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,27 @@ end


for (fa,fb,fc,typ) in (
(:ma57ad_, :ma57bd_, :ma57cd_, Float64),
(:ma57a_, :ma57b_, :ma57c_, Float32)
(:ma57ad, :ma57bd, :ma57cd, Float64),
(:ma57a , :ma57b , :ma57c , Float32)
)
@eval begin

ma57ad!(n::Cint,nz::Cint,I::Vector{Cint},J::Vector{Cint},lkeep::Cint,
keep::Vector{Cint},iwork::Vector{Cint},icntl::Vector{Cint},
info::Vector{Cint},rinfo::Vector{$typ}) = ccall(
($(string(fa)),libhsl),
Nothing,
(Ref{Cint},Ref{Cint},Ptr{Cint},Ptr{Cint},Ref{Cint},
Ptr{Cint},Ptr{Cint},Ptr{Cint},
Ptr{Cint},Ptr{$typ}),
n,nz,I,J,lkeep,keep,iwork,icntl,info,rinfo)
info::Vector{Cint},rinfo::Vector{$typ}
) = HSL.$fa(n,nz,I,J,lkeep,keep,iwork,icntl,info,rinfo)

ma57bd!(n::Cint,nz::Cint,V::Vector{$typ},fact::Vector{$typ},
lfact::Cint,ifact::Vector{Cint},lifact::Cint,lkeep::Cint,
keep::Vector{Cint},iwork::Vector{Cint},icntl::Vector{Cint},cntl::Vector{$typ},
info::Vector{Cint},rinfo::Vector{$typ}) = ccall(
($(string(fb)),libhsl),
Nothing,
(Ref{Cint},Ref{Cint},Ptr{$typ},Ptr{$typ},
Ref{Cint},Ptr{Cint},Ref{Cint},Ref{Cint},
Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{$typ},
Ptr{Cint},Ptr{$typ}),
n,nz,V,fact,lfact,ifact,lifact,lkeep,keep,iwork,icntl,cntl,info,rinfo)
info::Vector{Cint},rinfo::Vector{$typ}
) = HSL.$fb(n,nz,V,fact,lfact,ifact,lifact,lkeep,keep,iwork,icntl,cntl,info,rinfo)

ma57cd!(job::Cint,n::Cint,fact::Vector{$typ},lfact::Cint,
ifact::Vector{Cint},lifact::Cint,nrhs::Cint,rhs::Vector{$typ},
lrhs::Cint,work::Vector{$typ},lwork::Cint,iwork::Vector{Cint},
icntl::Vector{Cint},info::Vector{Cint}) = ccall(
($(string(fc)),libhsl),
Nothing,
(Ref{Cint},Ref{Cint},Ptr{$typ},Ref{Cint},
Ptr{Cint},Ref{Cint},Ref{Cint},Ptr{$typ},
Ref{Cint},Ptr{$typ},Ref{Cint},Ptr{Cint},
Ptr{Cint},Ptr{Cint}),
job,n,fact,lfact,ifact,lifact,nrhs,rhs,lrhs,work,lwork,iwork,icntl,info)
icntl::Vector{Cint},info::Vector{Cint}
) = HSL.$fc(job,n,fact,lfact,ifact,lifact,nrhs,rhs,lrhs,work,lwork,iwork,icntl,info)
end
end

Expand Down
Loading

0 comments on commit 2bec55d

Please sign in to comment.