I'm playing around for the first time with parallel computing with julia. I'm having a bit of a headache. So let's say I start julia as follows: julia -p 4. Then I declare the a function for all processors and then I use it with pmap and also with @parallel for.
@everywhere function count_heads(n)
c::Int = 0
for i=1:n
c += rand(Bool)
end
n, c # tuple (input, output)
end
###### first part ######
v=pmap(count_heads, 50000:1000:70000)
println("Result first part")
println(v)
###### second part ######
println("Result second part")
@parallel for i in 50000:1000:70000
println(count_heads(i))
end
The result is the following.
Result first part
Counting heads function
Any[(50000,24894),(51000,25559),(52000,26141),(53000,26546),(54000,27056),(55000,27426),(56000,28024),(57000,28380),(58000,29001),(59000,29398),(60000,30100),(61000,30608),(62000,31001),(63000,31520),(64000,32200),(65000,32357),(66000,33063),(67000,33674),(68000,34085),(69000,34627),(70000,34902)]
Result second part
From worker 4: (61000, From worker 5: (66000, From worker 2: (50000, From worker 3: (56000
Thus, the funcion pmap is apparently working fine but @parallel for is stopping or it doesn't give me the results. Am I doing something wrong?
Thanks!
Update
If at the end of the code I put sleep(10). It does the work correctly.
From worker 5: (66000,33182)
From worker 3: (56000,27955)
............
From worker 3: (56000,27955)
printlnas I guess thats more likely to be what you'll use them for later - Alexander Morley