CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Hybrid View

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Number of hardware processors (cores)

    Hi guys. This is way out of my league but I thought someone here might have some ideas...

    Apparently there are various methods (GetSystemInfo() / GetLogicalProcessorInfoEx() etc) which can return the number of available processors. But they usually return the number of logical processors and they're affected by stuff like hyperthreading. So for example, depending on how you get the information, a dual-core CPU can either return 1, 2 or 4 processors.

    I've been asked if there's any simple way to retrieve the actual number of physical processor cores - i.e. such that a dual core CPU will always get returned as '2'. An 8-core CPU would return '8' etc. Any ideas anyone?
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Number of hardware processors (cores)

    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    There is sample code there that seems to extract that info.

    gg

  3. #3
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: Number of hardware processors (cores)

    IIRC, if you want a solution that works on as many versions of windows as possible, you have to resort to assembly hacks. I may have some example code if you are interested.
    Nobody cares how it works as long as it works

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Number of hardware processors (cores)

    You can also use WMI.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Number of hardware processors (cores)

    what's the difference betwee 1 dual core processor and 2 single core processors ?
    other than the physical packaging, they'll behave identically as far as an OS is concerned.

    wanting to know if a core is a hyperthreading or a real core, ok I can see reasons why you'd want to know why it is either, because the hyperthreaded cores are slightly less capable as their real counterpart.

  6. #6
    Join Date
    Aug 2013
    Posts
    55

    Re: Number of hardware processors (cores)

    Quote Originally Posted by John E View Post
    Any ideas anyone?
    You can get that information from a package that's designed to utilize multiple cores.

    This will allow you not only to know how many cores you have at your disposal but also to utilize the cores optimally in your programs.

    My favourite is TBB from Intel.

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Number of hardware processors (cores)

    Tbh. Why do you even need this ?
    Most cases I've seen where devs tried to "game" the system trying to get more oomph out of the system, they ended up doing the opposite, or they ended up getting more speed, but at the cost of making the entire rest of the PC unusable for anything meanwhile.

    Doing massively multithreading properly is hard... very hard... more ofen than not you see software that spends a large amount of it's time in the waiting loops trying to sync up.

  8. #8
    Join Date
    Aug 2013
    Posts
    55

    Re: Number of hardware processors (cores)

    Quote Originally Posted by OReubens View Post
    Tbh. Why do you even need this ?
    Do you mean TBB and replied to me?

  9. #9
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Number of hardware processors (cores)

    I've been asked if there's any simple way to retrieve the actual number of physical processor cores - i.e. such that a dual core CPU will always get returned as '2'. An 8-core CPU would return '8' etc
    but for what is this data going to be used? Just for info purposes or??
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  10. #10
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Number of hardware processors (cores)

    Thanks guys. Shortly after posting I came down with some horrible virus (i.e. dizziness / cold / headache etc - not a computer virus!) but there's plenty of stuff here for me to investigate once I'm feeling a bit better. Thanks!
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured