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
  • 101,029
  • 52
  • 303
  • 540
Mat
  • 10,493
  • 10
  • 42
  • 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
  • 37,495
  • 14
  • 63
  • 72
2

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

luke
  • 34,649
  • 7
  • 57
  • 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,626
  • 2
  • 14
  • 18