简体   繁体   English

为什么我的 CPU 核心数是 2,但使用 multiprocessing.cpu_count() 得到 4?

[英]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.

相关问题 multiprocessing.cpu_count返回错误的内核数量 - multiprocessing.cpu_count returning wrong number of cores multiprocessing.cpu_count和os.cpu_count之间的区别 - Difference between multiprocessing.cpu_count and os.cpu_count Python multiprocessing.cpu_count() 在 4 核 Nvidia Jetson TK1 上返回“1” - Python multiprocessing.cpu_count() returns '1' on 4-core Nvidia Jetson TK1 如果在python multiprocessing.cpu_count()中返回64,我是否可以从gcloud计算引擎的96个vCPU中受益? - Do I benefit from the 96 vCPUs of a gcloud Compute Engine if in python multiprocessing.cpu_count() returns 64? 为什么我的 python 多处理不能使用所有 cpu? - why my python multiprocessing can't use all cpu? 多处理池大小 - cpu_count 或 cpu_count/2? - Multiprocessing pool size - cpu_count or cpu_count/2? 为什么在我使用多处理时我的 CPU 没有 100% 运行? - Why my CPU are not running 100% while I'm using multiprocessing? 为什么多处理在Google Compute Engine中不使用100%CPU? - Why doesn't Multiprocessing use 100% CPU in Google Compute Engine? 多处理:比cpu.count更多的进程 - Multiprocessing : More processes than cpu.count Python 多线程/多处理和限制 CPU 内核关联性 - Python multithreading/multiprocessing & limiting CPU core affinity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM