Not seeing speed-up with Dagger.jl. Am I doing something wrong?

  1. I am setting 8 CPU cores using the following code:
using IJulia
installkernel("Julia (8 threads)", env=Dict("JULIA_NUM_THREADS"=>"8"))
Threads.nthreads()
  1. I change the kernel environment of the Jupyter Notebook to the 8 CPU core environment.

  2. Run the non-Dagger command

e = zeros(173,290)
f = ones(290)

function a!(b,c,d)
    for j in 1:290
        e[t, j] = f[j]
        f[j] = e[t, j]
    end
end

@time begin

for t in 1:173
        
        a!(t)
end
end

The result is

  0.021634 seconds (100.34 k allocations: 1.531 MiB)

However, when I run the Dagger.jl command:

e = zeros(173,290)
f = ones(290)

function a!(t)
    for j in 1:290
        e[t, j] = f[j]
        f[j] = e[t, j]
    end
end

@time begin

@sync for t in 1:173
        
        Dagger.@spawn a!(t)
end
end

The result is:

  0.620212 seconds (283.25 k allocations: 11.632 MiB, 2.90% compilation time)

Am I doing something wrong? I am not seeing a speed-up from using Dagger

Your code takes 0.02 seconds to run in serial, it seems very unlikely that you would amortize the overhead of distributed computing over such a trivial task?

This is a smaller version of a much larger problem. But yes you are right, maybe I should use the parameters of the larger problem to see if distribution is helpful.

I guess my question is more along the lines of, did I write the Dagger.jl code properly

Dagger has reasonably high overhead right now, but even if I bring that down significantly (which I am working on), your non-Dagger code can very trivially be optimized by Julia’s compiler across calls to a!, whereas Dagger cannot (yet) do something like this. So it’ll be very hard for Dagger to be competitive, and I wouldn’t expect that at this small scale. Maybe try @spawning a larger set of a! calls as one Dagger task, to amortize overhead and let Julia’s compiler work better with Dagger?

Thank you!

If I may make a general comment - and I hope not to speak out of turn - from all your questions in the last days it appears that you are fairly new to Julia and are trying to jump right into the deep end.

Julia’s performance model can at times be subtle (cf. the length of the Performance Tips · The Julia Language at this point) so new users can often find remarkable speedups by focusing on implementing all performance tips while focusing on single threaded execution speed. Multithreading and distributed computing adds another layer of complexity which often isn’t helpful to get into before you are sure you’ve squeezed every bit of performance out of the basic non-parallel version of your code.

1 Like

No worries, I appreciate your honesty with me. And yes, compared to the people on this forum, I am fairly new to the language.

Thanks for the link, I’ll check it out.

2 Likes

I’d like to thank you for sharing the Performance Tips link.

I was able to speed up performance by 2x simply be defining certain variables as “const”.

2 Likes