0

I wonder whether the multiprocesses or threads must occupy independent physical cores respectively and that is called the true parallel? Furthermore, when conducting parallel computing with multiprocesses or multithreads, which of the physical core or logical core of cpu should be pay attention?

I have looked forward many informations, and still be confused.

lwt
  • 1
  • 2

1 Answers1

0

If multiple cores are available, the operating system will use them as it sees fit to distribute work whether it's running multithreaded or multiprocess applications. I'll adopt the meaning of the words concurrency and parallelism described here What is the difference between concurrency and parallelism?. It's something to watch out for because often people even inside the computing universe use them differently.

With a single core, single 'thread' CPU, you won't get 'parallelism', meaning multiple streams of instructions being executed at the same time. The operating system will instead rapidly switch between them creating something which often appears to be parallelism but actually isn't. This can also occur with multiple cores, but the operating system will try to keep the available cores busy and therefore get the work done quickly. If there are more threads/processes than available CPU 'threads', then it will have no choice but to share them.

It's a bit confusing because the term 'thread' is used to mean different things in different contexts. In CPUs that support hyper-threading, a single core can run multiple, usually 2, streams of instructions in parallel and share the computational and other resources of that CPU core between them. For most purposes though, these CPU 'threads' present themselves as cores in their own right.

To complicate things, some languages, though none relevant to HPC, support multi-threading but without parallelism. There's also instruction level parallelism, and SIMD which you should look up if you're not sure what they are.

Simon Goater
  • 759
  • 1
  • 1
  • 7
  • Thanks for your answer, and I can understand you almost. Can I ask for further question, if I want to run a parallel program, and the available cores are less than the called threads, which means some one core must operate more than one thread? And if I want to conduct true parallel computing, the running cores must be equal to the called threads? and the cores are physical cores, not logical cores? – lwt Jul 06 '23 at 11:53
  • As far as the application programmer is concerned, there's no 'must' about not using more threads than available CPU thread/cores as the OS handles it. Yes, it will have to get some cores to run more than one thread if there not enough cores. For IO or network bound applications, you might well get better performance running more threads than CPU threads/cores. As a general rule, for computationally bound applications, you're probably going to get the best performance by avoiding sharing CPU threads/cores. – Simon Goater Jul 06 '23 at 12:00
  • "As a general rule, for computationally bound applications, you're probably going to get the best performance by avoiding sharing CPU threads/cores." means allocating equal cores or at leat not less than the called threads will result in best performance? Additionally, the "cores" mean physical core? – lwt Jul 06 '23 at 12:05
  • There's no guarantee, but I've found for computationally bound applications, I get the best overall performance running as many application threads as there are CPU threads. So that's 8 application threads on a CPU with 4 'cores' and 8 threads. – Simon Goater Jul 06 '23 at 12:33
  • I don't understand the "So that's 8 application threads on a CPU with 4 'cores' and 8 threads. " means, CPU with 4 cores and 8 threads mean what? 4 physical cores and 8 logical cores result from the Hyper Threading of Intel? – lwt Jul 06 '23 at 12:43
  • Yes, it's 4 pairs of logical 'cores'. Each pair share resources so don't really qualify as 'physical cores'. – Simon Goater Jul 06 '23 at 12:47
  • My understanding is that allocate equal physical cores not logical cores to the called threads in the situation of computing bound, and the performance generally reaches best? – lwt Jul 06 '23 at 12:56
  • No, other way around. Use all logical cores. You'll probably find you get diminishing returns and not a huge difference in computational performance between using as many threads as you have physical cores or logical cores. – Simon Goater Jul 06 '23 at 12:59
  • Sorry, I begin to get confused, the real parallel computing is take multi physical cores to run responding threads? Why the logical cores are also done? – lwt Jul 06 '23 at 13:05
  • Your CPU presents itself to your application as having a certain number of cores. These are logical cores. On CPUs that use hyper-threading, they are not all physically seperate 'cores' as they share resources. As far as you application is concerned though, you don't even know how many physical cores you have. – Simon Goater Jul 06 '23 at 13:13
  • @lwt, simply put - a physical core with 2 logical cores (HW threads) will usually be able to run 2 SW threads slightly faster than it would take to run them one after the other. It would still be slower than running them on 2 different physical cores, so it's only used once you've saturated all your physical cores and still want to add more threads for a bit of extra performance. – Leeor Jul 17 '23 at 17:01
  • @Leeor Thank you for your answer that help me understand above problem further. – lwt Jul 18 '23 at 23:01