Hacker News new | ask | show | jobs
by adrian_b 2 hours ago
Whether an application gains or loses from SMT depends on what is does.

As a general rule, when there are multiple threads inside a single process, which do the same kind of thing, for example when they process some array and each thread works on some part of that array, enabling SMT frequently degrades the performance, because the threads compete for the same execution units and for the limited space in the cache memory.

On the other hand, when each hardware thread executes a distinct process, which does things uncorrelated with the others, enabling SMT frequently improves the performance.

Typical cases when SMT is beneficial are servers accessed simultaneously by many clients, and compiling a big software project, with hundreds or thousands of files.

For me, compiling big software projects is the main thing that is seriously accelerated by SMT, while some CAD/EDA simulations may be slowed down by SMT.

An interesting fact is that there is a traditional advice than says that when compiling on a multi-core or multi-threaded CPU with N threads, it is optimum to set the number of parallel compilation jobs to N+1.

I have verified that this old advice is correct for multi-core CPUs without SMT or with SMT disabled. On the other hand, if you enable SMT on a CPU with N cores, the optimum number of parallel compilation jobs becomes 2*N, not 2*N+1. For instance, on a 16-core CPU, the optimum number of parallel compilation jobs is 17 with SMT disabled and 32 with SMT enabled.

This result is not very surprising, because every additional parallel job introduces overhead, but without SMT an extra thread is useful, because whenever a running thread is stalled, typically waiting for a file to be read, the extra thread can start running instantly. On the other hand, with SMT enabled, there is no need for an extra thread, because whenever one thread is stalled, its sibling thread is accelerated instantly by using the whole core, instead of sharing it.