Pin the first min(length(cpuids), nthreads) Julia threads to an explicit or implicit list
of CPU ids. The latter can be specified in three ways:
1) explicitly (e.g. 0:3 or [0,12,4]),
2) by passing one of several predefined symbols (e.g. :cores or :sockets),
3) by providing a logical specification via helper functions (e.g. node and socket).
See below for more information.
If force=false the pinthreads call will only pin threads
if this is the first attempt to pin threads with ThreadPinning.jl. Otherwise it will be a
no-op. This may be particularly useful for packages that merely want to specify a
"default pinning".
The option warn toggles general warnings, such as unwanted interference with BLAS thread
settings.
1) Explicit
Simply provide an AbstractVector{<:Integer} of CPU ids. The latter are expected to be the
"physical" ids, i.e. as provided by lscpu, and thus start at zero!
2) Predefined Symbols
:cputhreads or :compact: successively pin to all available CPU threads.
:cores: spread threads across all available cores, only use hyperthreads if necessary.
:sockets: spread threads across sockets (round-robin), only use hyperthreads if
necessary. Set compact=true to get compact pinning within each socket.
:numa: spread threads across NUMA/memory domains (round-robin), only use hyperthreads
if necessary. Set compact=true to get compact pinning within each NUMA/memory
domain.
:random: pin threads randomly to CPU threads
:current: pin threads to the CPU threads they are currently running on
:firstn: pin threads to CPU threads in "physical" order (as specified by lscpu).
3) Logical Specification
The functions node, socket, numa, and core can be used to to specify CPU ids
of/within a certain domain. Moreover, the functions sockets and numas can be used to
express a scatter policy (round-robin) between sockets or NUMA domains, respectively.
Examples (domains):
pinthreads(socket(1, 1:3)) # pin to the first 3 cores in the first socket
pinthreads(socket(1, 1:3; compact=true)) # pin to the first 3 CPU threads in the first
socket
pinthreads(numa(2, [2,4,6])) # pin to the second, the fourth, and the sixth cores in
the second NUMA/memory domain
pinthreads(node(ncores():-1:1)) # pin threads to cores in reversing order (starting at
the end of the node)
pinthreads(sockets()) # scatter threads between sockets, cores before hyperthreads
Different domains can be concatenated by providing them in a vector or as separate
arguments to pinthreads.
TODOs
pinthreads_likwidpin
(#43)pin
likwidpin
JULIA_PIN
JULIA_LIKWID_PIN
See
?pinthreads
for the new interface. Citing it here for clarity:New
pinthreads
docstring:Pin the first
min(length(cpuids), nthreads)
Julia threads to an explicit or implicit list of CPU ids. The latter can be specified in three ways:1) explicitly (e.g.
0:3
or[0,12,4]
), 2) by passing one of several predefined symbols (e.g.:cores
or:sockets
), 3) by providing a logical specification via helper functions (e.g.node
andsocket
).See below for more information.
If
force=false
thepinthreads
call will only pin threads if this is the first attempt to pin threads with ThreadPinning.jl. Otherwise it will be a no-op. This may be particularly useful for packages that merely want to specify a "default pinning".The option
warn
toggles general warnings, such as unwanted interference with BLAS thread settings.1) Explicit
Simply provide an
AbstractVector{<:Integer}
of CPU ids. The latter are expected to be the "physical" ids, i.e. as provided bylscpu
, and thus start at zero!2) Predefined Symbols
:cputhreads
or:compact
: successively pin to all available CPU threads.:cores
: spread threads across all available cores, only use hyperthreads if necessary.:sockets
: spread threads across sockets (round-robin), only use hyperthreads if necessary. Setcompact=true
to get compact pinning within each socket.:numa
: spread threads across NUMA/memory domains (round-robin), only use hyperthreads if necessary. Setcompact=true
to get compact pinning within each NUMA/memory domain.:random
: pin threads randomly to CPU threads:current
: pin threads to the CPU threads they are currently running on:firstn
: pin threads to CPU threads in "physical" order (as specified by lscpu).3) Logical Specification
The functions
node
,socket
,numa
, andcore
can be used to to specify CPU ids of/within a certain domain. Moreover, the functionssockets
andnumas
can be used to express a scatter policy (round-robin) between sockets or NUMA domains, respectively.Examples (domains):
pinthreads(socket(1, 1:3))
# pin to the first 3 cores in the first socketpinthreads(socket(1, 1:3; compact=true))
# pin to the first 3 CPU threads in the first socketpinthreads(numa(2, [2,4,6]))
# pin to the second, the fourth, and the sixth cores in the second NUMA/memory domainpinthreads(node(ncores():-1:1))
# pin threads to cores in reversing order (starting at the end of the node)pinthreads(sockets())
# scatter threads between sockets, cores before hyperthreadsDifferent domains can be concatenated by providing them in a vector or as separate arguments to
pinthreads
.Examples (concatenation):
pinthreads([socket(1, 1:3), numa(2, 4:6)])
pinthreads(socket(1, 1:3), numa(2, 4:6))
Closes #39 Closes #27 Closes #43