exanauts / ColPack.jl

A Julia interface to the C++ library ColPack for graph and sparse matrix coloring.
https://exanauts.github.io/ColPack.jl/
MIT License
6 stars 0 forks source link

Understanding the C++ bindings #18

Closed gdalle closed 3 weeks ago

gdalle commented 1 month ago

Where does this function come from? What is the libcolpack object?

https://github.com/exanauts/ColPack.jl/blob/01dd2827473e2424b46323f9307b4c931799e82c/src/colpackcoloring.jl#L95-L103

I don't speak C++ so the ColPack documentation is very foreign to me. And I am not familiar with the jll mechanism either.

For Jacobian coloring, we would need to access the BipartiteGraph PartialColoringInterface instead (see the ColPack class hierarchy). Here are the three examples we want to reproduce in Julia:

amontoison commented 1 month ago

libcolpack is the path to the shared library libcolpack.$dlext where $dlext is so on Linux / FreeBSD, dll on Windows, and dylib on Mac. libcolpack contains all the (compiled) routines of ColPack.

When we create a recipe with Yggdrasil, the JLL package is generated such that the products (libraries or binaries) are exported as Julia variables. The build_tarballs.jl that is used to cross-compile ColPack is: https://github.com/JuliaPackaging/Yggdrasil/blob/master/C/ColPack/build_tarballs.jl

With @ccall we can directly call a C or Fortran routine but not C++ ones (except if they only have C-like arguments). If we want to call C++ routines, we need to create a C interface. This is what Michel did with his fork: https://github.com/michel2323/ColPack

amontoison commented 1 month ago

We need to update two files:

It seems that Michel already implemented what we want but he got some issues with OpenMP. I found this commit: https://github.com/michel2323/ColPack/commit/e2290dff4dc27985b9c1e5f45ae08e67f488798f It should not be too hard to fix it.

amontoison commented 1 month ago

@gdalle I did a few modifications on my fork: https://github.com/amontoison/ColPack/

I just updated the C routine build_coloring. Do you need additional modifications / additional C routines?

I also the build system such that the binary ColPack is available in the JLL: https://github.com/CSCsw/ColPack/tree/master/Examples

gdalle commented 1 month ago

Thanks! I can't judge the modifications to the C++ code though.

To sum up, based on https://github.com/CSCsw/ColPack/tree/master/Examples, all we need from ColPack.jl is:

As long as a function like this is available, I don't care what goes on under the hood:

colpack_coloring(matrix::SparseMatrixCSC, method::Symbol, order::Symbol)