JuliaFolds2 / OhMyThreads.jl

Simple multithreading in julia
https://juliafolds2.github.io/OhMyThreads.jl/
MIT License
139 stars 9 forks source link

Reusable task-pool scheduler #79

Open MasonProtter opened 7 months ago

MasonProtter commented 7 months ago

Potentially related to or overlapping with https://github.com/JuliaFolds2/OhMyThreads.jl/issues/75, I think it'd be good if there was a scheduler that had a pre-allocated set of Tasks stored inside it that are then re-used, like how Polyester.jl handles its tasks.

This could help users avoid allocations and GC-latency, and also potentially do other things like re-use TaskLocalValues between multiple calls to tmapreduce. Definitely an advanced feature we shouldn't recommend to everyone, but in certain circumstances, it could be useful.

carstenbauer commented 7 months ago

I agree, this could be useful. If we want to implement new schedulers - say a dynamic load-balancing one that only uses a fixed subset of the threads - we probably need/want something like this. However, this is isn't just more advanced from a users POV but also (much?) more ambitious for us. AFAIR, Polyester jumps through a number of hoops to make the basics of this work.

MasonProtter commented 7 months ago

I think it doesn't necessarily need to be so complicated as Polyester, e.g. here's a much simpler go at the same idea: https://github.com/JuliaFolds2/FoldsThreads.jl/blob/master/src/taskpool.jl

but yes, this'd require a lot of design work to figure out properly. Not a short-term idea.