Is there a way to determine how many cores a machine has from C/C++ in a platform-independent way? If no such thing exists, what about determining it per-platform (Windows/*nix/Mac)?
C++ – How to Programmatically Find the Number of Cores on a Machine
c++multiplatformmultithreading
Best Answer
C++11
Reference: std::thread::hardware_concurrency
In C++ prior to C++11, there's no portable way. Instead, you'll need to use one or more of the following methods (guarded by appropriate
#ifdef
lines):Win32
Linux, Solaris, AIX and Mac OS X >=10.4 (i.e. Tiger onwards)
FreeBSD, MacOS X, NetBSD, OpenBSD, etc.
HPUX
IRIX
Objective-C (Mac OS X >=10.5 or iOS)