Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michel2323 committed Feb 14, 2022
0 parents commit f33b028
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name = "ColPack"
uuid = "ffa27691-3a59-46ab-a8d4-551f45b8d401"
authors = ["Michel Schanen <[email protected]>"]
version = "0.1.0"

[deps]
MatrixMarket = "4d4711f2-db25-561a-b6b3-d35e7d4047d3"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
9 changes: 9 additions & 0 deletions examples/coloring.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using ColPack

verbose = 1
A = sprand(100, 100, 0.1)
MatrixMarket.mmwrite(filename, A)
ccall((:hello, libcolpack), Cvoid, ())

coloring = ColPack(filename, ColPack.d1, "RANDOM", verbose)
colors = get_colors(coloring)
50 changes: 50 additions & 0 deletions src/ColPack.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module ColPack

using SparseArrays
using MatrixMarket

const libcolpack = "/home/michel/git/ColPack.jl/ColPack/build/automake/build/lib/libColPack"

const filename = "mat.mtx"
const d1 = "DISTANCE_ONE"
const d2 = "DISTANCE_TWO"
const acyclic = "ACYCLIC",
const star = "STAR",

struct ColPack
refColPack::Vector{Ptr{Cvoid}}
coloring::Vector{Cint}
method::AbstractString
order::AbstractString
end

function ColPack(filename::AbstractString, method::AbstractString, order::AbstractString, verbose::Int)
reflen = Vector{Cint}([Cint(0)])
refColPack = Vector{Ptr{Cvoid}}([C_NULL])
ret = ccall(
(:build_coloring, libcolpack),
Cint, (Ptr{Cvoid}, Ptr{Cint}, Cstring, Cstring, Cstring, Cint),
refColPack, reflen, filename, method, order, verbose,
)
if ret == 0
error("ColPack coloring failed.")
end

println("Coloring length $(reflen[1])")
return ColPack(refColPack, zeros(Int, reflen[1]), method, order)
end

function get_colors(coloring::ColPack)
ccall(
(:get_colors, libcolpack),
Cvoid, (Ptr{Cvoid}, Ptr{Cdouble}, Cstring),
coloring.refColPack[1], coloring.coloring, coloring.method,
)
@show coloring.coloring
end

@show length(get_colors(coloring))
@show unique(colors)
@show length(unique(colors))
end #module

0 comments on commit f33b028

Please sign in to comment.