Ask Your Question

Revision history [back]

If you want/need something fancier, you can use the @parallel decorator. When you decorate a function definition with this, it automatically becomes a function which can take a list (or other iterable) of inputs. The output in that case is an iterator which computes the values of the original function on each list element, and it does so in parallel. This is probably worse than map if your function calls are very very fast, but if the computation takes more time it's quite useful. And it has the advantage of requiring no extra syntax for the function call. The tradeoff is that the output list is not just the list of function values, but also contains the input values too, and thus requires some parsing. This is because the outputs are returned in the order that computations are finished, not the order they are begun.

There are some other answers on this site which expand on the (pretty weak) manual description of @parallel. Here's one to start with: When/How to use parallel.