0

I have an Early 2011 Quad Core i7 Mac. Due to hyperthreading, a lot of programs report 8 "cores". If I were to write a program that executes in parallel, could I kick off 8 instances of this program or just 4?

I get I can start as many threads as I want, but would I be seeing 4 or 8 instances of the program execute in parallel?

David
  • 9,144
  • 3
  • 24
  • 41
Tyler DeWitt
  • 243
  • 3
  • 9
  • 2
    Hyperthreading allows each core to process 2 threads at a time after each clock trigger. If you did not have Hyperthreading each core would be only be able to process a single thread at a time. Please note this is the most basic explaination of Hyperthread, something that is well documented, which you would be wise to read about. I should note that you can run 8 instances of a program even with a single core processor, it might be slow, depending on what instructions are hapening exactly but you already are running hundreds of **processes** in a case like OS X anyways. – Ramhound Dec 04 '13 at 19:18
  • The programs you make run in an independent process, regardless of how many cores or threads the processor is able to give you. How you use what resources you are given is also your design option. To simplify: if you run 1 instance, you only see 1 program execute. – Doktoro Reichard Dec 04 '13 at 19:18
  • @Ramhound - I think David's edit might make the question a little clearer, sorry. I was asking at what point would I saturate my cores if my process was the only one running (not real world, I understand, just trying to grasp the abstract ideas). – Tyler DeWitt Dec 04 '13 at 20:30
  • @DoktoroReichard - Sorry for the confusion in the question text, I think David's edit makes it clearer. Joshua's answer gave me what I was looking for. Thanks for the input though. – Tyler DeWitt Dec 04 '13 at 20:31

1 Answers1

2

The Intel Core i7 processor has 4 physical cores, but each core has the ability to input up to 2 Threads at a time, showing 8 Threads total to the operating system in the form of "available logical CPU's."

In reality, a single core can only handle one thread at a time, but it has special queueing / timing / scheduling mechanisms to allow 2 threads to be at different stages of the "pipeline" at the same time. This enables the CPU to finish 2 threads sooner than it would if it were to only handle one at a time. Because both threads are sharing the same pipeline, the performance benefit will obviously not be 2x. Most tests peg the benefit anywhere between 10% and 50% depending on the type of instructions being executed.

In answer to your question, if you start 4, 8 or 16 instances of your program, they would all be "running," but instructions for each would be queued up depending on how many available THREADS are available. Once you move beyond the number of available PHYSICAL CORES (e.g. 5 or more), the performance will reduce because any threads beyond the base 4 will be sharing a physical CPU core.

Finally, once you hit the limit of the available CPU threading capability (exceed 8 threads), the OS will then start scheduling / queueing instructions to wait until the ones in the pipeline are done. Ideally you want to avoid going over the available threads because it could have negative performance impacts and bottleneck the system.

Joshua
  • 4,362
  • 3
  • 24
  • 31
  • Hyperthreading in the Core i7 is *simultaneous multithreading* **not** fine-grained/interleaved multithreading: instructions from both threads can begin execution at the same time (the front-end up to register renaming [IIRC] is interleaved, but later stages are mixed). Also it should be stated more clearly that performance *per thread* "will reduce"; as noted total performance may increase by about 20%. Code constrained by cache capacity or memory bandwidth may suffer performance degradation; code constrained by latency issues is more likely to benefit from SMT. –  Dec 04 '13 at 21:43