[英]Why my CPU core number is 2, but use multiprocessing.cpu_count() get 4?
In my Mac: MacBook Pro (Retina, 13-inch, Early 2015)在我的 Mac 中:MacBook Pro(Retina,13 英寸,2015 年初)
there is the CPU information:有CPU信息:
Model: MacBook Pro
Model description: MacBookPro12,1
CPU name: Dual-Core Intel Core i5
CPU rate: 2.7 GHz
CPU number: 1
Core number: 2
When I use Python execute the code:当我使用 Python 执行代码时:
from multiprocessing import cpu_count
print(cpu_count()) # 4
there output 4
.有输出
4
。
Why not 2?为什么不是2?
I think multiprocessing.cpu_count()
returns the number of logic cores, not physical ones.我认为
multiprocessing.cpu_count()
返回逻辑内核的数量,而不是物理内核的数量。 For example, I have a surface pro 7, with 4 physical cores and 8 logic ones, and my output is:例如,我有一个 Surface pro 7,有 4 个物理内核和 8 个逻辑内核,我的输出是:
>>> print(multiprocessing.cpu_count())
8
Yes multiprocessing.cpu_count()
and os.cpu_count()
will return logical processors.是的
multiprocessing.cpu_count()
和os.cpu_count()
将返回逻辑处理器。 If you want to check logical and physical processors seperately you can use psutil
They can be uses as shown below.如果你想分别检查逻辑和物理处理器,你可以使用
psutil
它们可以如下所示使用。
import psutil
print(psutil.cpu_count(logical = False))
print(psutil.cpu_count(logical = True))
output will be输出将是
2 2
4 4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.