diff --git a/lib/MadNLPHSL/Project.toml b/lib/MadNLPHSL/Project.toml index 592ba316..41310146 100644 --- a/lib/MadNLPHSL/Project.toml +++ b/lib/MadNLPHSL/Project.toml @@ -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] diff --git a/lib/MadNLPHSL/README.md b/lib/MadNLPHSL/README.md index 7b0cac69..8596ff58 100644 --- a/lib/MadNLPHSL/README.md +++ b/lib/MadNLPHSL/README.md @@ -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: @@ -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" ``` diff --git a/lib/MadNLPHSL/src/MadNLPHSL.jl b/lib/MadNLPHSL/src/MadNLPHSL.jl index 8f51a88c..bc239b71 100644 --- a/lib/MadNLPHSL/src/MadNLPHSL.jl +++ b/lib/MadNLPHSL/src/MadNLPHSL.jl @@ -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") diff --git a/lib/MadNLPHSL/src/ma27.jl b/lib/MadNLPHSL/src/ma27.jl index 28b575cc..0f95b8f0 100644 --- a/lib/MadNLPHSL/src/ma27.jl +++ b/lib/MadNLPHSL/src/ma27.jl @@ -38,8 +38,8 @@ 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!( @@ -47,44 +47,21 @@ for (fa, fb, fc, typ) in [ 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 diff --git a/lib/MadNLPHSL/src/ma57.jl b/lib/MadNLPHSL/src/ma57.jl index 57ce07cc..ba623300 100644 --- a/lib/MadNLPHSL/src/ma57.jl +++ b/lib/MadNLPHSL/src/ma57.jl @@ -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 diff --git a/lib/MadNLPHSL/src/ma77.jl b/lib/MadNLPHSL/src/ma77.jl index 4aa2a6b7..0b7d03ad 100644 --- a/lib/MadNLPHSL/src/ma77.jl +++ b/lib/MadNLPHSL/src/ma77.jl @@ -12,144 +12,16 @@ ma77_umax::Float64 = 1e-4 end -@kwdef mutable struct Ma77Control{T} - f_arrays::Cint = 0 - print_level::Cint = 0 - unit_diagnostics::Cint = 0 - unit_error::Cint = 0 - unit_warning::Cint = 0 - bits::Cint = 0 - - buffer_lpage_1::Cint = 0 - buffer_lpage_2::Cint = 0 - buffer_npage_1::Cint = 0 - buffer_npage_2::Cint = 0 - - file_size::Clong = 0 - maxstore::Clong = 0 - - storage_1::Clong = 0 - storage_2::Clong = 0 - storage_3::Clong = 0 - - nemin::Cint = 0 - maxit::Cint = 0 - infnorm::Cint = 0 - thresh::T = 0. - nb54::Cint = 0 - action::Cint = 0 - multiplier::T = 0. - nb64::Cint = 0 - nbi::Cint = 0 - small::T = 0. - static_::T = 0. - storage_indef::Clong = 0 - u::T = 0. - umin::T = 0. - consist_tol::T = 0. - - ispare_1::Cint = 0 - ispare_2::Cint = 0 - ispare_3::Cint = 0 - ispare_4::Cint = 0 - ispare_5::Cint = 0 - - lspare_1::Clong = 0 - lspare_2::Clong = 0 - lspare_3::Clong = 0 - lspare_4::Clong = 0 - lspare_5::Clong = 0 - - rspare_1::T = 0. - rspare_2::T = 0. - rspare_3::T = 0. - rspare_4::T = 0. - rspare_5::T = 0. -end - -@kwdef mutable struct Ma77Info{T} - detlog::T = 0. - detsign::Cint = 0 - flag::Cint = 0 - iostat::Cint = 0 - matrix_dup::Cint = 0 - matrix_rank::Cint = 0 - matrix_outrange::Cint = 0 - maxdepth::Cint = 0 - maxfront::Cint = 0 - minstore::Clong = 0 - ndelay::Cint = 0 - nfactor::Clong = 0 - nflops::Clong = 0 - niter::Cint = 0 - nsup::Cint = 0 - num_neg::Cint = 0 - num_nothresh::Cint = 0 - num_perturbed::Cint = 0 - ntwo::Cint = 0 - - stat_1::Cint = 0 - stat_2::Cint = 0 - stat_3::Cint = 0 - stat_4::Cint = 0 - - nio_read_1::Clong = 0 # 2 - nio_read_2::Clong = 0 # 2 - - nio_write_1::Clong = 0 # 2 - nio_write_2::Clong = 0 # 2 - - nwd_read_1::Clong = 0 # 2 - nwd_read_2::Clong = 0 # 2 - - nwd_write_1::Clong = 0 # 2 - nwd_write_2::Clong = 0 # 2 - - num_file_1::Cint = 0 # 4 - num_file_2::Cint = 0 # 4 - num_file_3::Cint = 0 # 4 - num_file_4::Cint = 0 # 4 - - storage_1::Clong = 0 # 4 - storage_2::Clong = 0 # 4 - storage_3::Clong = 0 # 4 - storage_4::Clong = 0 # 4 - - tree_nodes::Cint = 0 - unit_restart::Cint = 0 - unused::Cint = 0 - usmall::T = 0. - - - ispare_1::Cint = 0 - ispare_2::Cint = 0 - ispare_3::Cint = 0 - ispare_4::Cint = 0 - ispare_5::Cint = 0 - - lspare_1::Clong = 0 - lspare_2::Clong = 0 - lspare_3::Clong = 0 - lspare_4::Clong = 0 - lspare_5::Clong = 0 - - rspare_1::T = 0. - rspare_2::T = 0. - rspare_3::T = 0. - rspare_4::T = 0. - rspare_5::T = 0. -end - mutable struct Ma77Solver{T} <: AbstractLinearSolver{T} tril::SparseMatrixCSC{T,Int32} full::SparseMatrixCSC{T,Int32} tril_to_full_view::SubVector{T} - control::Ma77Control{T} - info::Ma77Info{T} + control::ma77_control{T} + info::ma77_info{T} - mc68_control::Mc68Control - mc68_info::Mc68Info + mc68_control::mc68_control + mc68_info::mc68_info order::Vector{Int32} keep::Vector{Ptr{Nothing}} @@ -167,79 +39,43 @@ for (fdefault, fanalyse, ffactor, fsolve, ffinalise, fopen, finputv, finputr, ty :ma77_open_s, :ma77_input_vars_s, :ma77_input_reals_s, Float32), ] @eval begin - ma77_default_control(control::Ma77Control{$typ}) = ccall( - ($(string(fdefault)),libhsl), - Cvoid, - (Ref{Ma77Control{$typ}},), - control - ) + ma77_default_control(control::ma77_control{$typ} + ) = HSL.$fdefault(control) + ma77_open( n::Cint,fname1::String,fname2::String,fname3::String,fname4::String, - keep::Vector{Ptr{Cvoid}},control::Ma77Control{$typ},info::Ma77Info{$typ} - ) = ccall( - ($(string(fopen)),libhsl), - Cvoid, - (Cint,Ptr{Cchar},Ptr{Cchar},Ptr{Cchar},Ptr{Cchar}, - Ptr{Ptr{Cvoid}},Ref{Ma77Control{$typ}},Ref{Ma77Info{$typ}}), - n,fname1,fname2,fname3,fname4,keep,control,info - ) + keep::Vector{Ptr{Cvoid}},control::ma77_control{$typ},info::ma77_info{$typ} + ) = HSL.$fopen(n,fname1,fname2,fname3,fname4,keep,control,info) + ma77_input_vars( idx::Cint,nvar::Cint,list::Vector{Cint}, - keep::Vector{Ptr{Cvoid}},control::Ma77Control{$typ},info::Ma77Info{$typ} - ) = ccall( - ($(string(finputv)),libhsl), - Cvoid, - (Cint,Cint,Ptr{Cint}, - Ptr{Ptr{Cvoid}},Ref{Ma77Control{$typ}},Ref{Ma77Info{$typ}} - ), - idx,nvar,list,keep,control,info) + keep::Vector{Ptr{Cvoid}},control::ma77_control{$typ},info::ma77_info{$typ} + ) = HSL.$finputv(idx,nvar,list,keep,control,info) + ma77_input_reals( idx::Cint,length::Cint,reals::Vector{$typ}, - keep::Vector{Ptr{Cvoid}},control::Ma77Control{$typ},info::Ma77Info{$typ} - ) = ccall( - ($(string(finputr)),libhsl), - Cvoid, - (Cint,Cint,Ptr{$typ}, - Ptr{Ptr{Cvoid}},Ref{Ma77Control{$typ}},Ref{Ma77Info{$typ}}), - idx,length,reals,keep,control,info - ) + keep::Vector{Ptr{Cvoid}},control::ma77_control{$typ},info::ma77_info{$typ} + ) = HSL.$finputr(idx,length,reals,keep,control,info) + ma77_analyse( order::Vector{Cint}, - keep::Vector{Ptr{Cvoid}},control::Ma77Control{$typ},info::Ma77Info{$typ} - ) = ccall( - ($(string(fanalyse)),libhsl), - Cvoid, - (Ptr{Cint},Ptr{Ptr{Cvoid}},Ref{Ma77Control{$typ}},Ref{Ma77Info{$typ}}), - order,keep,control,info - ) + keep::Vector{Ptr{Cvoid}},control::ma77_control{$typ},info::ma77_info{$typ} + ) = HSL.$fanalyse(order,keep,control,info) + ma77_factor( - posdef::Cint,keep::Vector{Ptr{Cvoid}},control::Ma77Control{$typ},info::Ma77Info{$typ}, + posdef::Cint,keep::Vector{Ptr{Cvoid}},control::ma77_control{$typ},info::ma77_info{$typ}, scale::Ptr{Nothing} - ) = ccall( - ($(string(ffactor)),libhsl), - Cvoid, - (Cint,Ptr{Ptr{Cvoid}},Ref{Ma77Control{$typ}},Ref{Ma77Info{$typ}},Ptr{Nothing}), - posdef,keep,control,info,scale - ) + ) = HSL.$ffactor(posdef,keep,control,info,scale) + ma77_solve( job::Cint,nrhs::Cint,lx::Cint,x::Vector{$typ}, - keep::Vector{Ptr{Cvoid}},control::Ma77Control{$typ},info::Ma77Info{$typ}, + keep::Vector{Ptr{Cvoid}},control::ma77_control{$typ},info::ma77_info{$typ}, scale::Ptr{Nothing} - ) = ccall( - ($(string(fsolve)),libhsl), - Cvoid, - (Cint,Cint,Cint,Ptr{$typ}, - Ptr{Ptr{Cvoid}},Ref{Ma77Control{$typ}},Ref{Ma77Info{$typ}},Ptr{Nothing}), - job,nrhs,lx,x,keep,control,info,scale - ); + ) = HSL.$fsolve(job,nrhs,lx,x,keep,control,info,scale) + ma77_finalize( - keep::Vector{Ptr{Cvoid}},control::Ma77Control{$typ},info::Ma77Info{$typ} - ) = ccall( - ($(string(ffinalise)),libhsl), - Cvoid, - (Ptr{Ptr{Cvoid}},Ref{Ma77Control{$typ}},Ref{Ma77Info{$typ}}), - keep,control,info - ) + keep::Vector{Ptr{Cvoid}},control::ma77_control{$typ},info::ma77_info{$typ} + ) = HSL.$ffinalise(keep,control,info) end end @@ -250,17 +86,18 @@ function Ma77Solver( full,tril_to_full_view = get_tril_to_full(csc) order = Vector{Int32}(undef,csc.n) - mc68_info = Mc68Info() - mc68_control = get_mc68_default_control() + mc68info = mc68_info() + mc68control = mc68_control() + HSL.mc68_default_control_i(mc68control) keep = [C_NULL] - mc68_control.f_array_in=1 - mc68_control.f_array_out=1 - mc68_order_i(Int32(opt.ma77_order),Int32(csc.n),csc.colptr,csc.rowval,order,mc68_control,mc68_info) + mc68control.f_array_in=1 + mc68control.f_array_out=1 + HSL.mc68_order_i(Int32(opt.ma77_order),Int32(csc.n),csc.colptr,csc.rowval,order,mc68control,mc68info) - info=Ma77Info{T}() - control=Ma77Control{T}() + info=ma77_info{T}() + control=ma77_control{T}() ma77_default_control(control) control.f_arrays = 1 control.bits = 32 @@ -268,10 +105,8 @@ function Ma77Solver( control.maxstore = opt.ma77_maxstore control.print_level = -1 - control.buffer_lpage_1=opt.ma77_buffer_lpage - control.buffer_lpage_2=opt.ma77_buffer_lpage - control.buffer_npage_1=opt.ma77_buffer_npage - control.buffer_npage_2=opt.ma77_buffer_npage + control.buffer_lpage = (opt.ma77_buffer_lpage, opt.ma77_buffer_lpage) + control.buffer_npage = (opt.ma77_buffer_npage, opt.ma77_buffer_npage) control.nemin = opt.ma77_nemin control.small = opt.ma77_small @@ -302,7 +137,7 @@ function Ma77Solver( info.flag<0 && throw(SymbolicException()) M = Ma77Solver{T}(csc,full,tril_to_full_view, - control,info,mc68_control,mc68_info,order,keep,opt,logger) + control,info,mc68control,mc68info,order,keep,opt,logger) finalizer(finalize,M) return M end diff --git a/lib/MadNLPHSL/src/ma86.jl b/lib/MadNLPHSL/src/ma86.jl index 248dbc42..a7994e59 100644 --- a/lib/MadNLPHSL/src/ma86.jl +++ b/lib/MadNLPHSL/src/ma86.jl @@ -10,51 +10,14 @@ ma86_umax::Float64 = 1e-4 end -@kwdef mutable struct Ma86Control{T} - f_arrays::Int32 = 0 - diagnostics_level::Int32 = 0 - unit_diagnostics::Int32 = 0 - unit_error::Int32 = 0 - unit_warning::Int32 = 0 - nemin::Int32 = 0 - nb::Int32 = 0 - action::Int32 = 0 - nbi::Int32 = 0 - pool_size::Int32 = 0 - small::T = 0. - static::T = 0. - u::T = 0. - umin::T = 0. - scaling::Int32 = 0 -end - -@kwdef mutable struct Ma86Info{T} - detlog::T = 0. - detsign::Int32 = 0 - flag::Int32 = 0 - matrix_rank::Int32 = 0 - maxdepth::Int32 = 0 - num_delay::Int32 = 0 - num_factor::Clong = 0 - num_flops::Clong = 0 - num_neg::Int32 = 0 - num_nodes::Int32 = 0 - num_nothresh::Int32 = 0 - num_perturbed::Int32 = 0 - num_two::Int32 = 0 - pool_size::Int32 = 0 - stat::Int32 = 0 - usmall::T = 0. -end - mutable struct Ma86Solver{T} <: AbstractLinearSolver{T} csc::SparseMatrixCSC{T,Int32} - control::Ma86Control{T} - info::Ma86Info{T} + control::ma86_control{T} + info::ma86_info{T} - mc68_control::Mc68Control - mc68_info::Mc68Info + mc68_control::mc68_control + mc68_info::mc68_info order::Vector{Int32} keep::Vector{Ptr{Nothing}} @@ -72,61 +35,34 @@ for (fdefault, fanalyse, ffactor, fsolve, ffinalise, typ) in [ ] @eval begin ma86_default_control( - control::Ma86Control{$typ} - ) = ccall( - ($(string(fdefault)),libhsl), - Nothing, - (Ref{Ma86Control{$typ}},), - control - ) + control::ma86_control{$typ} + ) = HSL.$fdefault(control) + ma86_analyse( n::Cint,colptr::Vector{Cint},rowval::Vector{Cint}, order::Vector{Cint},keep::Vector{Ptr{Nothing}}, - control::Ma86Control{$typ},info::Ma86Info{$typ} - ) = ccall( - ($(string(fanalyse)),libhsl), - Nothing, - (Cint,Ptr{Cint},Ptr{Cint},Ptr{$typ}, - Ptr{Ptr{Nothing}},Ref{Ma86Control{$typ}},Ref{Ma86Info{$typ}}), - n,colptr,rowval,order,keep,control,info - ) + control::ma86_control{$typ},info::ma86_info{$typ} + ) = HSL.$fanalyse(n,colptr,rowval,order,keep,control,info) + ma86_factor( n::Cint,colptr::Vector{Cint},rowval::Vector{Cint}, nzval::Vector{$typ},order::Vector{Cint}, - keep::Vector{Ptr{Nothing}},control::Ma86Control,info::Ma86Info, + keep::Vector{Ptr{Nothing}},control::ma86_control,info::ma86_info, scale::Ptr{Nothing} - ) = ccall( - ($(string(ffactor)),libhsl), - Nothing, - (Cint,Ptr{Cint},Ptr{Cint},Ptr{$typ},Ptr{Cint}, - Ptr{Ptr{Nothing}},Ref{Ma86Control},Ref{Ma86Info},Ptr{Nothing}), - n,colptr,rowval,nzval,order,keep,control,info,scale - ) + ) = HSL.$ffactor(n,colptr,rowval,nzval,order,keep,control,info,scale) + ma86_solve( job::Cint,nrhs::Cint,n::Cint,rhs::Vector{$typ}, order::Vector{Cint},keep::Vector{Ptr{Nothing}}, - control::Ma86Control,info::Ma86Info,scale::Ptr{Nothing} - ) = ccall( - ($(string(fsolve)),libhsl), - Nothing, - (Cint,Cint,Cint,Ptr{$typ},Ptr{Cint},Ptr{Ptr{Nothing}}, - Ref{Ma86Control},Ref{Ma86Info},Ptr{Nothing}), - job,nrhs,n,rhs,order,keep,control,info,scale - ) + control::ma86_control,info::ma86_info,scale::Ptr{Nothing} + ) = HSL.$fsolve(job,nrhs,n,rhs,order,keep,control,info,scale) + ma86_finalize( - keep::Vector{Ptr{Nothing}},control::Ma86Control{$typ} - ) = ccall( - ($(string(ffinalise)),libhsl), - Nothing, - (Ptr{Ptr{Nothing}},Ref{Ma86Control{$typ}}), - keep,control - ) + keep::Vector{Ptr{Nothing}},control::ma86_control{$typ} + ) = HSL.$ffinalise(keep,control) end end -ma86_set_num_threads(n) = ccall((:omp_set_num_threads_,libhsl), - Cvoid, - (Ref{Int32},), - Int32(n)) +ma86_set_num_threads(n) = HSL.omp_set_num_threads(n) function Ma86Solver( csc::SparseMatrixCSC{T,Int32}; @@ -137,29 +73,30 @@ function Ma86Solver( order = Vector{Int32}(undef,csc.n) - info=Ma86Info{T}() - control=Ma86Control{T}() - mc68_info = Mc68Info() - mc68_control = get_mc68_default_control() + info = ma86_info{T}() + control = ma86_control{T}() + mc68info = mc68_info() + mc68control = mc68_control() + HSL.mc68_default_control_i(mc68control) keep = [C_NULL] - mc68_control.f_array_in=1 - mc68_control.f_array_out=1 - mc68_order_i(Int32(opt.ma86_order),Int32(csc.n),csc.colptr,csc.rowval,order,mc68_control,mc68_info) + mc68control.f_array_in=1 + mc68control.f_array_out=1 + HSL.mc68_order_i(Int32(opt.ma86_order),Int32(csc.n),csc.colptr,csc.rowval,order,mc68control,mc68info) ma86_default_control(control) control.diagnostics_level = Int32(opt.ma86_print_level) control.f_arrays = 1 control.nemin = opt.ma86_nemin - control.small = opt.ma86_small + control.small_ = opt.ma86_small control.u = opt.ma86_u control.scaling = Int32(opt.ma86_scaling) ma86_analyse(Int32(csc.n),csc.colptr,csc.rowval,order,keep,control,info) info.flag<0 && throw(SymbolicException()) - M = Ma86Solver{T}(csc,control,info,mc68_control,mc68_info,order,keep,opt,logger) + M = Ma86Solver{T}(csc,control,info,mc68control,mc68info,order,keep,opt,logger) finalizer(finalize,M) return M diff --git a/lib/MadNLPHSL/src/ma97.jl b/lib/MadNLPHSL/src/ma97.jl index 5301c4bf..2ac1cb4d 100644 --- a/lib/MadNLPHSL/src/ma97.jl +++ b/lib/MadNLPHSL/src/ma97.jl @@ -9,57 +9,13 @@ ma97_umax::Float64 = 1e-4 end -@kwdef mutable struct Ma97Control{T} - f_arrays::Cint = 0 - action::Cint = 0 - nemin::Cint = 0 - multiplier::T = 0. - ordering::Cint = 0 - print_level::Cint = 0 - scaling::Cint = 0 - small::T = 0 - u::T = 0 - unit_diagnostics::Cint = 0 - unit_error::Cint = 0 - unit_warning::Cint = 0 - factor_min::Clong = 0 - solve_blas3::Cint = 0 - solve_min::Clong = 0 - solve_mf::Cint = 0 - consist_tol::T = 0 - ispare::Vector{Cint} - rspare::Vector{T} -end - -@kwdef mutable struct Ma97Info{T} - flag::Cint = 0 - flag68::Cint = 0 - flag77::Cint = 0 - matrix_dup::Cint = 0 - matrix_rank::Cint = 0 - matrix_outrange::Cint = 0 - matrix_missing_diag::Cint = 0 - maxdepth::Cint = 0 - maxfront::Cint = 0 - num_delay::Cint = 0 - num_factor::Clong = 0 - num_flops::Clong = 0 - num_neg::Cint = 0 - num_sup::Cint = 0 - num_two::Cint = 0 - ordering::Cint = 0 - stat::Cint = 0 - ispare::Vector{Cint} - rspare::Vector{T} -end - mutable struct Ma97Solver{T} <:AbstractLinearSolver{T} n::Int32 csc::SparseMatrixCSC{T,Int32} - control::Ma97Control{T} - info::Ma97Info{T} + control::ma97_control{T} + info::ma97_info{T} akeep::Vector{Ptr{Nothing}} fkeep::Vector{Ptr{Nothing}} @@ -76,61 +32,34 @@ for (fdefault, fanalyse, ffactor, fsolve, ffinalise, typ) in [ ] @eval begin ma97_default_control( - control::Ma97Control{$typ} - ) = ccall( - ($(string(fdefault)), libhsl), - Nothing, - (Ref{Ma97Control{$typ}},), - control - ) + control::ma97_control{$typ} + ) = HSL.$fdefault(control) + ma97_analyse( check::Cint,n::Cint,ptr::Vector{Cint},row::Vector{Cint}, val::Ptr{Nothing},akeep::Vector{Ptr{Nothing}}, - control::Ma97Control{$typ},info::Ma97Info{$typ}, + control::ma97_control{$typ},info::ma97_info{$typ}, order::Ptr{Nothing} - ) = ccall( - ($(string(fanalyse)),libhsl), - Nothing, - (Cint,Cint,Ptr{Cint},Ptr{Cint},Ptr{$typ}, - Ptr{Ptr{Nothing}},Ref{Ma97Control{$typ}},Ref{Ma97Info{$typ}},Ptr{Cint}), - check,n,ptr,row,val,akeep,control,info,order - ) + ) = HSL.$fanalyse(check,n,ptr,row,val,akeep,control,info,order) + ma97_factor( matrix_type::Cint,ptr::Ptr{Nothing},row::Ptr{Nothing}, val::Vector{$typ},akeep::Vector{Ptr{Nothing}},fkeep::Vector{Ptr{Nothing}}, - control::Ma97Control,info::Ma97Info,scale::Ptr{Nothing} - ) = ccall( - ($(string(ffactor)),libhsl), - Nothing, - (Cint,Ptr{Cint},Ptr{Cint},Ptr{$typ},Ptr{Ptr{Nothing}}, - Ptr{Ptr{Nothing}},Ref{Ma97Control},Ref{Ma97Info},Ptr{$typ}), - matrix_type,ptr,row,val,akeep,fkeep,control,info,scale - ) + control::ma97_control,info::ma97_info,scale::Ptr{Nothing} + ) = HSL.$ffactor(matrix_type,ptr,row,val,akeep,fkeep,control,info,scale) + ma97_solve( job::Cint,nrhs::Cint,x::Vector{$typ},ldx::Cint, akeep::Vector{Ptr{Nothing}},fkeep::Vector{Ptr{Nothing}}, - control::Ma97Control,info::Ma97Info - ) = ccall( - ($(string(fsolve)),libhsl), - Nothing, - (Cint,Cint,Ptr{$typ},Cint,Ptr{Ptr{Nothing}}, - Ptr{Ptr{Nothing}},Ref{Ma97Control},Ref{Ma97Info}), - job,nrhs,x,ldx,akeep,fkeep,control,info - ) + control::ma97_control,info::ma97_info + ) = HSL.$fsolve(job,nrhs,x,ldx,akeep,fkeep,control,info) + ma97_finalize( ::Type{$typ},akeep::Vector{Ptr{Nothing}},fkeep::Vector{Ptr{Nothing}} - )=ccall( - ($(string(ffinalise)),libhsl), - Nothing, - (Ptr{Ptr{Nothing}},Ptr{Ptr{Nothing}}), - akeep,fkeep - ) + ) = HSL.$ffinalise(akeep,fkeep) end end -ma97_set_num_threads(n) = ccall((:omp_set_num_threads_,libhsl), - Cvoid, - (Ref{Cint},), - Cint(n)) +ma97_set_num_threads(n) = HSL.omp_set_num_threads(n) function Ma97Solver( @@ -142,8 +71,8 @@ function Ma97Solver( n = Int32(csc.n) - info = Ma97Info{T}(ispare=zeros(Int32,5),rspare=zeros(T,10)) - control=Ma97Control{T}(ispare=zeros(Int32,5),rspare=zeros(T,10)) + info = ma97_info{T}() + control=ma97_control{T}() ma97_default_control(control) control.print_level = opt.ma97_print_level diff --git a/lib/MadNLPHSL/src/mc68.jl b/lib/MadNLPHSL/src/mc68.jl deleted file mode 100644 index a5d2b75e..00000000 --- a/lib/MadNLPHSL/src/mc68.jl +++ /dev/null @@ -1,47 +0,0 @@ -# MadNLP.jl -# Created by Sungho Shin (sungho.shin@wisc.edu) - -@kwdef mutable struct Mc68Control - f_array_in::Cint = 0 - f_array_out::Cint = 0 - min_l_workspace::Clong = 0 - lp::Cint = 0 - wp::Cint = 0 - mp::Cint = 0 - nemin::Cint = 0 - print_level::Cint = 0 - row_full_thresh::Cint = 0 - row_search::Cint = 0 -end - -@kwdef mutable struct Mc68Info - flag::Cint = 0 - iostat::Cint = 0 - stat::Cint = 0 - out_range::Cint = 0 - duplicate::Cint = 0 - n_compressions::Cint = 0 - n_zero_eigs::Cint = 0 - l_workspace::Clong = 0 - zb01_info::Cint = 0 - n_dense_rows::Cint = 0 -end - -function get_mc68_default_control() - control = Mc68Control(0,0,0,0,0,0,0,0,0,0) - mc68_default_control_i(control) - return control -end - -mc68_default_control_i(control::Mc68Control) = ccall((:mc68_default_control_i,libhsl), - Nothing, - (Ref{Mc68Control},), - control) - -mc68_order_i(ord::Int32,n::Int32,ptr::Array{Int32,1},row::Array{Int32,1}, - perm::Array{Int32,1},control::Mc68Control,info::Mc68Info) = ccall( - (:mc68_order_i,libhsl), - Nothing, - (Cint,Cint,Ptr{Cint},Ptr{Cint},Ptr{Cint},Ref{Mc68Control},Ref{Mc68Info}), - ord,n,ptr,row,perm,control,info) - diff --git a/lib/MadNLPHSL/test/runtests.jl b/lib/MadNLPHSL/test/runtests.jl index b7776e4d..23d1c116 100644 --- a/lib/MadNLPHSL/test/runtests.jl +++ b/lib/MadNLPHSL/test/runtests.jl @@ -1,4 +1,4 @@ -using Test, MadNLP, MadNLPHSL, MadNLPTests +using Test, MadNLP, MadNLPHSL, MadNLPTests, HSL testset = [ [ @@ -39,13 +39,13 @@ testset = [ ] @testset "MadNLPHSL test" begin - for hsl_solver in [Ma27Solver, Ma57Solver, Ma77Solver, Ma86Solver, Ma97Solver] - # MadNLPTests.test_linear_solver(hsl_solver,Float32) - MadNLPTests.test_linear_solver(hsl_solver,Float64) - end - for (name,optimizer_constructor,exclude) in testset - test_madnlp(name,optimizer_constructor,exclude) + if LIBHSL_isfunctional() + for hsl_solver in [Ma27Solver, Ma57Solver, Ma77Solver, Ma86Solver, Ma97Solver] + # MadNLPTests.test_linear_solver(hsl_solver,Float32) + MadNLPTests.test_linear_solver(hsl_solver,Float64) + end + for (name,optimizer_constructor,exclude) in testset + test_madnlp(name,optimizer_constructor,exclude) + end end end - -