python - 在Python中使用Dask并行运行函数

标签 python parallel-processing dask

我正在尝试使用 Dask.delayed 来并行计算函数。 函数 BL.BLSN 有 1 个字符串参数。

runs=['forcing.dat','forcing.dat','forcing.dat','forcing.dat','forcing.dat','forcing.dat']
dfs = [delayed(BL.BLSN)(fn) for fn in runs]

当我打印 dfs 时,我得到了延迟对象的列表。这正是我所期待的。

[Delayed('BLSN-630cb6bf-7104-4d41-b5fb-544116fec7ed'), Delayed('BLSN-150a5d45-073a-48af-af03-6e85f809617c'), Delayed('BLSN-484e7d71-af09-4a1f-be28-42358ef745e9'), Delayed('BLSN-2f2f2cc1-76bc-4c29-839d-091255556f35'), Delayed('BLSN-8aae0a06-d607-4a98-89a7-cfd2c877bf11'), Delayed('BLSN-f0131a69-2bfd-4153-94c1-2d3ef4973772')

]

但是,当我尝试时:

dfs.compute()

我得到:

AttributeError: 'list' object has no attribute 'compute'

对列表中的每个对象进行计算操作的最佳方式是什么?

最佳答案

您想要 compute 的函数形式而不是方法:

import dask
dask.compute(*dfs)

这将并行运行(带有通常的警告),如果任务共享依赖项,它们将被智能地共享。

关于python - 在Python中使用Dask并行运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58664548/

相关文章:

python - numpy 排列的 2D

parallel-processing - CPU SIMD和GPU SIMD?

C++ OpenMP : nested loops where the inner iterator depends on the outer one

python - 将 SQL 查询读入 Dask DataFrame

python - 延时函数解包结果

用于强制自定义类型的不变性的 Python 元类

python - 如何加快Python代码在功能强大的计算机上运行的速度?

python - 找出句子中所有的小写单词

language-agnostic - 如何学习多线程并行编程?

dask - 如何使用 Iguazio 设置 Dask 自动缩放?