August 24th, 2020

How can I get the number of processors in the system, when there are more than 64?

A customer noted that the way their program obtains the number of processors is by calling Get­System­Info and looking at the dwNumberOfProcessors. However, the documentation notes that this gives the number of processors in the current processor group, and that can be less than the total number of processors.

For example, when they checked the dwNumberOfProcessors on a system with 80 processors (lucky them), they found that it reported only 40 processors.

How can they get the total number of processors across all processor groups?

The easy way is to call Get­Active­Processor­Count with the ALL_PROCESSOR_GROUPS parameter. This counts up all processors across all groups.

The hard way is to call Get­Logical­Processor­Information­Ex and ask for Relation­Group. Then go through all the active groups and add up all of the Active­Processor­Counts. This is more work, but you also get to see the distribution of the processors among the groups, if that’s something you’re interested in.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

8 comments

Discussion is closed. Login to edit/delete existing comments.

  • Campbell Kerr

    Can understand why taskmgr these days only shows a single CPU graph, instead of 1 graph per CPU. I remember Windows servers with 16 or 32 cores trying to display each core in taskmgr, was fun to look at I guess!

    • Petr Kadlec

      You need to right-click the graph and choose Change graph to \ Logical processors.

  • Thiago Macieira

    > The hard way is to call Get­Logical­Processor­Information­Ex and ask for Relation­Group.

    Note it has to be Get­Logical­Processor­Information­Ex, not Get­Logical­Processor­Information­, which is slightly easier to parse. The latter has the same limitation and only reports the processors in the current processor group. On Raymond's example machine with 80 logical processors, Get­Logical­Processor­Information­ would report a single "RelationGroup" with 40 logical processors in them (usually 20 cores with 2 threads each).

    Read more
  • Flux

    By the way, happy Windows 95 anniversary, Mr. Chen. 😊

    I miss the engineers behind it.

  • Flux

    How lucky to run into this post. I was trying to find a way to get the number of available CPU cores in Node.js. Lately, I’ve been having some extra time, so I thought why not get a copy of e-Mage’s source code and alter it so that it processes its image list one per CPU core at a time.

  • Chris Crowther

    You can get 96 vCPUs using an Azure VM…although I suspect it would blow my monthly MSDN Azure budget instantly.

  • David Bry

    “64 processors ought to be enough for anybody.”

    • Jan RingoÅ¡

      In times, where only the most expensive machines had 4 cores, it seemed like a good idea to use bitmask for logical processor (HW thread) affinities and everything.