Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to find Number of processor or Cores ?

How to find Number of processor or Cores ?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
13 Posts 4 Posters 14 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ERLN
    wrote on last edited by
    #1

    How To Find Number of processors Present in the CPU ? How to Find Number of Cores Present in the CPU ? Is any possiblity to find Number Cores and Number of Processors ? (Is any difference ) ?

    _ L 2 Replies Last reply
    0
    • E ERLN

      How To Find Number of processors Present in the CPU ? How to Find Number of Cores Present in the CPU ? Is any possiblity to find Number Cores and Number of Processors ? (Is any difference ) ?

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Try GetSystemInfo[^]

      «_Superman_» I love work. It gives me something to do between weekends.

      E 1 Reply Last reply
      0
      • _ _Superman_

        Try GetSystemInfo[^]

        «_Superman_» I love work. It gives me something to do between weekends.

        E Offline
        E Offline
        ERLN
        wrote on last edited by
        #3

        fine. GetSystemInfo is giving number of processor is 2 for Pentium D. But I have only one processor but 2 cores. Is there any way to find number processor and number of cores.?

        _ 1 Reply Last reply
        0
        • E ERLN

          fine. GetSystemInfo is giving number of processor is 2 for Pentium D. But I have only one processor but 2 cores. Is there any way to find number processor and number of cores.?

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          I guess you could use GetLogicalProcessorInformation[^] on Windows Vista and later versions.

          «_Superman_» I love work. It gives me something to do between weekends.

          E 1 Reply Last reply
          0
          • _ _Superman_

            I guess you could use GetLogicalProcessorInformation[^] on Windows Vista and later versions.

            «_Superman_» I love work. It gives me something to do between weekends.

            E Offline
            E Offline
            ERLN
            wrote on last edited by
            #5

            So There is no way for Windows XP . is it ?

            _ S 2 Replies Last reply
            0
            • E ERLN

              So There is no way for Windows XP . is it ?

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              Guess not. Even the System Control Panel in XP lists it as separate processors. But I guess it shouldn't matter to a program whether is two processors or two cores. The documentation says that it is available on Windows XP Professional x64 Edition.

              «_Superman_» I love work. It gives me something to do between weekends.

              E 1 Reply Last reply
              0
              • _ _Superman_

                Guess not. Even the System Control Panel in XP lists it as separate processors. But I guess it shouldn't matter to a program whether is two processors or two cores. The documentation says that it is available on Windows XP Professional x64 Edition.

                «_Superman_» I love work. It gives me something to do between weekends.

                E Offline
                E Offline
                ERLN
                wrote on last edited by
                #7

                good. How CPU-z software is telling core is 2 process is 1 on Windows XP ? ( CPU-Z)[^]

                S _ 2 Replies Last reply
                0
                • E ERLN

                  So There is no way for Windows XP . is it ?

                  S Offline
                  S Offline
                  Stuart Dootson
                  wrote on last edited by
                  #8

                  No, and it shouldn't really be a surprise. When Windows XP was designed (2001, remember!), multi-core processors (the whole idea of multiple independent processing units of one piece of silicon) hadn't been thought of, so Windows XP didn't include support for multi-core. Adding support may sound easy at first glance, but it cuts across many different parts of the system, so isn't easy to do.

                  Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                  E 1 Reply Last reply
                  0
                  • E ERLN

                    good. How CPU-z software is telling core is 2 process is 1 on Windows XP ? ( CPU-Z)[^]

                    S Offline
                    S Offline
                    Stuart Dootson
                    wrote on last edited by
                    #9

                    They have their own processor detection algorithms that allow them to tell what family a processor belongs to.[^]. Look at the number and frequency of updates they do to keep up with the latest processors... In addition, the page you point at shows that CPU-Z has a kernel mode driver, which allows CPU-Z to get at the real hardware, rather than what Windows presents as the hardware to user-mode.

                    Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                    1 Reply Last reply
                    0
                    • E ERLN

                      good. How CPU-z software is telling core is 2 process is 1 on Windows XP ? ( CPU-Z)[^]

                      _ Offline
                      _ Offline
                      _Superman_
                      wrote on last edited by
                      #10

                      I'm not really sure how that works. But I have a thought. The GetProcessAffinityMask[^] function returns a system affinity mask which represents the processors configured on the system. Perhaps this will give you the answer.

                      «_Superman_» I love work. It gives me something to do between weekends.

                      1 Reply Last reply
                      0
                      • S Stuart Dootson

                        No, and it shouldn't really be a surprise. When Windows XP was designed (2001, remember!), multi-core processors (the whole idea of multiple independent processing units of one piece of silicon) hadn't been thought of, so Windows XP didn't include support for multi-core. Adding support may sound easy at first glance, but it cuts across many different parts of the system, so isn't easy to do.

                        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                        E Offline
                        E Offline
                        ERLN
                        wrote on last edited by
                        #11

                        ok fine. Is there anyway to find number of processor and number of cores using any freeware library. I want to use it from windows 2000 onwards. Give a good solution

                        S 1 Reply Last reply
                        0
                        • E ERLN

                          ok fine. Is there anyway to find number of processor and number of cores using any freeware library. I want to use it from windows 2000 onwards. Give a good solution

                          S Offline
                          S Offline
                          Stuart Dootson
                          wrote on last edited by
                          #12

                          You are more likely to get a good answer if you're polite.[^]

                          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                          1 Reply Last reply
                          0
                          • E ERLN

                            How To Find Number of processors Present in the CPU ? How to Find Number of Cores Present in the CPU ? Is any possiblity to find Number Cores and Number of Processors ? (Is any difference ) ?

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            You can use the cpuid assembly instruction to get this information, it will require some assembly knowledge. I wrote the following functions a few years ago, you may want to check that they return the correct values. __inline BOOL IsHyperThreaded() { BOOL bHyperthread = 0; __asm { xor eax, eax cpuid cmp eax, 1 jb end xor eax, eax inc eax cpuid test edx, 0x10000000 jz end mov dword ptr [bHyperthread], 1 end: } return bHyperthread; } __inline unsigned int PhysicalCores() { unsigned int cores = 1; __asm { xor eax, eax cpuid cmp eax, 4 jb end mov eax, 4 xor ecx, ecx cpuid shr eax, 26 and eax, 0x1F add eax, 1 mov dword ptr [cores], eax end: } return cores; } __inline unsigned int CpuCores() { unsigned int cores = 0; __asm { xor eax, eax cpuid cmp eax, 4 jl single mov eax, 4 xor ecx, ecx cpuid mov cores, eax jmp multi single: xor eax, eax multi: } return (unsigned int)((cores & 0xFC000000) >> 26)+1; } __inline unsigned int LogicalCores() { unsigned int cores = 1; __asm { xor eax, eax cpuid cmp eax, 1 jb end xor eax, eax inc eax cpuid test edx, 0x10000000 jz end mov eax, ebx and eax, 0x00FF0000 shr eax, 16 mov cores, eax end: } return cores; } My code will not work on the MSVC 64 bit compiler, if you are creating a 64 bit application then you will need to use the CPUID intrinsics[^] Best Wishes, -David Delaune

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups