API - Querying
threadinfo
ThreadPinning.threadinfo
— Functionthreadinfo(;
groupby = :sockets,
threadpool = :default,
blas = false,
slurm = false,
hints = false,
compact = true,
hyperthreads = SysInfo.hyperthreading_is_enabled(),
efficiency = SysInfo.ncorekinds() > 1,
masks = false,
coregaps = SysInfo.hyperthreading_is_enabled(),
logical = false,
color = true,
blocksize = choose_blocksize()
)
Print information about Julia threads, e.g. on which CPU-threads (i.e. cores if hyperthreading is disabled) they are running.
Keyword arguments
groupby
: Options are:sockets
,:numa
,:cores
, or:none
.threadpool
: Only consider Julia threads in the given thread pool. Supported values are:default
,:interactive
, and:all
.blas
: Visualize BLAS threads instead of Julia threads.slurm
: Only show the part of the system that is covered by the active SLURM allocation.hints
: Try to give some hints about how to improve the threading related settings.compact
: Toggle between compact and "cores before hyperthreads" ordering.hyperthreads
: Iftrue
, we (try to) highlight CPU-threads that aren't the first threads within a CPU-core.efficiency
: Iftrue
, we highlight (underline) CPU-threads that belong to efficiency cores.masks
: Show the affinity masks of all Julia threads.coregaps
: Put an extra space ("gap") between different CPU-cores, when printing.logical
: Toggle between logical and "physical" CPU-thread indices.color
: Toggle between colored and black-and-white output.blocksize
: Wrap to a new line afterblocksize
many CPU-threads. May also be set to:numa
in which case the line break will occur after each numa domain.
Querying
ThreadPinning.getcpuids
— Functiongetcpuids(; threadpool = :default)
Returns the IDs of the CPU-threads on which the Julia threads are currently running on.
The keyword argument threadpool
(default: :default
) may be used to specify a specific thread pool.
ThreadPinning.getcpuid
— Functiongetcpuid(; threadid = nothing)
Returns the ID of the CPU thread on which a Julia thread is currently running.
If threadid=nothing
(default), we query the id directly from the calling thread.
ThreadPinning.ispinned
— Functionispinned(; threadid = Threads.threadid())
Returns true
if the thread is pinned, that is, if it has an affinity mask that highlights a single CPU-thread.
ThreadPinning.getispinned
— Functiongetispinned(; threadpool = :default)
Returns the results of ispinned
for all Julia threads.
The keyword argument threadpool
(default: :default
) may be used to specify a specific thread pool.
ThreadPinning.getaffinity
— Functiongetaffinity(; threadid = Threads.threadid(), cutoff = cpuidlimit())
Get the thread affinity of a Julia thread. Returns the affinity mask as a vector of zeros and ones. By default, the mask is cut off at Sys.CPU_THREADS
. This can be tuned via the cutoff
keyword argument (nothing
means no cutoff).
ThreadPinning.printaffinity
— Functionprintaffinity(; threadid::Integer = Threads.threadid())
Print the affinity mask of the Julia thread.
The keyword argument groupby
may be used to change how CPU-threads are grouped visually. It defaults to groupby=:socket
. Other valid values are :numa
and :core
.
ThreadPinning.printaffinities
— Functionprintaffinities(; threadpool = :default, kwargs...)
Print the affinity masks of all Julia threads. See printaffinity
for options.
ThreadPinning.visualize_affinity
— FunctionVisualize the affinity mask of a Julia thread. Many of the keyword options of threadinfo
work here as well.
ThreadPinning.getnumanode
— Functiongetnumanode(; threadid = nothing)
Returns the ID (starting at zero) of the NUMA node corresponding to the CPU thread on which the calling thread is currently running. A threadid
may be provided to consider a Julia thread that is different from the calling one.
ThreadPinning.getnumanodes
— Functiongetnumanodes(; threadpool = :default)
Returns the IDs (starting at zero) of the NUMA nodes corresponding to the CPU threads on which the Julia threads are currently running.
The keyword argument threadpool
(default: :default
) may be used to consider only those Julia threads that belong to a specific thread pool.
Querying - Logical
ThreadPinning.core
— FunctionReturns the CPU IDs that belong to core i
(logical index, starts at 1). Set shuffle=true
to randomize.
Optional second argument: Logical indices to select a subset of the CPU-threads.
ThreadPinning.numa
— FunctionReturns the CPU IDs that belong to the i
th NUMA domain (logical index, starts at 1). By default, an "cores before hyperthreads" ordering is used. Set compact=true
if you want compact ordering. Set shuffle=true
to randomize.
Optional second argument: Logical indices to select a subset of the CPU-threads.
ThreadPinning.socket
— FunctionReturns the CPU IDs that belong to the i
th CPU/socket (logical index, starts at 1). By default, an "cores before hyperthreads" ordering is used. Set compact=true
if you want compact ordering. Set shuffle=true
to randomize.
Optional second argument: Logical indices to select a subset of the CPU-threads.
ThreadPinning.node
— FunctionReturns all CPU IDs of the system/compute node (logical index, starts at 1). By default, an "cores before hyperthreads" ordering is used. Set compact=true
if you want compact ordering. Set shuffle=true
to randomize.
Optional second argument: Logical indices to select a subset of the CPU-threads.
ThreadPinning.cores
— FunctionReturns the CPU IDs of the system as obtained by a round-robin scattering between CPU cores. This is the same as nodes(; compact=false)
. Set shuffle=true
to randomize.
Optional first argument: Logical indices to select a subset of the sockets.
ThreadPinning.numas
— FunctionReturns the CPU IDs of the system as obtained by a round-robin scattering between NUMA domains. Within each NUMA domain, a round-robin ordering among CPU cores is used ("cores before hyperthreads"). Provide compact=true
to get compact ordering within each NUMA domain. Set shuffle=true
to randomize.
Optional first argument: Logical indices to select a subset of the sockets.
ThreadPinning.sockets
— FunctionReturns the CPU IDs of the system as obtained by a round-robin scattering between sockets. By default, within each socket, a round-robin ordering among CPU cores is used ("cores before hyperthreads"). Provide compact=true
to get compact ordering within each socket. Set shuffle=true
to randomize.
Optional first argument: Logical indices to select a subset of the sockets.
ThreadPinning.cpuids
— FunctionAll valid CPU IDs of the system (sorted).
ThreadPinning.id
— FunctionReturns the logical index (starts at 1) that corresponds to the given CPU ID ("physical" OS index).
ThreadPinning.cpuid
— FunctionReturns the CPU ID ("physical" OS index) that corresponds to the given logical index (starts at 1).
Querying - System
ThreadPinning.ncputhreads
— FunctionNumber of CPU-threads
ThreadPinning.ncores
— FunctionNumber of cores (i.e. excluding hyperthreads)
ThreadPinning.nnuma
— FunctionNumber of NUMA nodes
ThreadPinning.nsockets
— FunctionNumber of CPU-sockets / CPUs
ThreadPinning.ncorekinds
— FunctionNumber of different kinds of cores (e.g. efficiency and performance cores).
ThreadPinning.nsmt
— FunctionThe number of SMT-threads in a core. If this number varies between different cores, the maximum is returned.
ThreadPinning.isefficiencycore
— FunctionReturns true if the given CPU-thread lies inside of a CPU-core that has the highest power efficiency of all the CPU-cores (i.e. an efficiency value of 1). If there is only a single CPU-core kind, the return value is false for all CPU IDs.
ThreadPinning.ishyperthread
— FunctionCheck whether the given CPU-thread is a SMT-thread / "hyperthread" (i.e. it is not the first CPU-thread in the CPU-core).
ThreadPinning.hyperthreading_is_enabled
— FunctionCheck whether simultaneous multithreading (SMT) / "hyperthreading" is enabled.
Querying - OpenBLAS
ThreadPinning.openblas_getaffinity
— Functionopenblas_getaffinity(; threadid, convert = true)
Query the affinity of the OpenBLAS thread with the given threadid
(typically 1:BLAS.get_num_threads()
). By default, returns a vector respresenting the mask. If convert=false
a Ccpu_set_t
is returned instead.
ThreadPinning.openblas_getcpuids
— Functionopenblas_getcpuids()
Get the ids of the CPU threads on which the OpenBLAS threads are running on according to their affinity. See openblas_getcpuid
for more information."
ThreadPinning.openblas_getcpuid
— Functionopenblas_getcpuid(; threadid)
Get the id of the CPU thread on which the OpenBLAS thread with the given threadid
is running on according to its affinity.
Note: If the OpenBLAS thread has not been pinned before, this function will error because the affinity mask highlights more than a single CPU thread by default.
ThreadPinning.openblas_ispinned
— Functionopenblas_ispinned(; threadid)
Check if the OpenBLAS thread is pinned to a single CPU thread.
ThreadPinning.openblas_printaffinities
— FunctionPrint the affinities of all OpenBLAS threads.
ThreadPinning.openblas_printaffinity
— Functionopenblas_printaffinity(; threadid)
Print the affinity of an OpenBLAS thread.
Querying - MPI
ThreadPinning.mpi_getcpuids
— FunctionOn rank 0, this function returns a Dict{Int, Vector{Int}}
where the keys are the MPI rank ids and the values are the CPU IDs of the CPU-threads that are currently running the Julia threads of the MPI rank. Returns nothing
on all other ranks.
ThreadPinning.mpi_gethostnames
— FunctionOn rank 0, this function returns a Dict{Int, String}
where the keys are the MPI rank ids and the values are the hostnames of the nodes that are currently hosting the respective MPI ranks. Returns nothing
on all other ranks.
ThreadPinning.mpi_getlocalrank
— FunctionReturns a node-local rank id (starts at zero). Nodes are identified based on their hostnames (gethostname
). On each node, ranks are ordered based on their global rank id.
Querying - Distributed.jl
ThreadPinning.distributed_getcpuids
— FunctionReturns a Dict{Int, Vector{Int}}
where the keys are the pids of the Julia workers and the values are the CPU IDs of the CPU-threads that are currently running the Julia threads of the worker.
If include_master=true
, the master process (Distributed.myid() == 1
) will be included.
ThreadPinning.distributed_gethostnames
— FunctionReturns a Dict{Int, String}
where the keys are the pids of the Julia workers and the values are the hostnames of the nodes that are currently hosting the respective workers.
If include_master=true
, the master process (Distributed.myid() == 1
) will be included.
ThreadPinning.distributed_getispinned
— FunctionReturns a Dict{Int, Vector{Bool}}
where the keys are the pids of the Julia workers and the values are the results of ThreadPinning.ispinned
evaluated for all Julia threads of a worker.
If include_master=true
, the master process (Distributed.myid() == 1
) will be included.