6

I try to use the following code to decide the number of cores of my laptop:

import multiprocessing
multiprocessing.cpu_count()

The result is 8, but when I open the system report, I can see that I have only 1 CPU with 4 cores.

What's wrong with cpu_count()?

2 Answers 2

7

You have 4 physical cores, but 8 logical processors. For example, you may have a processor with hyper-threading.

From SuperUser: Difference Between Cores and Processors

2
  • 1
    What function should I call to get the number of physical cores?
    – satoru
    Jul 5, 2016 at 7:12
  • From this answer stackoverflow.com/a/14840102/431033: psutil has a cpu_count function with this option.
    – Lack
    Jul 5, 2016 at 16:15
1

What CPU do you have, it might be counting the Physical cores + virtual cores.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.