12.1 From Cores to Hardware Threads

CPU AND PERFORMANCESTATUS: DEVELOPINGLEVEL: INTROREVIEWED: 2026-11-18
Before this page Processes vs Threads

A CPU socket contains physical cores. Each physical core runs its own thread. Simultaneous multithreading (SMT) adds logical processors to each core. A CPU reports a thread count to the operating system. That count is not the number of independent cores, and for CPU-bound work the difference decides how many workers help.

12.1.1 Physical cores and sockets

A modern CPU die contains physical cores. Each core has its own instruction fetch unit, its own registers, and its own L1 cache. A socket is one CPU package. A machine can have one, two, or more sockets. The package may hold one die or several: AMD puts the cores of its EPYC and many Ryzen processors on several chiplets.

A physical core can run exactly one hardware thread without SMT. This is the natural baseline.

12.1.2 Simultaneous multithreading and hyperthreading

SMT lets one physical core run two or more instruction streams at once. Intel calls its version Hyper-Threading, with two threads per core. AMD’s Zen cores also run two. IBM’s POWER9 and Power10 cores run up to eight, and Intel’s Xeon Phi ran four.

SMT works because real code stalls. A thread reads from main memory and waits hundreds of cycles for the data to arrive. While it waits, another thread on the same core can execute. Each thread runs slower than it would alone, but the core gets more done overall.

SMT does NOT double throughput. The two hardware threads share one core’s execution units, its load and store ports, and its L1 and L2 caches. When both want the same unit in the same cycle, one waits.

Intel’s first Hyper-Threading paper reported “performance gains of up to 30%” on common server benchmarks (Marr et al., 2002). The gain depends on the workload: code that already keeps a core’s execution units busy leaves little for a second thread to use.

12.1.3 Logical processors and the operating system

The OS sees each logical processor as a separate entity it can schedule work onto. A machine with 4 physical cores and SMT=2 appears to the OS as 8 logical processors. The OS will schedule 8 independent threads. Four of them run on different cores. The other four share those cores with the first four, running at the same time.

The scheduler knows which logical processors share a core: Linux, for one, groups SMT siblings in its scheduling domains. With fewer runnable threads than cores, it tries to give each thread a core of its own. When you spawn 8 R workers on a 4-core machine with SMT=2, every logical processor gets one worker, and each worker shares its core with another.

12.1.4 Consequences for worker count

An R worker or Python process runs on one logical processor. If you spawn 8 workers on a 4-core machine with SMT=2, every worker shares a core with another. The workers do not take turns on a processor, since each has a logical processor of its own. The slowdown comes from the sharing.

For CPU-bound work (pure computation with few memory stalls), limit workers to physical core count. Each worker gets a core to itself, though workers on cores that share an L3 cache still share it, and all workers on a socket share its memory bandwidth.

For I-O-bound work (file I-O, network, database queries), more workers than physical cores can help because workers block on I-O. While one worker waits, others run.

Determine your hardware correctly:

parallel::detectCores()                 # logical processors
parallel::detectCores(logical = FALSE)  # physical cores on Windows and macOS; on Linux, still logical

A machine with 16 logical processors often has 8 physical cores. Spawning 16 workers for CPU-bound work on it gains at most what SMT adds over 8 workers, and holds twice as many R processes in memory.

12.1.5 Socket-local memory and NUMA

When a machine has two sockets, each socket has its own local memory. A thread on socket 0 can read from socket 1 memory, but the access is slower. The memory path goes through the inter-socket interconnect.

A thread that runs on socket 0 but reads memory allocated on socket 1 sees higher latency than for local memory, by a factor that depends on the machine. This is the NUMA (non-uniform memory access) penalty.

If your workers land on a single socket and memory is allocated locally, access is fast. If half your workers are on socket 0 and half on socket 1, they read from different local memory. Some workers pay a latency penalty.

Take a 2-socket machine with 32 cores, 16 per socket. If your data fits in one socket’s memory, pin the workers to that socket. Tools such as numactl do this from outside R. Inside R, parallel::mcaffinity() and the affinity.list argument of mclapply() pin forked workers to chosen CPUs where the system allows it, but nothing in base R controls which socket’s memory a worker allocates from.

12.1.6 Failure modes

A benchmark reports “16-core speedup” but means 16 logical processors on 8 physical cores. The claim is incomplete and misleading. Disclose physical core count explicitly.

Scaling from 8 physical cores to 16 logical processors often yields poor speedup. Adding 8 more workers that share core resources with the first 8 adds interference, not new cores. The speedup looks sublinear or flat.

