Sometimes problems don’t fit into one of the collections like dask.array or
dask.dataframe. In these cases, users can parallelize custom algorithms
using the simpler dask.delayed interface. This allows one to create graphs
directly with a light annotation of normal python code.

There is clearly parallelism in this problem (many of the inc and
double and add functions can evaluate independently), but it’s not
clear how to convert this to a big array or big dataframe computation.

As written this code runs sequentially in a single thread. However we see that
a lot of this could be executed in parallel.

The Dask delayed function decorates your functions so that they operate
lazily. Rather than executing your function immediately it will defer
execution, placing the function and its arguments into a task graph.

We used the dask.delayed function to wrap the function calls that we want
to turn into tasks. None of the inc, double, add or sum calls
have happened yet, instead the object total is a Delayed result that
contains a task graph of the entire computation. Looking at the graph we see
clear opportunities for parallel execution. The dask schedulers will exploit
this parallelism, generally improving performance. (although not in this
example, because these functions are already very small and fast.)