Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Understanding the C++ bindings #18

Closed
gdalle opened this issue Jun 4, 2024 · 4 comments
Closed

Understanding the C++ bindings #18

gdalle opened this issue Jun 4, 2024 · 4 comments

Comments

@gdalle
Copy link
Collaborator

gdalle commented Jun 4, 2024

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

ret = @ccall libcolpack.build_coloring_from_csr(
refColPack::Ptr{Cvoid},
reflen::Ptr{Cint},
csr::Ref{Ptr{Cuint}},
nrows::Cint,
method.method::Cstring,
order.order::Cstring,
verbose::Cint,
)::Cint

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
Copy link
Member

amontoison commented Jun 5, 2024

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
Copy link
Member

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: michel2323/ColPack@e2290df
It should not be too hard to fix it.

@amontoison
Copy link
Member

@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
Copy link
Collaborator Author

gdalle commented Jun 5, 2024

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:

  • a conversion from our SparseMatrixCSC to a matrix format that ColPack in C++ can eat
  • a way to perform the following colorings (method -m):
    • STAR on general graphs
    • COLUMN_PARTIAL_DISTANCE_TWO and ROW_PARTIAL_DISTANCE_TWO on bipartite graphs
  • with all the available orders (-o): NATURAL, RANDOM, etc.
  • a way to retrieve the colors as a Julia vector

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)

@gdalle gdalle linked a pull request Jun 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants