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

What's the difference between dask=parallelized and dask=allowed in xarray's apply_ufunc?

在函数 apply_ufunc 的 xarray documentation 中说:

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 是否仍然对块进行逐个操作以降低内存使用率?如果应用的 ufunc 仅使用 dask 操作,allowed 是否仍会并行化?为什么 parallelizedallowed 要求您提供更多关于 ufunc 输出的信息(即参数 output_dtypesoutput_sizes)?

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

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