Skip to content

Commit

Permalink
Add the new wrappers with support of Int64
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Dec 9, 2024
1 parent 6e4489b commit 0f5ce85
Show file tree
Hide file tree
Showing 58 changed files with 2,886 additions and 375 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ deps/build.log
Manifest.toml
docs/Manifest.toml
gen/symbols.txt
gen/symbols_64.txt
1 change: 1 addition & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"

[compat]
julia = "1.6"
HSL_jll = "=2024.11.28"
50 changes: 48 additions & 2 deletions gen/analyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
using HSL_jll
using JuliaFormatter

release = "2023.11.7"
libhsl = "/home/alexis/Bureau/git/hsl/libhsl/libHSL-$release/"
release = "2024.11.28"
libhsl = "/home/alexis/Bureau/git/hsl/libhsl/libHSL.v$release/"

# Symbols of the shared library libhsl
symbols_path = "symbols.txt"
run(pipeline(`nm -D $(HSL_jll.libhsl_path)`, stdout=symbols_path))

# Symbols of the shared library libhsl_subset_64
symbols_64_path = "symbols_64.txt"
run(pipeline(`nm -D $(HSL_jll.libhsl_subset_64_path)`, stdout=symbols_64_path))

# Relation between the hsl precision and the name of the symbols
hsl_precision = Dict{Char, String}('i' => "integer",
'l' => "long_integer",
Expand Down Expand Up @@ -392,6 +396,11 @@ function main(name::String="all"; verbose::Bool=false)
symbols = split(symbols, "\n", keepempty=false)
symbols = [symbol[20:end] for symbol in symbols]

# Create a vector with all symbols exported by the shared library libhsl_subset_64
symbols_64 = read(symbols_64_path, String)
symbols_64 = split(symbols_64, "\n", keepempty=false)
symbols_64 = [symbol_64[20:end] for symbol_64 in symbols_64]

for (root, dirs, files) in walkdir(libhsl)

# We don't want to go inside "examples", metis" and "libhsl" folders
Expand Down Expand Up @@ -475,6 +484,43 @@ function main(name::String="all"; verbose::Bool=false)
end
write(file_wrapper, ")::$(output_type)\n")
write(file_wrapper, "end\n")

# Symbols with the suffix `64_`
if "$(fname)64_" in symbols_64
write(file_wrapper, "\n")
signature64 = replace(signature, fname[1:end-1] => "$(fname)64")
signature64 = replace(signature64, "Cint" => "Int64")
write(file_wrapper, "function $signature64\n")
write(file_wrapper, " @ccall libhsl_subset_64.$(fname)64_(")
for k = 1:narguments
if types[k] == ""
format = false
@warn "Unable to determine the type of $(arguments[k])"
else
type64 = replace(types[k], "Cint" => "Int64")
write(file_wrapper, "$(arguments[k])::$(type64)")
end
(k < narguments) && write(file_wrapper, ", ")
end

# Hidden arguments
if "Ref{UInt8}" types || "Ptr{UInt8}" types || "Ptr{Ptr{UInt8}}" types
verbose && @info "Hidden argument in $fname."
end
for k = 1:narguments
(types[k] == "Ref{UInt8}") && write(file_wrapper, ", 1::Csize_t")
(types[k] == "Ptr{UInt8}") && write(file_wrapper, ", $(strlen[arguments[k]])::Csize_t")
(types[k] == "Ptr{Ptr{UInt8}}") && write(file_wrapper, ", $(strlen[arguments[k]])::Csize_t")
end

if output_type == ""
format = false
@warn "Unable to determine the output type"
end
write(file_wrapper, ")::$(output_type)\n")
write(file_wrapper, "end\n")
end

index < num_fnames && write(file_wrapper, "\n")
end
end
Expand Down
4 changes: 2 additions & 2 deletions gen/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function wrapper(name::String, headers::Vector{String}, optimized::Bool)
@info "Wrapping $name"

cd(@__DIR__)
include_dir = joinpath(HSL_jll.artifact_dir, "include")
include_dir = joinpath(HSL_jll.artifact_dir, "include", "libhsl")
options = load_options(joinpath(@__DIR__, "hsl.toml"))
options["general"]["output_file_path"] = joinpath("..", "src", "C", "$(name).jl")

Expand Down Expand Up @@ -47,7 +47,7 @@ function hsl_headers(include::String, package::String, precisions::Vector{Char})
end

function main(name::String="all"; optimized::Bool=false)
include = joinpath(HSL_jll.artifact_dir, "include")
include = joinpath(HSL_jll.artifact_dir, "include", "libhsl")

if name == "all" || name == "libhsl"
wrapper("libhsl", [joinpath(include, "libhsl.h")], optimized)
Expand Down
50 changes: 36 additions & 14 deletions src/C/hsl_ma48.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ mutable struct ma48_control{T}
fill_in::Cint
switch_mode::Cint

ma48_control{T}() where T = new()
ma48_control{T}() where {T} = new()

ma48_control{T}(f_arrays, multiplier, u, switch_, drop, tolerance, cgce, lp, wp, mp, ldiag, btf, struct_, maxit, factor_blocking, solve_blas, pivoting, diagonal_pivoting, fill_in, switch_mode) where T = new(f_arrays, multiplier, u, switch_, drop, tolerance, cgce, lp, wp, mp, ldiag, btf, struct_, maxit, factor_blocking, solve_blas, pivoting, diagonal_pivoting, fill_in, switch_mode)
function ma48_control{T}(f_arrays, multiplier, u, switch_, drop, tolerance, cgce, lp, wp, mp,
ldiag, btf, struct_, maxit, factor_blocking, solve_blas, pivoting,
diagonal_pivoting, fill_in, switch_mode) where {T}
return new(f_arrays, multiplier, u, switch_, drop, tolerance, cgce, lp, wp, mp, ldiag, btf,
struct_, maxit, factor_blocking, solve_blas, pivoting, diagonal_pivoting, fill_in,
switch_mode)
end
end

function ma48_default_control_s(control)
Expand All @@ -52,9 +58,14 @@ mutable struct ma48_ainfo{T}
sblock::Cint
tblock::Clong

ma48_ainfo{T}() where T = new()
ma48_ainfo{T}() where {T} = new()

ma48_ainfo{T}(ops, flag, more, lena_analyse, lenj_analyse, lena_factorize, leni_factorize, ncmpa, rank, drop, struc_rank, oor, dup, stat, lblock, sblock, tblock) where T = new(ops, flag, more, lena_analyse, lenj_analyse, lena_factorize, leni_factorize, ncmpa, rank, drop, struc_rank, oor, dup, stat, lblock, sblock, tblock)
function ma48_ainfo{T}(ops, flag, more, lena_analyse, lenj_analyse, lena_factorize,
leni_factorize, ncmpa, rank, drop, struc_rank, oor, dup, stat, lblock,
sblock, tblock) where {T}
return new(ops, flag, more, lena_analyse, lenj_analyse, lena_factorize, leni_factorize, ncmpa,
rank, drop, struc_rank, oor, dup, stat, lblock, sblock, tblock)
end
end

mutable struct ma48_finfo{T}
Expand All @@ -68,16 +79,20 @@ mutable struct ma48_finfo{T}
rank::Cint
stat::Cint

ma48_finfo{T}() where T = new()
ma48_finfo{T}() where {T} = new()

ma48_finfo{T}(ops, flag, more, size_factor, lena_factorize, leni_factorize, drop, rank, stat) where T = new(ops, flag, more, size_factor, lena_factorize, leni_factorize, drop, rank, stat)
function ma48_finfo{T}(ops, flag, more, size_factor, lena_factorize, leni_factorize, drop, rank,
stat) where {T}
return new(ops, flag, more, size_factor, lena_factorize, leni_factorize, drop, rank, stat)
end
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
finfo::Ref{ma48_finfo{Float32}}, perm::Ptr{Cint},
endcol::Ptr{Cint})::Cvoid
end

