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()
?
help(multiprocessing) One of the useful functions in multiprocessing is cpu_count() . This returns the number of CPUs (computer cores) available on your computer to be used for a parallel program. Type into ipython. print(multiprocessing.cpu_count())
We can also use the os. cpu_count() function to return the count of the number of logical CPU cores in the current system.
Multiprocessing: The use of two or more CPUs within a single computer system [4][5]. The term also refers to the ability of a system to support more than one processor or the ability to allocate tasks between them.
In Python, single-CPU use is caused by the global interpreter lock (GIL), which allows only one thread to carry the Python interpreter at any given time. The GIL was implemented to handle a memory management issue, but as a result, Python is limited to using a single processor.
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
What CPU do you have, it might be counting the Physical cores + virtual cores.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With