Does Polyester.jl compose with tasks launched with Threads.@threads
etc? i.e., will launching a bunch of tasks with both simultaneously cause oversubscription? I see in the README there's a section about using disable_polyester_threads()
, but I don't know if that's because it doesn't compose well with Base.Threads
, or if it's just to avoid the overhead of launching too many tasks.
No, it does not compose well
Ah, that's unfortunate. Do you know why? I browsed the repo and docs but couldn't really grok how it works, it's pretty under-documented.
It's basically an orthogonal threading system that makes different tradeoffs in order to get lower overhead. From what I understand, it would lose those benefits if it tried to compose well
Maybe @chriselrod can expand or correct what I've said though
Any other things one shouldn't use Polyester for in preference to base Threads? The only thing that comes to mind for me is that I once had a problem when trying to @batch
something that including making and saving some Plots.jl plots but wasn't sure if it was because of Plots.jl doing weird non-thread-safe things or something else
I don't know of any cases where Polyester isn't prefereable to Threads.@threads
, but Polyester also has no replacement for things like Threads.@spawn
as far as I'm aware.
I see, thanks.
Polyester won't oversubscribe your CPU, because it runs on regular Julia tasks that get scheduled by the regular scheduler.
Instead of having a short lifetime, these tasks live until you exit Julia. Polyester works by telling them what to do.
It is faster because it avoids spawning new tasks and getting the scheduler to schedule them. It is much more direct in this way.
ThreadingUtilities is the library that provides both the task pool, and the ability to send them code to run.
PolyesterWeave is the extremely naive scheduling library that Polyester, LoopVectorization, and Octavian use.
One could experiment with writing other scheduling libraries/taking other approaches. That'd be interesting, but unfortunately not something I have time for. An alternative to PolyesterWeave that supports @spawn
/implements work-stealing while still quickly allowing one to launch large threaded jobs would be great.
I think code should generally work when you run Polyester and base threading together, but it will likely regress performance.
Ah thanks, that clears up a lot :thumbs_up:
Last updated: Nov 06 2024 at 04:40 UTC