function ma48_get_perm_s(m, n, factors, perm, control)
Expand All @@ -88,7 +103,8 @@ 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,
control::Ref{ma48_control{Float32}},
finfo::Ref{ma48_finfo{Float32}}, fast::Cint,
partial::Cint)::Cvoid
end

Expand All @@ -106,7 +122,8 @@ function ma48_solve_s(m, n, ne, row, col, val, factors, rhs, x, control, sinfo,
@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,
control::Ref{ma48_control{Float32}}, sinfo::Ref{ma48_sinfo},
trans::Cint,
resid::Ptr{Float32}, error::Ptr{Float32})::Cvoid
end

Expand All @@ -116,7 +133,8 @@ 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
cols::Ptr{Cint},
control::Ref{ma48_control{Float32}})::Cint
end

function ma48_determinant_s(factors, sgndet, logdet, control)
Expand All @@ -136,7 +154,8 @@ function ma48_analyse_d(m, n, ne, row, col, val, factors, control, ainfo, finfo,
@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
finfo::Ref{ma48_finfo{Float64}}, perm::Ptr{Cint},
endcol::Ptr{Cint})::Cvoid
end

function ma48_get_perm_d(m, n, factors, perm, control)
Expand All @@ -147,15 +166,17 @@ 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,
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,
control::Ref{ma48_control{Float64}}, sinfo::Ref{ma48_sinfo},
trans::Cint,
resid::Ptr{Float64}, error::Ptr{Float64})::Cvoid
end

