First post - what am I doing wrong - distributed benchmark show no improvement

Howdy - this is my first foray into Julia so I started with Gary Feierbach “Learning Julia 1.0” O’Reilly video. I am on Julia 1.5 (installed a while ago but never started). And on Win10 machine.
After first lecture I wanted to time some code and it seems that Distributed does not seem to work - what am I doing wrong? Code is below:

julia> using Distributed
julia> function head_count_parallel(count)
           heads = @distributed (+) for i=1:count
           Int(floor(rand()+0.5))
               end
           return heads
       end
head_count_parallel (generic function with 1 method)
julia> function head_count(count)
           heads = 0
           for i=1:count
               heads += Int(floor(rand()+0.5))
           end
           return heads
       end
head_count (generic function with 1 method)
julia> using BenchmarkTools
julia> @btime head_count(200000000)
  826.122 ms (0 allocations: 0 bytes)
100015574
julia> @btime head_count_parallel(200000000)
  831.377 ms (29 allocations: 1.84 KiB)
99991249

Hello and welcome!

I think you fail to see any speedup here because the computation is too simple. There is an overhead associated with both threading and distributed computing, the latter typically higher than the former. Unless the computation performed in each of the loop iteration is large, the overhead of distributing the computation might make it slower overall.

For lower-overhead threading, you may have a look at https://github.com/JuliaSIMD/Polyester.jl

3 Likes

Thank you - that (overhead) certainly makes sense. Thank you for the link!