Possible Duplicate:
Programatically detect number of physical processors/cores or if hyper-threading is active on Windows, Mac and Linux

I wonder if there is any crossplatform (std or boost based or even c) way to get totall number of cores in a crossplatform manner? (for linux Mac Os X and Windows)

有帮助吗?

解决方案

Oooh, you'll probably have to get down to assembly...

http://code.google.com/p/geekinfo/source/browse/trunk/

Or go boost:

boost::thread::hardware_concurrency(); // returns number of cores/HT/procs

其他提示

You could use OpenMP's omp_get_max_threads () function. For g++, enable OpenMP with the -fopenmp directive. For MS Visual Studio enable it in project properties - configuration properties - C/C++ - language. Be aware that omp_get_max_threads () may return less than the actual number of hardware cores/threads if omp_set_num_threads () has been used to limit the number of threads an OpenMP parallel region is allowed to use (not an issue at program start). You should also be aware that for hyper threading CPUs omp_get_max_threads () doesn't return the number of hardware CPU cores, but of hardware threads the CPU supports (and the additional threads provided by hyper threading don't quite cut it).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top