문제

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