[英]get number of CPUs in C++ MFC application
I write a little raytracer and i'd like to query how many cpu cores (or virtual cpu cores if the cpu uses hyperthreading) the current computer offers, such that i can instanciate as many threads to get better parallel rendering. 我写了一点raytracer,我想查询当前计算机提供了多少个cpu核心(如果cpu使用超线程,则为虚拟cpu核心),这样我就可以实例化多个线程以获得更好的并行渲染。
How can I do that using C++? 如何使用C ++做到这一点?
thanks! 谢谢!
You can get the number of physical processors by calling GetSystemInfo
and checking the dwNumberOfProcessors
field of the SYSTEM_INFO
structure. 您可以通过调用
GetSystemInfo
并检查SYSTEM_INFO
结构的dwNumberOfProcessors
字段来获取物理处理器的数量。 You can get the number of logical processors by calling GetLogicalProcessorInformation
. 您可以通过调用
GetLogicalProcessorInformation
获得逻辑处理器的GetLogicalProcessorInformation
。
Try the GetSystemInfo
function. 尝试使用
GetSystemInfo
函数。 It returns a SYSTEM_INFO
struct which has a dwNumberOfProcessors
member. 它返回一个具有
dwNumberOfProcessors
成员的SYSTEM_INFO
结构。
The Win32 API function GetSystemInfo will return a SYSTEM_INFO structure with the information you need. Win32 API函数GetSystemInfo将返回包含您所需信息的SYSTEM_INFO结构。 Specifically, check the dwNumberOfProcessors member variable.
具体来说,请检查dwNumberOfProcessors成员变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.