Skip to content

Commit

Permalink
Update the C wrappers with the release of libHSL
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Nov 13, 2023
1 parent 1334e06 commit ae6e64c
Show file tree
Hide file tree
Showing 19 changed files with 2,901 additions and 3,007 deletions.
6 changes: 3 additions & 3 deletions gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The `main` function supports the boolean keyword argument `optimized` to clear t
You can also call `main(library)` if you want to generate the wrapper for a specific HSL `library`.
The possible values for `library` are:
- `"all"` (default);
- `"juliahsl"`;
- `"libhsl"`;
- `"hsl_ma48"`;
- `"hsl_ma57"`;
- `"hsl_ma77"`;
Expand All @@ -30,8 +30,8 @@ The possible values for `library` are:
If a package doesn't have a C interface, we are still able to use it in Julia but we need to call the Fortran functions and subroutines.
The wrappers for Fortran functions and subroutines can't be easily generated and are generally written by hand but the file `analyzer.jl` helps to partially generate the wrappers.
`analyzer.jl` is only able to fully generate the wrappers of functions and subroutines written in FORTRAN 77.
You just need to provide the path of the `JuliaHSL` on your computer (`julihsl` variable) and call `main(library)`.
`library` can be any HSL package available in the `JuliaHSL` folder.
You just need to provide the path of the `libHSL` on your computer (`libhsl` variable) and call `main(library)`.
`library` can be any HSL package available in the `libHSL` folder.

# Maintenance

