carstenbauer / ThreadPinning.jl

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

Unpinning and thread affinity printing #34

Closed carstenbauer closed 1 year ago

carstenbauer commented 1 year ago

Closes #33

Based on libuv.

Introduces unpinthread, unpinthreads, threadinfo(; masks=true), and ThreadPinning.print_affinity_masks().

carstenbauer commented 1 year ago

Showcase

julia> using ThreadPinning

julia> threadinfo(; masks=true)

| 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
  16,17,18,19 |
| 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,
  36,37,38,39 |

# = Julia thread, | = Socket seperator

Julia threads: 16
├ Occupied CPU-threads: 16
└ Mapping (Thread => CPUID): 1 => 36, 2 => 34, 3 => 35, 4 => 37, 5 => 38, ...

1:   |11111111111111111111|11111111111111111111|
2:   |11111111111111111111|11111111111111111111|
3:   |11111111111111111111|11111111111111111111|
4:   |11111111111111111111|11111111111111111111|
5:   |11111111111111111111|11111111111111111111|
6:   |11111111111111111111|11111111111111111111|
7:   |11111111111111111111|11111111111111111111|
8:   |11111111111111111111|11111111111111111111|
9:   |11111111111111111111|11111111111111111111|
10:  |11111111111111111111|11111111111111111111|
11:  |11111111111111111111|11111111111111111111|
12:  |11111111111111111111|11111111111111111111|
13:  |11111111111111111111|11111111111111111111|
14:  |11111111111111111111|11111111111111111111|
15:  |11111111111111111111|11111111111111111111|
16:  |11111111111111111111|11111111111111111111|

julia> pinthreads(:compact)

julia> ThreadPinning.print_affinity_masks()
1:   |10000000000000000000|00000000000000000000|
2:   |01000000000000000000|00000000000000000000|
3:   |00100000000000000000|00000000000000000000|
4:   |00010000000000000000|00000000000000000000|
5:   |00001000000000000000|00000000000000000000|
6:   |00000100000000000000|00000000000000000000|
7:   |00000010000000000000|00000000000000000000|
8:   |00000001000000000000|00000000000000000000|
9:   |00000000100000000000|00000000000000000000|
10:  |00000000010000000000|00000000000000000000|
11:  |00000000001000000000|00000000000000000000|
12:  |00000000000100000000|00000000000000000000|
13:  |00000000000010000000|00000000000000000000|
14:  |00000000000001000000|00000000000000000000|
15:  |00000000000000100000|00000000000000000000|
16:  |00000000000000010000|00000000000000000000|

julia> unpinthread(3)
true

julia> ThreadPinning.print_affinity_masks()
1:   |10000000000000000000|00000000000000000000|
2:   |01000000000000000000|00000000000000000000|
3:   |11111111111111111111|11111111111111111111|
4:   |00010000000000000000|00000000000000000000|
5:   |00001000000000000000|00000000000000000000|
6:   |00000100000000000000|00000000000000000000|
7:   |00000010000000000000|00000000000000000000|
8:   |00000001000000000000|00000000000000000000|
9:   |00000000100000000000|00000000000000000000|
10:  |00000000010000000000|00000000000000000000|
11:  |00000000001000000000|00000000000000000000|
12:  |00000000000100000000|00000000000000000000|
13:  |00000000000010000000|00000000000000000000|
14:  |00000000000001000000|00000000000000000000|
15:  |00000000000000100000|00000000000000000000|
16:  |00000000000000010000|00000000000000000000|

julia> unpinthreads()

julia> ThreadPinning.print_affinity_masks()
1:   |11111111111111111111|11111111111111111111|
2:   |11111111111111111111|11111111111111111111|
3:   |11111111111111111111|11111111111111111111|
4:   |11111111111111111111|11111111111111111111|
5:   |11111111111111111111|11111111111111111111|
6:   |11111111111111111111|11111111111111111111|
7:   |11111111111111111111|11111111111111111111|
8:   |11111111111111111111|11111111111111111111|
9:   |11111111111111111111|11111111111111111111|
10:  |11111111111111111111|11111111111111111111|
11:  |11111111111111111111|11111111111111111111|
12:  |11111111111111111111|11111111111111111111|
13:  |11111111111111111111|11111111111111111111|
14:  |11111111111111111111|11111111111111111111|
15:  |11111111111111111111|11111111111111111111|
16:  |11111111111111111111|11111111111111111111|

@vchuravy, happy with this? 😄

vchuravy commented 1 year ago

Very!