Skip to content

Commit

Permalink
Getting ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
michel2323 committed Feb 15, 2022
1 parent f33b028 commit 226a1da
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 16 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run tests

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
schedule:
- cron: '0 0 * * 0'

jobs:
test-github-cpuonly:
env:
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
julia-version: ['1.7']
julia-arch: [x64]

steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Michel Schanen, Daniel Adrian Maldonado, François Pacaud

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,17 @@ authors = ["Michel Schanen <[email protected]>"]
version = "0.1.0"

[deps]
ColPack_jll = "f218ff0c-cb54-5151-80c4-c0f62c730ce6"
MatrixMarket = "4d4711f2-db25-561a-b6b3-d35e7d4047d3"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
MatrixMarket = "0.3"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ColPack
[![][build-stable-img]][build-url]

This is the Julia interface to [ColPack](https://github.com/CSCsw/ColPack).

## Usage
```julia
verbose = 1
coloring = ColPackColoring("M.mtx", ColPack.d1, "RANDOM", 1)

println("Number of colors: ", length(unique(get_colors(coloring))))
println("Vector of vertex colors: ", get_colors(coloring))
```
[build-url]: https://github.com/michel2323/ColPack.jl/actions?query=workflow

[build-stable-img]: https://github.com/michel2323/ColPack.jl/workflows/Run%20tests/badge.svg?branch=master
33 changes: 28 additions & 5 deletions examples/coloring.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
using ColPack
using MatrixMarket
using SparseArrays
using SparseDiffTools
using LinearAlgebra

const filename = "/scratch/jac_case9241pegase_17036.mtx"

orderings = Vector{String}()

push!(orderings, "NATURAL")
push!(orderings, "LARGEST_FIRST")
push!(orderings, "DYNAMIC_LARGEST_FIRST")
push!(orderings, "DISTANCE_TWO_LARGEST_FIRST")
push!(orderings, "SMALLEST_LAST")
push!(orderings, "DISTANCE_TWO_SMALLEST_LAST")
push!(orderings, "INCIDENCE_DEGREE")
push!(orderings, "DISTANCE_TWO_INCIDENCE_DEGREE")
push!(orderings, "RANDOM")

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

@time sparsediff_coloring = SparseDiffTools.matrix_colors(A)
ncolor = size(unique(sparsediff_coloring),1)
@time colpack_coloring = ColPackColoring("/scratch/jac_case9241pegase_17036.mtx", ColPack.d1, "RANDOM", verbose)

coloring = ColPack(filename, ColPack.d1, "RANDOM", verbose)
colors = get_colors(coloring)
for ordering in orderings
colpack_coloring = ColPackColoring("/scratch/jac_case9241pegase_17036.mtx", ColPack.d1, ordering, verbose)
end
colors = get_colors(colpack_coloring)
@show length(unique(colors))
55 changes: 44 additions & 11 deletions src/ColPack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ module ColPack

using SparseArrays
using MatrixMarket
using ColPack_jll

const libcolpack = "/home/michel/git/ColPack.jl/ColPack/build/automake/build/lib/libColPack"
export ColPackColoring, get_colors

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

struct ColPack
struct ColPackColoring
refColPack::Vector{Ptr{Cvoid}}
coloring::Vector{Cint}
method::AbstractString
order::AbstractString
csr::Union{Vector{Ptr{Cuint}},Nothing}
end

function ColPack(filename::AbstractString, method::AbstractString, order::AbstractString, verbose::Int)
function ColPackColoring(filename::AbstractString, method::AbstractString, order::AbstractString, verbose::Int)
reflen = Vector{Cint}([Cint(0)])
refColPack = Vector{Ptr{Cvoid}}([C_NULL])
ret = ccall(
Expand All @@ -30,21 +31,53 @@ function ColPack(filename::AbstractString, method::AbstractString, order::Abstra
error("ColPack coloring failed.")
end

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

function ColPackColoring(M_::SparseMatrixCSC{VT,IT}, method::AbstractString, order::AbstractString, verbose::Int) where {VT,IT}
# Get the CSR by transposing
# M = convert(SparseMatrixCSC, transpose(M_))
M = M_
csr = Vector{Ref{Cuint}}()
@show length(M.colptr)
@show length(M.rowval)
@show length(M.nzval)
@show size(M)
for i in 1:(length(M.colptr) -1)
vec = Vector{Cuint}()
# Number of column elements of column elements
push!(vec, M.colptr[i+1] - M.colptr[i])
for j in M.colptr[i]:(M.colptr[i+1]-1)
push!(vec, M.rowval[j]-1)
end
push!(csr, Base.unsafe_convert(Ptr{Cuint}, vec))
end
nrows = size(M,2)
# @assert nrows == size(M,2)
reflen = Vector{Cint}([Cint(0)])
refColPack = Vector{Ptr{Cvoid}}([C_NULL])
ret = ccall(
(:build_coloring_from_csr, libcolpack),
Cint, (Ptr{Cvoid}, Ptr{Cint}, Ref{Ptr{Cuint}}, Cint, Cstring, Cstring, Cint),
refColPack, reflen, csr, nrows, method, order, verbose,
)
# exit()
if ret == 0
error("ColPack coloring failed.")
end

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

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

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

43 changes: 43 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using ColPack
using MatrixMarket
using Random
using SparseArrays
using Test

orderings = Vector{String}()

push!(orderings, "NATURAL")
push!(orderings, "LARGEST_FIRST")
push!(orderings, "DYNAMIC_LARGEST_FIRST")
push!(orderings, "DISTANCE_TWO_LARGEST_FIRST")
push!(orderings, "SMALLEST_LAST")
push!(orderings, "DISTANCE_TWO_SMALLEST_LAST")
push!(orderings, "INCIDENCE_DEGREE")
push!(orderings, "DISTANCE_TWO_INCIDENCE_DEGREE")
# push!(orderings, "RANDOM")

ncolors = Vector{Int}()

push!(ncolors, 11)
push!(ncolors, 9)
push!(ncolors, 9)
push!(ncolors, 10)
push!(ncolors, 10)
push!(ncolors, 10)
push!(ncolors, 9)
push!(ncolors, 9)
# push!(ncolors, 10)

Random.seed!(2713)
A = sprand(100,100,0.1)

const filename = joinpath(@__DIR__, "A.mtx")
MatrixMarket.mmwrite(filename, A)
verbose = 1

@testset "Test ColPack" begin
for (i,ordering) in enumerate(orderings)
coloring = ColPackColoring(filename, ColPack.d1, ordering, verbose)
@test length(unique(get_colors(coloring))) == ncolors[i]
end
end

0 comments on commit 226a1da

Please sign in to comment.