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

number of physical CPUs + HT CPUs

tihomir
Beginner
555 Views

Hi

How can I get in Intel-Fortran the optimal/maximum number of threads to use in a program on a given PC. This would be the "number cores + the number of HT cores", right? Is there a system function in Intel-Fortran that will give me this number?

Thank you

Tihomir

0 Kudos
9 Replies
Steven_L_Intel1
Employee
555 Views
The Win32 API routine GetSystemInfo will return the number of logical processors that Windows sees in the dwNumberOfProcessors field of the SYSTEM_INFO structure. This will include both physical processors/cores and the logical processors that HT creates.

There is, I am sure, also a way to find out how many physical processors and/or cores are on the system, but I don't know offhand what that is.
0 Kudos
Steven_L_Intel1
Employee
555 Views
0 Kudos
Steven_L_Intel1
Employee
555 Views
I have attached a sample program that shows use of GetSystemInfo.
0 Kudos
grg99
Beginner
555 Views
Note that the number returned by the system API may not be very helpful. For many reasons:

(1) There may be processes running that have already reserved one or more CPU's.

(2) There may be system drivers that have priority over your requests.

(3) There may be system limits set for your account that limit the number of CPU's you may be allowed to request.

(4) There may be CPU's that can't reach the memory allocated for your program.

(5) There may be "hyper" CPU's, which IMHO are mostly hype. Even in Intel's own specially crafted benchmarks, it's hard for them to show more than a few tenths of a CPU is generated by the hyper feature. And IIRC they've dropped the hyper feature on their latest CPUs.

(6) One or more CPU's may be sidelined due to some unrecoverable error, such as a double bus fault.

(7) One or more CPU's may be virtual CPU's, if your app ends up running under something like "virtual PC", or the microsoft equivalent.

In my programs I usually detect the number of CPU's by starting 1, 2, ... threads and stop adding threads when the thruput stops increasing.


0 Kudos
Steven_L_Intel1
Employee
555 Views
The GetSystemInfo API will tell you about the processors available to the OS, which is good enough for the purpose requested. Hyper-Threading can show a benefit of up to 25% in some real applications, but I'm not going to argue that it's a replacement for a physical CPU or core.

The article I pointed to goes into a lot more detail regarding processor affinity, etc. And yes, if you're talking about non-uniform memory access (NUMA), then knowing which memory is local and which is not can be important, but in the Intel world that's for users of certain Itanium-based systems only.
0 Kudos
tihomir
Beginner
555 Views
This is very helpful. Thanks a lot.One morequick question. Is there an advantage of two single core procs over one dual core?
0 Kudos
Steven_L_Intel1
Employee
555 Views
It depends. Some dual-core CPUs (such as the Intel Core 2 Duo processors) have a shared cache which can speed sharing data between threads but the total cache available tends to be less than in dual-CPU systems. So a lot depends on the application and how much communication between threads is needed. Dual-CPU systems tend to need more components on the motherboard and are more expensive. Of course, the multiple-socket strategy nowadays is to have dual-core CPUs in each socket.
0 Kudos
emilio_perea
Beginner
555 Views
That link does not work for me (brings up a blank screen and gets me right back here). Is it still valid?
0 Kudos
Steven_L_Intel1
Employee
555 Views
Not any more, it would seem. I've replaced the link with a new one (this is for the article, not my Fortran sample program).
0 Kudos
Reply