Expand Down
4 changes: 2 additions & 2 deletions gen/rewriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ structure_modifications = Dict("_control_s}" => "_control{Float32}}",

function rewrite!(path::String, name::String, optimized::Bool)
text = read(path, String)
if name == "juliahsl"
updated_text = replace(text, "# no prototype is found for this function at juliahsl.h:44:6, please use with caution\n" => "")
if name == "libhsl"
updated_text = replace(text, "# no prototype is found for this function at libhsl.h:44:6, please use with caution\n" => "")
updated_text = replace(updated_text, "major, minor, patch)\n" => ")\n major = Ref{Cint}(0)\n minor = Ref{Cint}(0)\n patch = Ref{Cint}(0)\n")
updated_text = replace(updated_text, "Ptr{Cint}" => "Ref{Cint}")
updated_text = replace(updated_text, "Cvoid\n" => "Cvoid\n VersionNumber(major[], minor[], patch[])\n")
Expand Down
8 changes: 4 additions & 4 deletions gen/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function wrapper(name::String, headers::Vector{String}, optimized::Bool)
options = load_options(joinpath(@__DIR__, "hsl.toml"))
options["general"]["output_file_path"] = joinpath("..", "src", "C", "$(name).jl")

if name != "juliahsl"
if name != "libhsl"
solver = split(name, "_")[2]
optimized && (options["general"]["output_ignorelist"] = ["$(solver)realtype_[sdcz]_\$",
"$(solver)pkgtype_[sdcz]_\$",
Expand All @@ -36,7 +36,7 @@ function wrapper(name::String, headers::Vector{String}, optimized::Bool)

path = options["general"]["output_file_path"]

(name != "juliahsl") && format_file(path, YASStyle())
(name != "libhsl") && format_file(path, YASStyle())
rewrite!(path, name, optimized)
return nothing
end
Expand All @@ -49,8 +49,8 @@ end
function main(name::String="all"; optimized::Bool=false)
include = joinpath(HSL_jll.artifact_dir, "include")

if name == "all" || name == "juliahsl"
wrapper("juliahsl", [joinpath(include, "juliahsl.h")], optimized)
if name == "all" || name == "libhsl"
wrapper("libhsl", [joinpath(include, "libhsl.h")], optimized)
end

if name == "all" || name == "hsl_ma48"
Expand Down
214 changes: 99 additions & 115 deletions src/C/hsl_ma48.jl
Original file line number Diff line number Diff line change
@@ -1,174 +1,158 @@
function ma48_initialize_s(factors)
@ccall libhsl.ma48_initialize_s(factors::Ptr{Ptr{Cvoid}})::Cvoid
@ccall libhsl.ma48_initialize_s(factors::Ptr{Ptr{Cvoid}})::Cvoid
end

mutable struct ma48_control{T}
f_arrays::Cint
multiplier::T
u::T
switch_::T
drop::T
tolerance::T
cgce::T
lp::Cint
wp::Cint
mp::Cint
ldiag::Cint
btf::Cint
struct_::Cint
maxit::Cint
factor_blocking::Cint
solve_blas::Cint
pivoting::Cint
diagonal_pivoting::Cint
fill_in::Cint
switch_mode::Cint
f_arrays::Cint
multiplier::T
u::T
switch_::T
drop::T
tolerance::T
cgce::T
lp::Cint
wp::Cint
mp::Cint
ldiag::Cint
btf::Cint
struct_::Cint
maxit::Cint
factor_blocking::Cint
solve_blas::Cint
pivoting::Cint
diagonal_pivoting::Cint
fill_in::Cint
switch_mode::Cint
end

function ma48_default_control_s(control)
@ccall libhsl.ma48_default_control_s(control::Ref{ma48_control{Float32}})::Cvoid
@ccall libhsl.ma48_default_control_s(control::Ref{ma48_control{Float32}})::Cvoid
end

mutable struct ma48_ainfo{T}
ops::T
flag::Cint
more::Cint
lena_analyse::Clong
lenj_analyse::Clong
lena_factorize::Clong
leni_factorize::Clong
ncmpa::Cint
rank::Cint
drop::Clong
struc_rank::Cint
oor::Clong
dup::Clong
stat::Cint
lblock::Cint
sblock::Cint
tblock::Clong
ops::T
flag::Cint
more::Cint
lena_analyse::Clong
lenj_analyse::Clong
lena_factorize::Clong
leni_factorize::Clong
ncmpa::Cint
rank::Cint
drop::Clong
struc_rank::Cint
oor::Clong
dup::Clong
stat::Cint
lblock::Cint
sblock::Cint
tblock::Clong
end

mutable struct ma48_finfo{T}
ops::T
flag::Cint
more::Cint
size_factor::Clong
lena_factorize::Clong
leni_factorize::Clong
drop::Clong
rank::Cint
stat::Cint
end

function ma48_analyse_s(m, n, ne, row, col, val, factors, control, ainfo, finfo, perm,
endcol)
@ccall libhsl.ma48_analyse_s(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint},
col::Ptr{Cint}, val::Ptr{Float32},
factors::Ptr{Cvoid}, control::Ref{ma48_control{Float32}},
ainfo::Ref{ma48_ainfo{Float32}}, finfo::Ref{ma48_finfo{Float32}},
perm::Ptr{Cint}, endcol::Ptr{Cint})::Cvoid
ops::T
flag::Cint
more::Cint
size_factor::Clong
lena_factorize::Clong
leni_factorize::Clong
drop::Clong
rank::Cint
stat::Cint
end

function ma48_analyse_s(m, n, ne, row, col, val, factors, control, ainfo, finfo, perm, endcol)
@ccall libhsl.ma48_analyse_s(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float32}, factors::Ptr{Cvoid},
control::Ref{ma48_control{Float32}}, ainfo::Ref{ma48_ainfo{Float32}},
finfo::Ref{ma48_finfo{Float32}}, perm::Ptr{Cint}, endcol::Ptr{Cint})::Cvoid
end

function ma48_get_perm_s(m, n, factors, perm, control)
@ccall libhsl.ma48_get_perm_s(m::Cint, n::Cint, factors::Ptr{Cvoid}, perm::Ptr{Cint},
control::Ref{ma48_control{Float32}})::Cvoid
@ccall libhsl.ma48_get_perm_s(m::Cint, n::Cint, factors::Ptr{Cvoid}, perm::Ptr{Cint},
control::Ref{ma48_control{Float32}})::Cvoid
end

function ma48_factorize_s(m, n, ne, row, col, val, factors, control, finfo, fast, partial)
@ccall libhsl.ma48_factorize_s(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint},
col::Ptr{Cint}, val::Ptr{Float32},
factors::Ptr{Cvoid}, control::Ref{ma48_control{Float32}},
finfo::Ref{ma48_finfo{Float32}}, fast::Cint,
partial::Cint)::Cvoid
@ccall libhsl.ma48_factorize_s(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float32}, factors::Ptr{Cvoid},
control::Ref{ma48_control{Float32}}, finfo::Ref{ma48_finfo{Float32}}, fast::Cint,
partial::Cint)::Cvoid
end

