0

So I typed in lscpu into my terminal and saw this:

CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  2
Core(s) per socket:  2
Socket(s):           1

The no. of CPU(s) is 4 here because of the formula: No. of CPUs = Sockets X Cores per socket X Threads per Core

But the question is, what exactly is a CPU? Why are we including threads in the above formula?

stagee
  • 1

1 Answers1

0

It depends on what you are looking.

When you buy a processor, it say clearly about hyperthread and number of cores, and if you can use it on multi-processor way (multiple sockets).

Lets' forget the cases where we have multiple physical CPU.

We have on one chip several cores: they may share some cache, else they are almost independent. But still: some tasks should be coordinated, so with 4 cores, you do not have (usually) 4 times the "power" of 1 single core.

Hyperthreads: this is more tricky: it was a trick of Intel (also before multi-cores), there you can simulate multiple CPU. In reality you can execute only one thread at a time, but CPU often need to do pauses (e.g. waiting for memory access or writing). With hyperthreading, the CPU could switch quickly to the second virtual CPU.

So with hyperthreading, you have often better performance compared at just one normal CPU, at nearly no costs (some more logic, cache and registers, but no duplicate transistors), but two cores are still better (still not equal two two CPU, but on numerical calculation, where the two tasks are fully independent, and kernel will not bother the tasks).

If you have parallel processes, I would often use the threads multiplied by cores (and often I add one to threads or final results, if there is a discrete number of IO). In this case you get better performance (assuming no other CPU intensive tasks): you use maximum power, also when a single core is waiting for memory data.

But to get the speed-up, I would just use number of cores (remembering that I will be some better data).

So, it depends on what you are looking. And if you are doing complex tasks, probably you are measuring much more your processes, and optimizing them (cache, memory, threads, cores, CPU, MPI, ...). Every program is different on resources.

  • With hyperthreading, even on the Pentium 4, some parts of the execution are fully parallel (when both threads use different execution units), so in reality you can execute two threads at a time at least some of the time. – Stephen Kitt Aug 11 '20 at 14:49
  • @StephenKitt: right, but so also a single threated CPU: the old pipelines (and over-optimization, on Pentium, pentiumPro), which I was forgetting. – Giacomo Catenazzi Aug 11 '20 at 14:51
  • Indeed, the difference with hyperthreading is that the OS scheduler can have its say, and the execution units can be fed with instructions from different processes or threads. U/V pipes and pipelines only act on consecutive instructions in single threads. – Stephen Kitt Aug 11 '20 at 14:53