Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Anybody knows how to get number of CPU cores?
Anybody knows how to get number of CPU cores? [message #10832] Wed, 01 August 2007 10:54 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
In Win32, Win64 and Linux/POSIX...

I have seen examples how to find a part of the information on one of system, but I would need implemenation for all (or most) platforms we support....
Re: Anybody knows how to get number of CPU cores? [message #10834 is a reply to message #10832] Wed, 01 August 2007 11:54 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

luzr wrote on Wed, 01 August 2007 04:54

In Win32, Win64 and Linux/POSIX...

I have seen examples how to find a part of the information on one of system, but I would need implemenation for all (or most) platforms we support....

Have you seen this: ?
http://www3.intel.com/cd/ids/developer/asmo-na/eng/275339.ht m?cid=sw:multicore005

There is a CPUCOUNT.CPP which seemms to be able to detect how many cores a cpu has (see int MaxCorePerPhysicalProc(void))
Re: Anybody knows how to get number of CPU cores? [message #10842 is a reply to message #10834] Wed, 01 August 2007 15:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thanks, it provided really useful hints:

For Win32, it seems like we can use GetProcessAffinityMask(GetCurrentProcess(), &pa, &sa);
and count the number of non-zero bits in sa.

For Linux, it is simply sysconf(_SC_NPROCESSORS_CONF); (or perhaps _SC_NPROCESSORS_ONLN).

BSD, MacOSX, anybody? Smile

Mirek
Re: Anybody knows how to get number of CPU cores? [message #10843 is a reply to message #10842] Wed, 01 August 2007 15:43 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Actually, it seems that there is

int get_nprocs (void)

in GNUC libc - nice Wink

Mirek
Previous Topic: What improvements for Upp on Linux to comply with freedesktop?
Next Topic: The age of multicore has just started for U++....
Goto Forum:
  


Current Time: Sun Apr 28 19:42:34 CEST 2024

Total time taken to generate the page: 0.03300 seconds