python - xarray 的 apply_ufunc 中 dask=parallelized 和 dask=allowed 有什么区别?

标签 python numpy dask python-xarray numpy-ufunc

xarray documentation对于函数 apply_ufunc,它说:

dask: ‘forbidden’, ‘allowed’ or ‘parallelized’, optional

    How to handle applying to objects containing lazy data in the form of dask arrays:

    ‘forbidden’ (default): raise an error if a dask array is encountered.
    ‘allowed’: pass dask arrays directly on to func.
    ‘parallelized’: automatically parallelize func if any of the inputs are a dask array. 
                    If used, the output_dtypes argument must also be provided. 
                    Multiple output arguments are not yet supported.

并在 Parallel Computing 上的文档页面中然后有一个注释:

For the majority of NumPy functions that are already wrapped by dask, it’s usually a better idea to use the pre-existing dask.array function, by using either a pre-existing xarray methods or apply_ufunc() with dask='allowed'. Dask can often have a more efficient implementation that makes use of the specialized structure of a problem, unlike the generic speedups offered by dask='parallelized'.

但是,我仍然不清楚这两个选项之间的区别。 allowed 是否仍然对 block 进行逐个操作以降低内存使用量?如果应用的 ufunc 仅使用 dask 操作,allowed 是否仍会并行化?为什么 parallelized 要求您提供比 allowed 是吗?

最佳答案

dask='allowed' 表示您正在应用已经知道如何处理 dask 数组的函数,例如,根据 编写的函数dask.array 操作。在大多数情况下,这确实意味着该函数将一个一个地对 block 进行操作以降低内存使用量,并将并行应用计算。

dask='parallelized' 需要来自用户的更多信息,因为它创建了自己的包装器,通过使用低级 dask.array 函数(例如 atop),允许提供的函数作用于 dask 数组。使用 dask='parallelized',您可以提供一个只知道如何处理 NumPy 数组的函数,xarray.apply_ufunc 也会扩展它以处理 dask 数组。

关于python - xarray 的 apply_ufunc 中 dask=parallelized 和 dask=allowed 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51736172/

相关文章:

python - 导入和 reshape MNIST 数据,numpy

python - dask:并行模型中的共享内存

dask - 触发 Dask worker 释放内存

python - 如何在不同目录下运行python?

python - 如果有 2 个 keras 模型共享层,设置 trainable=False 后要编译哪个模型?

python - 在 numpy 中应用二维函数的最佳方法

python - 通过热图绘制横截面

pandas - 如何在 dask DataFrame 上调用 unique()

python - 使用服务主体登录 python 脚本

python - 如何使用Python求解Lambert W函数?