Skip to content

Commit

Permalink
[MC66] first draft of the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Oct 6, 2022
1 parent 897256b commit 73b0720
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 9 deletions.
8 changes: 0 additions & 8 deletions deps/versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,4 @@ hsl_collection["hsl_mc66"] = [
".zip",
),
]

hsl_collection["hsl_mi35"] = [
HSLVersion(
"2.0.1",
"39d22d55dd36776e5400313b8c2915bb39823b19740aee7a390937072f7cd7b1",
".zip",
),
]
#! format: on
5 changes: 4 additions & 1 deletion src/HSL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function __init__()
LinearAlgebra.BLAS.lbt_forward(OpenBLAS32_jll.libopenblas_path)
end
end
if (@isdefined libhsl_ma57) || (@isdefined libhsl_ma97) || (@isdefined libmc21)
if (@isdefined libhsl_ma57) || (@isdefined libhsl_ma97) || (@isdefined libmc21) || (@isdefined libhsl_mc66)
check_deps()
end
end
Expand All @@ -46,5 +46,8 @@ end
if (@isdefined libmc21) || haskey(ENV, "DOCUMENTER_KEY")
include("mc21.jl")
end
if (@isdefined libhsl_mc66) || haskey(ENV, "DOCUMENTER_KEY")
include("hsl_mc66.jl")
end

end
71 changes: 71 additions & 0 deletions src/hsl_mc66.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export mc66, mc66_control

mutable struct mc66_control{T <: BLAS.BlasReal}
lp::Int32
wp::Int32
mp::Int32
print_level::Int32
max_imbalance::T
mglevel::Int32
coarsen_scheme::Int32
coarsest_size::Int32
num_coarsest_kl::Int32
grid_rdc_fac::T
kl_agressive::T
end

function mc66_control{T}(; lp=6, wp=6, mp=6, print_level=-1, max_imbalance=0.01,
mglevel=typemax(Int32), coarsen_scheme=1,
coarsest_size=100, num_coarsest_kl=4,
grid_rdc_fac=0.75, kl_agressive=-1) where {T <: BLAS.BlasReal}

control = mc66_control{T}(lp, wp, mp, print_level, max_imbalance, mglevel, coarsen_scheme,
coarsest_size, num_coarsest_kl, grid_rdc_fac, kl_agressive)
return control
end

#! format: off
# Thanks to `nm -D libhsl_mc66.so`!
function mc66s(m, n, nz, irn, jcn, nblocks, control, seed, row_order, info, rowptr, column_order, colptr, netcut, rowdiff, kblocks)
ccall((:__hsl_mc66_simple_MOD_monet, libhsl_mc66),
Nothing,
(Ptr{Int32}, Ref{Int32}, Ref{Int32}, Ptr{Int32}, Ptr{Int32}, Ref{Int32}, Ref{mc66_control{Float32}}, Ref{Int32}, Ptr{Int32}, Ref{Int32}, Ptr{Int32}, Ptr{Int32} , Ptr{Int32}, Ref{Int32}, Ref{Float32}, Ref{Int32}),
m , n , nz , irn , jcn , nblocks , control , seed , row_order , info , rowptr , column_order, colptr , netcut , rowdiff , kblocks )
end

function mc66d(m, n, nz, irn, jcn, nblocks, control, seed, row_order, info, rowptr, column_order, colptr, netcut, rowdiff, kblocks)
ccall((:__hsl_mc66_double_MOD_monet, libhsl_mc66),
Nothing,
(Ptr{Int32}, Ref{Int32}, Ref{Int32}, Ptr{Int32}, Ptr{Int32}, Ref{Int32}, Ref{mc66_control{Float64}}, Ref{Int32}, Ptr{Int32}, Ref{Int32}, Ptr{Int32}, Ptr{Int32} , Ptr{Int32}, Ref{Int32}, Ref{Float64}, Ref{Int32}),
m , n , nz , irn , jcn , nblocks , control , seed , row_order , info , rowptr , column_order, colptr , netcut , rowdiff , kblocks )
end
#! format: on

"""
rp, cp = mc66(A::SparseMatrixCSC, k::Integer)
Order an unsymmetric matrix A into singly bordered blocked diagonal (SBBD) form.
"""
function mc66(A::SparseMatrixCSC{T}, nblocks::Integer) where {T <: BLAS.BlasReal}
m, n = size(A)
m = Ref{Int32}(m)
n = Ref{Int32}(n)
nz = Ref{Int32}(nnz(A))
irn, jcn, val = findnz(A)
irn = convert(Vector{Cint}, irn)
jcn = convert(Vector{Cint}, jcn)
nblocks = Ref{Int32}(nblocks)
control = mc66_control{T}()
seed = Ref{Int32}(abs(rand(Int32)))
row_order = zeros(Cint, m[])
info = Ref{Cint}()
rowptr = zeros(Cint, nblocks[]+1)
column_order = zeros(Cint, n[])
colptr = zeros(Cint, nblocks[]+1)
netcut = Ref{Cint}()
rowdiff = Ref{T}()
kblocks = Ref{Cint}()
(T == Float32) && mc66s(m, n, nz, irn, jcn, nblocks, control, seed, row_order, info, rowptr, column_order, colptr, netcut, rowdiff, kblocks)
(T == Float64) && mc66d(m, n, nz, irn, jcn, nblocks, control, seed, row_order, info, rowptr, column_order, colptr, netcut, rowdiff, kblocks)
return row_order, column_order
end

0 comments on commit 73b0720

Please sign in to comment.