1

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.

How can I do that using C++?

thanks!

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
Mat
  • 11,263
  • 10
  • 45
  • 48

3 Answers3

8

You can get the number of physical processors by calling GetSystemInfo and checking the dwNumberOfProcessors field of the SYSTEM_INFO structure. You can get the number of logical processors by calling GetLogicalProcessorInformation.

Nick Meyer
  • 39,212
  • 14
  • 67
  • 75
2

Try the GetSystemInfo function. It returns a SYSTEM_INFO struct which has a dwNumberOfProcessors member.

luke
  • 36,103
  • 8
  • 58
  • 81
2

The Win32 API function GetSystemInfo will return a SYSTEM_INFO structure with the information you need. Specifically, check the dwNumberOfProcessors member variable.

Russell Newquist
  • 2,656
  • 2
  • 16
  • 18