brenhinkeller / StaticTools.jl

Enabling StaticCompiler.jl-based compilation of (some) Julia code to standalone native binaries by avoiding GC allocations and llvmcall-ing all the things!
MIT License
167 stars 12 forks source link

Implement Threads #9

Open PallHaraldsson opened 2 years ago

PallHaraldsson commented 2 years ago

I suppose threads aren't yet implemented. I suppose it's hard so feel free to skip. Or at least comment on how difficult.

Since you already did mandelbrot I thought it might be low-hanging fruit as for another Julia program at Debian Benchmark Game, but the one there is already threaded so I may give up on that one.

Taking out write I got allocations (assuming because of the threading):

julia> @time mandelbrot(stdout, 8)
  0.000394 seconds (55 allocations: 4.703 KiB)

Since it's a constant known amount of threads and thus allocations, then maybe this actually would just work? Allocations only a problem if they actually trigger GC, and I could rely on not happening for such a small amount of?

brenhinkeller commented 2 years ago

Ah yeah, so as I understand it, enabling multithreading in StaticCompiler currently would be rather hard. On the StaticTools side, some of the Libc functions that StaticTools calls may not be thread-safe unless your Libc is thread-safe, but that's not likely what's causing any errors you'd get. Someday I'd like to be able to use MPI in StaticCompiler'd programs, but that's unlikely to work out of the box