how to get the number of CPUs? (include hyper-threading)

Jaubing Lin linjaubing@mail.com
Tue Jul 23 18:18:00 GMT 2002


> I'm writing a multithread program to exploit power of CPUs on my Linux
> machines. I'm intending to run it on several machines with other
> number of CPUs on each of them. So I want to get the number of CPUs
> dynamically at run time.
> 
> I've googled and learned about sysconf and getconf, but still dont
> know will they help me and how to use them. Please help me!
> 
> Thank in advance.


Hi! there:

  I think it is a little bit too late to reply
this question. However, I remeber someone asking for a program can run on windows machine.
And I feel this is a very good question and
someone may use multi CPU or sigle CPU supports Hyper-Threading.

  It means when some people's program return the
NUMBER of CPUs  on your Linux box might not be correct.

  I found a article on Intel.com website, which
is talking about counting logical and physical
processor in 32 bits system.

  This program returns
1) The numbers of logical CPU per physical CPU
2) The numbers of physical CPU

  I will attach the source file which I just
download from Intel.com

  The C++ source code is writen in VC++ and enclose some assembly code, but I guess you
can rewrite it to fit on a Linux box.
 
Linus Lin
-- 
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

Save up to $160 by signing up for NetZero Platinum Internet service.
http://www.netzero.net/?refcd=N2P0602NEP8

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Cpucount.cpp
Type: application/octet-stream
Size: 9053 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20020723/d6a61268/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Cpucount.exe
Type: application/octet-stream
Size: 40960 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20020723/d6a61268/attachment.exe>


More information about the Gcc-help mailing list