Python multiprocessing.cpu_count()在4核Nvidia Jetson TK1上返回'1' [英] Python multiprocessing.cpu_count() returns '1' on 4-core Nvidia Jetson TK1

查看:211
本文介绍了Python multiprocessing.cpu_count()在4核Nvidia Jetson TK1上返回'1'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我为什么在Jetson上调用Python的 multiprocessing.cpu_count()函数会返回 1 的原因带有四个ARMv7处理器的TK1?

 >>导入多处理
>> multiprocessing.cpu_count()
1

Jetson TK1板差不多盒子,没有人把cpusets弄乱了。在同一个Python Shell中,我可以打印 / proc / self / status 的内容,它告诉我该进程应该可以访问所有四个内核:

 >>打印open('/ proc / self / status')。read()
-----(snip)-----
Cpus_allowed:f
Cpus_allowed_list:0-3
-----(snip)-----

可能还会导致什么 cpu_count()的行为?



编辑:



<为了测试克劳斯的假设,我使用以下代码运行了一个非常简单的实验:

  import multiprocessing 

def f(x):
n = 0
对于xrange(10000)中的i:
n = max(n,multiprocessing.cpu_count())
返回n

p = multiprocessing.Pool(5)
for i in range(10):
print p.map(f,[1,2,3,4,5])

产生了以下输出:

  [3、3、3、3、1] 
[4、3、3、3、3]
[4、3、3、3、3]
[3,3,4,3,3]
[4,3,3,3,3]
[3,3,4,4,3,3]
[4, 3、3、3、3]
[3、3、4、3、3]
[3、3、3、4、3]
[4、3、3、3 ,3]

仅运行 p.map(f,[1,2,3,4,5])的单个迭代通常会产生 [1,1,1,1,1] ,尽管有时 2 会作为列表元素之一出现。

解决方案

在Linux系统上, multiprocessing.cpu_count()依赖于 sysconf(_SC_NPROCESSORS_ONLN)调用,该调用返回在线 CPU的数量,而不是 sysconf(_SC_NPROCESSORS_CONF)返回已配置的 CPU的数量。



在具有高级CPU电源管理功能(可将CPU内核设置为脱机以节省能源)或具有类似的动态CPU激活功能的系统中,这些值可能会有所不同。


Can anyone tell me why Python's multiprocessing.cpu_count() function would return 1 when when called on a Jetson TK1 with four ARMv7 processors?

>>> import multiprocessing
>>> multiprocessing.cpu_count()
1

The Jetson TK1 board is more or less straight out of the box, and no one has messed with cpusets. From within the same Python shell I can print the contents of /proc/self/status and it tells me that the process should have access to all four cores:

>>> print open('/proc/self/status').read()
----- (snip) -----
Cpus_allowed:   f
Cpus_allowed_list:      0-3
----- (snip) -----

What else could be causing this behavior from cpu_count()?

Edit:

To test Klaus's hypothesis, I used the following code to run a very simple experiment:

import multiprocessing

def f(x):
    n = 0
    for i in xrange(10000):
        n = max(n, multiprocessing.cpu_count())
    return n

p = multiprocessing.Pool(5)
for i in range(10):
    print p.map(f, [1,2,3,4,5])

Which produced the following output:

[3, 3, 3, 3, 1]
[4, 3, 3, 3, 3]
[4, 3, 3, 3, 3]
[3, 3, 4, 3, 3]
[4, 3, 3, 3, 3]
[3, 3, 4, 3, 3]
[4, 3, 3, 3, 3]
[3, 3, 4, 3, 3]
[3, 3, 3, 4, 3]
[4, 3, 3, 3, 3]

Running just a single iteration of p.map(f, [1,2,3,4,5]) usually produces [1, 1, 1, 1, 1], although occasionally a 2 will appear as one of the list elements.

解决方案

On Linux systems multiprocessing.cpu_count() relies on a sysconf (_SC_NPROCESSORS_ONLN) call, which returns the number of online CPUs in contrast to sysconf (_SC_NPROCESSORS_CONF) which returns the number of configured CPUs.

The values might differ in systems with advanced CPU power management functionality that sets CPU cores offline to save energy or with similar dynamic CPU activation functionality.

这篇关于Python multiprocessing.cpu_count()在4核Nvidia Jetson TK1上返回'1'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