Expand All @@ -165,7 +186,8 @@ 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
cols::Ptr{Cint},
control::Ref{ma48_control{Float64}})::Cint
end

function ma48_determinant_d(factors, sgndet, logdet, control)
Expand Down
64 changes: 44 additions & 20 deletions src/C/hsl_ma57.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ mutable struct ma57_control{T}
ordering::Cint
scaling::Cint
rank_deficient::Cint
ispare::NTuple{5,Cint}
rspare::NTuple{10,T}
ispare::NTuple{5, Cint}
rspare::NTuple{10, T}

ma57_control{T}() where T = new()
ma57_control{T}() where {T} = new()

ma57_control{T}(f_arrays, multiplier, reduce, u, static_tolerance, static_level, tolerance, convergence, consist, lp, wp, mp, sp, ldiag, nemin, factorblocking, solveblocking, la, liw, maxla, maxliw, pivoting, thresh, ordering, scaling, rank_deficient, ispare, rspare) where T = new(f_arrays, multiplier, reduce, u, static_tolerance, static_level, tolerance, convergence, consist, lp, wp, mp, sp, ldiag, nemin, factorblocking, solveblocking, la, liw, maxla, maxliw, pivoting, thresh, ordering, scaling, rank_deficient, ispare, rspare)
function ma57_control{T}(f_arrays, multiplier, reduce, u, static_tolerance, static_level,
tolerance, convergence, consist, lp, wp, mp, sp, ldiag, nemin,
factorblocking, solveblocking, la, liw, maxla, maxliw, pivoting, thresh,
ordering, scaling, rank_deficient, ispare, rspare) where {T}
return new(f_arrays, multiplier, reduce, u, static_tolerance, static_level, tolerance,
convergence, consist, lp, wp, mp, sp, ldiag, nemin, factorblocking, solveblocking,
la, liw, maxla, maxliw, pivoting, thresh, ordering, scaling, rank_deficient, ispare,
rspare)
end
end

function ma57_default_control_s(control)
Expand Down Expand Up @@ -59,12 +67,16 @@ mutable struct ma57_ainfo{T}
dup::Cint
maxfrt::Cint
stat::Cint
ispare::NTuple{5,Cint}
rspare::NTuple{10,T}
ispare::NTuple{5, Cint}
rspare::NTuple{10, T}

ma57_ainfo{T}() where T = new()
ma57_ainfo{T}() where {T} = new()

ma57_ainfo{T}(opsa, opse, flag, more, nsteps, nrltot, nirtot, nrlnec, nirnec, nrladu, niradu, ncmpa, ordering, oor, dup, maxfrt, stat, ispare, rspare) where T = new(opsa, opse, flag, more, nsteps, nrltot, nirtot, nrlnec, nirnec, nrladu, niradu, ncmpa, ordering, oor, dup, maxfrt, stat, ispare, rspare)
function ma57_ainfo{T}(opsa, opse, flag, more, nsteps, nrltot, nirtot, nrlnec, nirnec, nrladu,
niradu, ncmpa, ordering, oor, dup, maxfrt, stat, ispare, rspare) where {T}
return new(opsa, opse, flag, more, nsteps, nrltot, nirtot, nrlnec, nirnec, nrladu, niradu,
ncmpa, ordering, oor, dup, maxfrt, stat, ispare, rspare)
end
end

function ma57_analyse_s(n, ne, row, col, factors, control, ainfo, perm)
Expand Down Expand Up @@ -100,18 +112,25 @@ mutable struct ma57_finfo{T}
modstep::Cint
rank::Cint
stat::Cint
ispare::NTuple{5,Cint}
rspare::NTuple{10,T}
ispare::NTuple{5, Cint}
rspare::NTuple{10, T}

ma57_finfo{T}() where T = new()
ma57_finfo{T}() where {T} = new()