mutable struct ma48_sinfo
flag::Cint
more::Cint
stat::Cint
flag::Cint
more::Cint
stat::Cint
end

function ma48_solve_s(m, n, ne, row, col, val, factors, rhs, x, control, sinfo, trans,
resid, error)
@ccall libhsl.ma48_solve_s(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float32}, factors::Ptr{Cvoid},
rhs::Ptr{Float32}, x::Ptr{Float32},
control::Ref{ma48_control{Float32}}, sinfo::Ref{ma48_sinfo},
trans::Cint, resid::Ptr{Float32},
error::Ptr{Float32})::Cvoid
function ma48_solve_s(m, n, ne, row, col, val, factors, rhs, x, control, sinfo, trans, resid, error)
@ccall libhsl.ma48_solve_s(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float32}, factors::Ptr{Cvoid},
rhs::Ptr{Float32}, x::Ptr{Float32},
control::Ref{ma48_control{Float32}}, sinfo::Ref{ma48_sinfo}, trans::Cint,
resid::Ptr{Float32}, error::Ptr{Float32})::Cvoid
end

function ma48_finalize_s(factors, control)
@ccall libhsl.ma48_finalize_s(factors::Ptr{Ptr{Cvoid}},
control::Ref{ma48_control{Float32}})::Cint
@ccall libhsl.ma48_finalize_s(factors::Ptr{Ptr{Cvoid}}, control::Ref{ma48_control{Float32}})::Cint
end

function ma48_special_rows_and_cols_s(factors, rank, rows, cols, control)
@ccall libhsl.ma48_special_rows_and_cols_s(factors::Ptr{Cvoid}, rank::Ptr{Cint},
rows::Ptr{Cint}, cols::Ptr{Cint},
control::Ref{ma48_control{Float32}})::Cint
@ccall libhsl.ma48_special_rows_and_cols_s(factors::Ptr{Cvoid}, rank::Ptr{Cint}, rows::Ptr{Cint},
cols::Ptr{Cint}, control::Ref{ma48_control{Float32}})::Cint
end

function ma48_determinant_s(factors, sgndet, logdet, control)
@ccall libhsl.ma48_determinant_s(factors::Ptr{Cvoid}, sgndet::Ptr{Cint},
logdet::Ptr{Float32},
control::Ref{ma48_control{Float32}})::Cint
@ccall libhsl.ma48_determinant_s(factors::Ptr{Cvoid}, sgndet::Ptr{Cint},
logdet::Ptr{Float32}, control::Ref{ma48_control{Float32}})::Cint
end

function ma48_initialize_d(factors)
@ccall libhsl.ma48_initialize_d(factors::Ptr{Ptr{Cvoid}})::Cvoid
@ccall libhsl.ma48_initialize_d(factors::Ptr{Ptr{Cvoid}})::Cvoid
end

function ma48_default_control_d(control)
@ccall libhsl.ma48_default_control_d(control::Ref{ma48_control{Float64}})::Cvoid
@ccall libhsl.ma48_default_control_d(control::Ref{ma48_control{Float64}})::Cvoid
end

function ma48_analyse_d(m, n, ne, row, col, val, factors, control, ainfo, finfo, perm,
endcol)
@ccall libhsl.ma48_analyse_d(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint},
col::Ptr{Cint}, val::Ptr{Float64},
factors::Ptr{Cvoid}, control::Ref{ma48_control{Float64}},
ainfo::Ref{ma48_ainfo{Float64}}, finfo::Ref{ma48_finfo{Float64}},
perm::Ptr{Cint}, endcol::Ptr{Cint})::Cvoid
function ma48_analyse_d(m, n, ne, row, col, val, factors, control, ainfo, finfo, perm, endcol)
@ccall libhsl.ma48_analyse_d(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float64}, factors::Ptr{Cvoid},
control::Ref{ma48_control{Float64}}, ainfo::Ref{ma48_ainfo{Float64}},
finfo::Ref{ma48_finfo{Float64}}, perm::Ptr{Cint}, endcol::Ptr{Cint})::Cvoid
end

