Embedding Julia code in parallel C++

Hey all- I’m working on a rather large machine learning project that entails using a C++ main to call functions written in Julia. In addition the regular pain of who manages what variables and how to translate between bitwise variable representations, one issue that has come up is that we plan to parallelize the C++ code. This will entail having multiple C++ threads, all of which need to call the same Julia precompiled library.

Is this possible? Is Julia re-entrant, for lack of a better word?

Linking related post.

The answer seems to be no, according to the linked post from the answer above, that is embedding two or more instances of Julia not supported.

Before that link, I wanted to find out for myself, can be fun to see what you can figure out yourself, and to help you. There’s nothing definitive I could find in the docs, and looking at the source code is going down quite the rabbit-hole.

What I found, but not sure the meaning of:
https://github.com/JuliaLang/julia/search?q=jl_init__threading

The docs state you should use jl_init. jl_init__threading was deleted then brought back, so I’m very curious what it’s for:
https://github.com/JuliaLang/julia/commit/829d7e090f2cadfe1b1d506394f416b2938b3e7e#diff-cf6e417d01a6e25b814df855f594119c5d96891b39091abc802a5b6b04a86a56

I’m pretty sure you would only initialize Julia once, and then it’s unclear where you go from there. Julia has threads now. There might be some workaround, other than letting Julia “drive”, which is supported, letting Julia take care of threading.

[Github tells me Julia is (partially) written in PHP. :slight_smile: That’s of course not true, it only detects PHP from the .inc file.]