Tutorial by Examples

pmap takes a function (that you specify) and applies it to all of the elements in an array. This work is divided up amongst the available workers. pmap then returns places the results from that function into another array. addprocs(3) sqrts = pmap(sqrt, 1:10) if you function takes multiple ar...
@parallel can be used to parallellize a loop, dividing steps of the loop up over different workers. As a very simple example: addprocs(3) a = collect(1:10) for idx = 1:10 println(a[idx]) end For a slightly more complex example, consider: @time begin @sync begin @paral...
The macros @spawn and @spawnat are two of the tools that Julia makes available to assign tasks to workers. Here is an example: julia> @spawnat 2 println("hello world") RemoteRef{Channel{Any}}(2,1,3) julia> From worker 2: hello world Both of these macros will evaluate an ex...
The Julia documentation advises that pmap() is designed for the case where each function call does a large amount of work. In contrast, @parallel for can handle situations where each iteration is tiny, perhaps merely summing two numbers. There are several reasons for this. First, pmap incurs ...
According to the documentation under ?@async, "@async wraps an expression in a Task." What this means is that for whatever falls within its scope, Julia will start this task running but then proceed to whatever comes next in the script without waiting for the task to complete. Thus, for...
When you first start Julia, by default, there will only be a single process running and available to give work to. You can verify this using: julia> nprocs() 1 In order to take advantage of parallel processing, you must first add additional workers who will then be available to do work that...

Page 1 of 1