Is there a way to get the nr of processing units like cpus or cores in a system? I am going to write an app with pthreads so if there is a posix call that would be great. I know about reading from /proc/cpuinfo but that is not so portable. Is there another more portable way?
A:
Not to my knowledge. Under windows, for example, you'd get that from GetSystemInfo. You can probably get this info on x86 CPUs using a CPUID assembler call, but thats no use on non-x86 platforms.
Goz
2009-07-16 08:27:41
+5
A:
The POSIX (threads) committee considered supporting such an operation, but then refused to. People have collected information on how to do that on various systems.
Martin v. Löwis
2009-07-16 08:28:33
The last two paragraphs of that newsgroup posting by Butenhof are particularly apt I would say; although I would add that the only person who can really answer the question "would my app benefit from creating another thread" is the system administrator, which implies that "number of threads" should be a user-tweakable.
caf
2009-07-16 11:56:43
A:
I found a similar (duplicate) question but for C++ http://stackoverflow.com/questions/150355/programmatically-find-the-number-of-cores-on-a-machine
Per Arneng
2009-07-16 08:38:18