function ma48_get_perm_d(m, n, factors, perm, control)
@ccall libhsl.ma48_get_perm_d(m::Cint, n::Cint, factors::Ptr{Cvoid}, perm::Ptr{Cint},
control::Ref{ma48_control{Float64}})::Cvoid
@ccall libhsl.ma48_get_perm_d(m::Cint, n::Cint, factors::Ptr{Cvoid}, perm::Ptr{Cint},
control::Ref{ma48_control{Float64}})::Cvoid
end

function ma48_factorize_d(m, n, ne, row, col, val, factors, control, finfo, fast, partial)
@ccall libhsl.ma48_factorize_d(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint},
col::Ptr{Cint}, val::Ptr{Float64},
factors::Ptr{Cvoid}, control::Ref{ma48_control{Float64}},
finfo::Ref{ma48_finfo{Float64}}, fast::Cint,
partial::Cint)::Cvoid
@ccall libhsl.ma48_factorize_d(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float64}, factors::Ptr{Cvoid},
control::Ref{ma48_control{Float64}}, finfo::Ref{ma48_finfo{Float64}}, fast::Cint,
partial::Cint)::Cvoid
end

function ma48_solve_d(m, n, ne, row, col, val, factors, rhs, x, control, sinfo, trans,
resid, error)
@ccall libhsl.ma48_solve_d(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float64}, factors::Ptr{Cvoid},
rhs::Ptr{Float64}, x::Ptr{Float64},
control::Ref{ma48_control{Float64}}, sinfo::Ref{ma48_sinfo},
trans::Cint, resid::Ptr{Float64},
error::Ptr{Float64})::Cvoid
function ma48_solve_d(m, n, ne, row, col, val, factors, rhs, x, control, sinfo, trans, resid, error)
@ccall libhsl.ma48_solve_d(m::Cint, n::Cint, ne::Clong, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float64}, factors::Ptr{Cvoid},
rhs::Ptr{Float64}, x::Ptr{Float64},
control::Ref{ma48_control{Float64}}, sinfo::Ref{ma48_sinfo}, trans::Cint,
resid::Ptr{Float64}, error::Ptr{Float64})::Cvoid
end

function ma48_finalize_d(factors, control)
@ccall libhsl.ma48_finalize_d(factors::Ptr{Ptr{Cvoid}},
control::Ref{ma48_control{Float64}})::Cint
@ccall libhsl.ma48_finalize_d(factors::Ptr{Ptr{Cvoid}}, control::Ref{ma48_control{Float64}})::Cint
end

function ma48_special_rows_and_cols_d(factors, rank, rows, cols, control)
@ccall libhsl.ma48_special_rows_and_cols_d(factors::Ptr{Cvoid}, rank::Ptr{Cint},
rows::Ptr{Cint}, cols::Ptr{Cint},
control::Ref{ma48_control{Float64}})::Cint
@ccall libhsl.ma48_special_rows_and_cols_d(factors::Ptr{Cvoid}, rank::Ptr{Cint}, rows::Ptr{Cint},
cols::Ptr{Cint}, control::Ref{ma48_control{Float64}})::Cint
end

function ma48_determinant_d(factors, sgndet, logdet, control)
@ccall libhsl.ma48_determinant_d(factors::Ptr{Cvoid}, sgndet::Ptr{Cint},
logdet::Ptr{Float64},
control::Ref{ma48_control{Float64}})::Cint
@ccall libhsl.ma48_determinant_d(factors::Ptr{Cvoid}, sgndet::Ptr{Cint},
logdet::Ptr{Float64}, control::Ref{ma48_control{Float64}})::Cint
end
Loading

0 comments on commit ae6e64c

Please sign in to comment.