carstenbauer / ThreadPinning.jl

Readily pin Julia threads to CPU-threads
https://carstenbauer.github.io/ThreadPinning.jl/
MIT License
106 stars 7 forks source link

Add support for interactive threads #56

Closed simsurace closed 1 year ago

simsurace commented 1 year ago

Julia 1.9 will introduce an interactive thread pools. Maybe the interactive threads can be pinned to specific cores/cpu threads as well?

carstenbauer commented 1 year ago

Absolutely! Since these "interactive threads" aren't particularly special with respect to affinity, you can already pin them right now:

(julia +1.9 -t 2,3)

julia> using ThreadPinning

julia> [getcpuid(i) for i in 1:Threads.maxthreadid()]
5-element Vector{Int64}:
 17
 12
 14
 16
 18

julia> for i in 1:Threads.maxthreadid()
           pinthread(i, i)
       end

julia> [getcpuid(i) for i in 1:Threads.maxthreadid()]
5-element Vector{Int64}:
 1
 2
 3
 4
 5

It'd still be nice to have "proper" support for the new threadpool feature in ThreadPinning.jl (in particular in getcpuid(s), pinthread(s), and threadinfo). I've already started with this (@tspawnat works and threadinfo has a premature threadpool option) but my short sprint was halfhearted at best.

If you're willing to, please open a PR! I'd be happy to help with comments and pointers.

simsurace commented 1 year ago

Funny you get 5 threads here. Any thoughts on this question on Slack?

simsurace commented 1 year ago

https://github.com/JuliaLang/julia/issues/48580

carstenbauer commented 1 year ago

Funny you get 5 threads here.

Note that I use Threads.maxthreadid() (rather than Threads.nthreads()). Up to the fact that, in principle, the number of Julia threads isn't strictly constant anymore in Julia 1.9 (AFAIU, the number can vary when one does parallel C/C++ interop of some kind), this is essentially equivalent to nthreads(:default) + nthreads(:interactive) and thus gives 5 as expected.

carstenbauer commented 1 year ago

@simsurace I've improved the thread pool support in ThreadPinning.jl a lot on the main branch. Among others, threadinfo, pinthreads, and getcpuids all have threadpool keyword arguments which can be set to :default, :interactive, or :all. Would be great if you could try this out, since I plan to tag a new release with this soon.

simsurace commented 1 year ago

I'll probably try this again quite soon, when https://github.com/JuliaLang/julia/pull/48702 has been released.