可能重复:
Programmatically find the number of cores on a machine我有多少个核心?
我有一个多线程的C++在Windows,MacOS和Linux上运行的程序。有没有简单的方法来找出我目前运行的机器有多少个内核?当每个内核有1个线程时,我的系统运行得最好。
可能重复:
Programmatically find the number of cores on a machine我有多少个核心?
我有一个多线程的C++在Windows,MacOS和Linux上运行的程序。有没有简单的方法来找出我目前运行的机器有多少个内核?当每个内核有1个线程时,我的系统运行得最好。
我相信这个问题可能包含你的答案:
Programmatically find the number of cores on a machine
编辑:我刚刚投过票了ybungalobill的答案。我爱boost
!
如果您有C++ 0x编译器,则使用boost::thread::hardware_concurrency()
或std::thread::hardware_concurrency()
。
在linux系统上,cat/proc/cpuinfo和解析输出是一种方法。不知道它是否是最有效的。