Avoid array duplication

I have a data structure in Julia (CSR matrix, essentially).
The same data structure is used in a C++ library that I use from Julia.

The question is “how do I avoid the penalty for copying data”?

Pass a Julia array to C, that seems the natural thing to do, but: Is that (i) portable, and (ii) robust (not too low-level)?

Have you searched in GitHub - JuliaPackaging/Yggdrasil: Collection of builder repositories for BinaryBuilder.jl if there is maybe a library which is compatible on a C++ level and which is already wrapped for Julia with proper functions for converting? (What is the target C++ library who’s format you want to satisfy?)

Actually, the library is nearly plain C. And it would be sufficient to pass a plain integer array. (GitHub - PetrKryslUCSD/ECLGraphColor.jl)

(Funny, I’m also implementing [just greedy] Graph coloring on GPUs today.)

To the question. First of all, you are more experienced than me. Anyway, I found this here: SparseArrays.jl/src/solvers/wrappers.jl at 3b303335db89ecaad55fde31a88c4eb1dab84e4c · JuliaSparse/SparseArrays.jl · GitHub where a core Julia package does the same. Defining a Julia struct and then passing that as a pointer. It seems to me there is no way around. If nobody did the low-level work you seem to have little alternatives.

That is a good point: Something like this might be done with SuiteSparse, for instance. Actually, I even found it in the manual now (Calling C and Fortran Code · The Julia Language). Must have been blind before … :roll_eyes:

That is a curious coincidence! :slight_smile:

1 Like