ma57_finfo{T}(opsa, opse, opsb, maxchange, smin, smax, flag, more, maxfrt, nebdu, nrlbdu, nirbdu, nrltot, nirtot, nrlnec, nirnec, ncmpbr, ncmpbi, ntwo, neig, delay, signc, static_, modstep, rank, stat, ispare, rspare) where T = new(opsa, opse, opsb, maxchange, smin, smax, flag, more, maxfrt, nebdu, nrlbdu, nirbdu, nrltot, nirtot, nrlnec, nirnec, ncmpbr, ncmpbi, ntwo, neig, delay, signc, static_, modstep, rank, stat, ispare, rspare)
function ma57_finfo{T}(opsa, opse, opsb, maxchange, smin, smax, flag, more, maxfrt, nebdu, nrlbdu,
nirbdu, nrltot, nirtot, nrlnec, nirnec, ncmpbr, ncmpbi, ntwo, neig, delay,
signc, static_, modstep, rank, stat, ispare, rspare) where {T}
return new(opsa, opse, opsb, maxchange, smin, smax, flag, more, maxfrt, nebdu, nrlbdu, nirbdu,
nrltot, nirtot, nrlnec, nirnec, ncmpbr, ncmpbi, ntwo, neig, delay, signc, static_,
modstep, rank, stat, ispare, rspare)
end
end

function ma57_factorize_s(n, ne, row, col, val, factors, control, finfo)
@ccall libhsl.ma57_factorize_s(n::Cint, ne::Cint, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float32}, factors::Ptr{Ptr{Cvoid}},
control::Ref{ma57_control{Float32}}, finfo::Ref{ma57_finfo{Float32}})::Cvoid
control::Ref{ma57_control{Float32}},
finfo::Ref{ma57_finfo{Float32}})::Cvoid
end

mutable struct ma57_sinfo{T}
Expand All @@ -122,12 +141,14 @@ mutable struct ma57_sinfo{T}
error::T
flag::Cint
stat::Cint
ispare::NTuple{5,Cint}
rspare::NTuple{10,T}
ispare::NTuple{5, Cint}
rspare::NTuple{10, T}

ma57_sinfo{T}() where T = new()
ma57_sinfo{T}() where {T} = new()

ma57_sinfo{T}(cond, cond2, berr, berr2, error, flag, stat, ispare, rspare) where T = new(cond, cond2, berr, berr2, error, flag, stat, ispare, rspare)
function ma57_sinfo{T}(cond, cond2, berr, berr2, error, flag, stat, ispare, rspare) where {T}
return new(cond, cond2, berr, berr2, error, flag, stat, ispare, rspare)
end
end

function ma57_solve_s(n, ne, row, col, val, factors, nrhs, x, control, sinfo, rhs, iter, cond)
Expand Down Expand Up @@ -186,7 +207,8 @@ function ma57_sparse_lsolve_s(factors, control, nzrhs, irhs, nzsoln, isoln, x, s
end

function ma57_fredholm_alternative_s(factors, control, x, fredx, sinfo)
@ccall libhsl.ma57_fredholm_alternative_s(factors::Ptr{Ptr{Cvoid}}, control::Ref{ma57_control{Float32}},
@ccall libhsl.ma57_fredholm_alternative_s(factors::Ptr{Ptr{Cvoid}},
control::Ref{ma57_control{Float32}},
x::Ptr{Float32}, fredx::Ptr{Float32},
sinfo::Ref{ma57_sinfo{Float32}})::Cvoid
end
Expand Down Expand Up @@ -224,7 +246,8 @@ end
function ma57_factorize_d(n, ne, row, col, val, factors, control, finfo)
@ccall libhsl.ma57_factorize_d(n::Cint, ne::Cint, row::Ptr{Cint}, col::Ptr{Cint},
val::Ptr{Float64}, factors::Ptr{Ptr{Cvoid}},
control::Ref{ma57_control{Float64}}, finfo::Ref{ma57_finfo{Float64}})::Cvoid
control::Ref{ma57_control{Float64}},
finfo::Ref{ma57_finfo{Float64}})::Cvoid
end

function ma57_solve_d(n, ne, row, col, val, factors, nrhs, x, control, sinfo, rhs, iter, cond)
Expand Down Expand Up @@ -283,7 +306,8 @@ function ma57_sparse_lsolve_d(factors, control, nzrhs, irhs, nzsoln, isoln, x, s
end

function ma57_fredholm_alternative_d(factors, control, x, fredx, sinfo)
@ccall libhsl.ma57_fredholm_alternative_d(factors::Ptr{Ptr{Cvoid}}, control::Ref{ma57_control{Float64}},
@ccall libhsl.ma57_fredholm_alternative_d(factors::Ptr{Ptr{Cvoid}},
control::Ref{ma57_control{Float64}},
x::Ptr{Float64}, fredx::Ptr{Float64},
sinfo::Ref{ma57_sinfo{Float64}})::Cvoid
end
Expand Down
Loading

0 comments on commit 0f5ce85

Please sign in to comment.