Julia Language for Loops Reduction and parallel loops


Example

Julia provides macros to simplify distributing computation across multiple machines or workers. For instance, the following computes the sum of some number of squares, possibly in parallel.

function sumofsquares(A)
    @parallel (+) for i in A
        i ^ 2
    end
end

Usage:

julia> sumofsquares(1:10)
385

For more on this topic, see the example on @parallel within the Parallel Processesing topic.