This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


> 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

Attachment: Cpucount.cpp
Description: Binary data

Attachment: Cpucount.exe
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]