A program sizes its worker pool with detectCores(). On a machine with SMT=2 the pool is twice the physical core count, so every CPU-bound worker shares a core and runs slower than it would alone.

A batch job that runs well on a 4-core laptop scales poorly to a 32-core, 2-socket server. The scheduler places workers on both sockets, and although Linux places each new page on the socket of the thread that first touches it, a worker that reads data its parent allocated, or that the scheduler moves to the other socket, reaches across the interconnect and pays the remote cost.

12.1.7 Worked example: SMT overhead

Assume a CPU-bound task on a 4-core machine with SMT=2. Assume also that two threads sharing a core together get 25 percent more work done than one thread alone. That figure is an assumption for the arithmetic, inside the range Intel reported, not a measurement.

Single-thread baseline: 40 seconds on one core.

Four workers (one per physical core): - 40 seconds ÷ 4 workers = 10 seconds of work per worker. - Each worker has a core to itself. - Measured time: 10 seconds plus synchronization overhead.

Eight workers (one per logical processor): - 40 seconds ÷ 8 workers = 5 seconds of work per worker. - Each core now runs two workers. Together they do 1.25 times the work of one, so each runs at 1.25 ÷ 2 = 0.625 of its solo speed. - Adjusted time: 5 seconds ÷ 0.625 = 8 seconds per worker. - Measured time: 8 seconds plus synchronization overhead.

Doubling the workers turned 10 seconds into 8, a 1.25x gain, not 2x. With no SMT gain at all, the eight workers would take 10 seconds, the same as four. If the two threads on a core slow each other down so much that together they do less than one thread alone, for example by evicting each other’s data from the shared caches, eight workers finish later than four.

12.1.8 Detection and reporting in practice

Tools to check your hardware:

On Linux, lscpu shows physical and logical processor counts. Windows Task Manager shows Cores and Logical processors. On macOS, sysctl hw.physicalcpu hw.logicalcpu prints both.

In R, parallel::detectCores() returns logical processors. parallel::detectCores(logical = FALSE) returns physical cores on Windows and macOS. Its help page says the argument is honored only there and on Solaris, so on Linux it returns the logical count. The RhpcBLASctl package reports both counts: get_num_cores() for physical cores and get_num_procs() for logical processors.

12.1.9 Reporting the hardware

Claimed efficiency depends on what you count. Suppose two groups measure the same 3.5x speedup on a machine with 4 physical cores and SMT=2.

Group A divides by the 8 logical processors that detectCores() reports and claims 44 percent parallel efficiency, which makes the code look poor.

Group B divides by the 4 physical cores and claims 88 percent. Same run, different story, and only Group B’s number says how well the code uses the hardware.

The difference matters for replication and comparison. A researcher trying to reproduce published results on a different machine misallocates workers when the original paper did not disclose physical core count.

12.1.10 Relevance to my work

threaded-r and r-in-rust must make decisions about worker placement. A user expects to scale to the reported core count. Suppose the user asks for 32 workers on a system with 16 physical cores and SMT of 2. The interpreter must decide whether to honor that request or cap it.

sunlight forks exactly as many workers as hatch(n) asks for, so the choice between physical and logical counts belongs to the caller: the OS will schedule 32 workers if you create 32 processes. Its thread governor separately clamps each worker’s BLAS, OpenMP and data.table threads to a share of the machine, so the threads inside the workers do not multiply past the core count.

Further reading

  • Marr, D. T., Binns, F., Hill, D. L., Hinton, G., Koufaty, D. A., Miller, J. A. and Upton, M. (2002). “Hyper-Threading Technology Architecture and Microarchitecture”. Intel Technology Journal 6(1). Issue PDF <https://www.intel.com/content/dam/www/public/us/en/documents/research/2002-vol06-iss-1-intel-technology-journal.pdf>.
  • Drepper, U. (2007). What Every Programmer Should Know About Memory <https://www.akkadia.org/drepper/cpumemory.pdf>. Section 5 covers NUMA.
  • Linux kernel documentation, What is NUMA? <https://docs.kernel.org/mm/numa.html>.
  • Linux kernel documentation, Scheduler Domains <https://docs.kernel.org/scheduler/sched-domains.html>, on how the scheduler groups SMT siblings.
  • Intel, VTune Profiler Memory Access Analysis <https://www.intel.com/content/www/us/en/docs/vtune-profiler/user-guide/2026-1/memory-access-analysis.html>, for finding NUMA problems and bandwidth-limited accesses.

Where to go next

Back to top