Hi Everyone. This is my first time using this forum....
Here is my current situation:
When I ccall my C function from Julia, the C function has to do some initial work that takes a lot of time. Then it processes the data Julia sent to it.
A very short time later, Julia has some new data. Julia then ccall the C function again. The C function has to do the same initial work again causing a delay before it can process the new data Julia sent to it.
Ideally, I would like to be able to send new data from Julia to the C program without having to restart the C program with another ccall.
So, I thought perhaps I can have C "callback" a Julia function and retrieve data from the Julia function back into the C program.
What are your thoughts?
Hey Jeffrey, welcome.
Have you considered just setting a flag in the C function that determines if you repeat the setup work? E.g. you could make it so that it caches the setup work somewhere, and then when Julia calls the C function, it either calls the version that does the setup work, or it calls the version that fetches the setup work from last time
But I think doing mutual callbacks would probably work too
Hi Mason!
The mutual callback sounds interesting. I have C sending Julia data via a callback but is it possible for Julia to send data to C via this same callback?
https://julialang.org/blog/2013/05/callback/
I have an example of the classic mutual fibonacci recurrence in https://github.com/GunnarFarneback/DynamicallyLoadedEmbedding.jl/blob/2df94e871b4967f96fe41427fcecd529685f1fb0/c/main.c#L6-L19 and https://github.com/GunnarFarneback/DynamicallyLoadedEmbedding.jl/blob/2df94e871b4967f96fe41427fcecd529685f1fb0/src/julia_cfunctions.jl#L3-L14.
Also see here for a refinement callback for triangulations:
https://github.com/JuliaGeometry/Triangulate.jl/blob/master/src/ctriangulateio.jl and https://github.com/JuliaGeometry/Triangulate.jl/blob/master/deps/src/triwrap.c
Wow!!! Lots of good material...I need a bit more time to delve into it...I will circle back with you all soon though...thx!
Last updated: Nov 06 2024 at 04:40 UTC