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

Raymond

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.

9 comments

Comments are closed. Login to edit/delete your existing comments

    • 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.

  • Chris Crowther

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

  • Fleet Command

    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.

  • Fleet Command

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

    I miss the engineers behind it.

  • Ray

    Happy 25th Windows 95 shipping day! And thanks for the many insights on Windows throughout the lifetime of this blog, still love to follow it since years. My Old New Thing book copy definitely needs a signature somewhen…

  • 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).

  • 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.