In the following minimal example, an outer function executes the inner function many times in parallel and is itself executed multiple times. The problem is trivially parallelizable, i.e. there are no dependencies across tasks.
I'm running Julia with 22 threads:
julia> Base.Threads.nthreads()
22
Copy-pasteable example
using Dagger
# Inner function
function inner_sleep()
sleep(2)
end
# Outer function
function outer_sleep()
@sync for _ in 1:10
Dagger.@spawn inner_sleep()
end
Base.Threads.threadid()
end
# Run outer task N times in parallel
@time fetch.([Dagger.@spawn outer_sleep() for _ in 1:2])
Results
If my understanding of the task-based parallelism approach is correct, this should take roughly 2 seconds regardless of how many outer tasks I'm spawning.
This actually takes ~4 seconds instead, on my machine.
Context
In the following minimal example, an outer function executes the inner function many times in parallel and is itself executed multiple times. The problem is trivially parallelizable, i.e. there are no dependencies across tasks.
I'm running Julia with 22 threads:
Copy-pasteable example
Results
If my understanding of the task-based parallelism approach is correct, this should take roughly 2 seconds regardless of how many outer tasks I'm spawning.
This actually takes ~4 seconds instead, on my machine.