Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

More threads than cores

David_DiLaura1
New Contributor I
1,800 Views

Steve, Colleagues,

What does a Release-2015-compiler-produced executable do if it wants 4 cores [ CALL OMP_SET_NUM_THREADS(4) ] and it is run on a machine with an old Intel chip there are only two cores? We're trying to predict behavior on user machines that date back a while.

David

0 Kudos
5 Replies
Steven_L_Intel1
Employee
1,800 Views

If you explicitly set the number of threads, that's what you get. Note that threads are an OS abstraction and have no direct relationship to cores. If you don't specify the number of threads, OpenMP will by default give you as many threads as there are execution streams on the processor (sockets * cores * threads/core). People were doing multithread programming on single-core processors for decades.

0 Kudos
David_DiLaura1
New Contributor I
1,800 Views

Thanks Steve. Yes, I understand the abstraction aspect, but what is the behavior? Is an attempt made to execute all 4 (in this case) threads more-or-less simultaneously?  That is, being switched in-and-out of available execution streams. (Which sounds very inefficient). Or are individual threads allowed to run to completion in one of the execution streams?  

David

0 Kudos
Steven_L_Intel1
Employee
1,800 Views

The OS manages this - and in general it will cycle among the threads, giving each one some time before swapping in another. Note that it's already doing this to some degree if there are ANY other processes or threads on the system, which there always will be. As for inefficient, it depends on the application, but certainly no individual thread will get 100% of a core's resources.

Also keep in mind that with Hyperthreading, such as almost all modern Intel CPUs have, typically two threads run per core, sharing some hardware resources.

What you describe is called "oversubscribing", and it is usually, but not always, a bad thing. Some applications do ok with some oversubscription.

0 Kudos
David_DiLaura1
New Contributor I
1,800 Views

Thanks Steve. It's clear now. It sounds best if we avoid (possible) oversubscribing -- we'll add code that limits the number of threads we'll use to the number of physical cores we find on the host system.

David

0 Kudos
Steven_L_Intel1
Employee
1,800 Views

Or you could simply not specify the number of threads and let the runtime figure it out on its own. OMP_GET_NUM_PROCS will get you the number, or if you want more details, see the ProcessorInfo sample in Win32.zip.

0 Kudos
Reply