How to get number of cores in Win32?

前端 未结 5 892
渐次进展
渐次进展 2020-12-11 17:50

I\'m writing a program in C on windows that needs to run as many threads as available cores. But I dont know how to get the number of cores. Any ideas?

5条回答
  •  独厮守ぢ
    2020-12-11 18:56

    Type "cmd" on windows startup and open "cmd.exe". Now type in the following command:

    WMIC CPU Get /Format:List
    

    You will find the entries like - "NumberOfCores" and "NumberOfLogicalProcessors". Typically the logical-processors are achieved by threading. Therefore the relation would typically go like;

    NumberOfLogicalProcessors = NumberOfCores * Number-of-Threads-per-Core.

    Since each core serves a processing-unit, therefore with threading, logical-processing-unit is realized in real space.

    More info here.

提交回复
热议问题