Jump to content
  • Advertisement
Sign in to follow this  
ddn3

Checking for multi-core

This topic is 3683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to check for the presence of a multi-core cpu? I've searched google and there doesn't seem to be a consistent or easy way of doing this. Does anyone know of any code snippet which can do this? Thanks! -ddn

Share this post


Link to post
Share on other sites
Advertisement
If you are in windows:

SYSTEM_INFO cSysInfo;
GetSystemInfo(&cSysInfo);

cSysInfo.dwNumberOfProcessors == The number of physical cores.

see: http://msdn.microsoft.com/en-us/library/ms724381(VS.85).aspx

Share this post


Link to post
Share on other sites
On *nix you can, like was mentioned, use a library such as GLFW... or you can go right ahead and steal their code (as long as you give them credit and follow any possibly stricter licensing issues).

GLFW's platform.h (X11):
Quote:

// We support two different ways for getting the number of processors in
// the system: sysconf (POSIX) and sysctl (BSD?)
#if defined( _GLFW_HAS_SYSCONF )

// Use a single constant for querying number of online processors using
// the sysconf function (e.g. SGI defines _SC_NPROC_ONLN instead of
// _SC_NPROCESSORS_ONLN)
#ifndef _SC_NPROCESSORS_ONLN
#ifdef _SC_NPROC_ONLN
#define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
#else
#error POSIX constant _SC_NPROCESSORS_ONLN not defined!
#endif
#endif

// Macro for querying the number of processors
#define _glfw_numprocessors(n) n=(int)sysconf(_SC_NPROCESSORS_ONLN)

#elif defined( _GLFW_HAS_SYSCTL )

#include <sys/types.h>
#include <sys/sysctl.h>

// Macro for querying the number of processors
#define _glfw_numprocessors(n) { int mib[2], ncpu; size_t len = 1; mib[0] = CTL_HW; mib[1] = HW_NCPU; n = 1; if( sysctl( mib, 2, &ncpu, &len, NULL, 0 ) != -1 ) { if( len > 0 ) { n = ncpu; } } }

#else

// If neither sysconf nor sysctl is supported, assume single processor
// system
#define _glfw_numprocessors(n) n=1

#endif

Share this post


Link to post
Share on other sites
I'll be a smart-ass. I wrote my own 64-bit, multicore operating system, LoseThos, and everything has kernel privilege. Read the Intel datasheets ;-)

You can see how I did it: http://www.losethos.com/multicore.html

I assume you mean for some specific operating system. Can't help you. If you manage to get kernel privilege you can use my code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!