Are threads inside a spawn supposed to find empty threads to use? For example, my function uses
@threads to perform 3 10 second
sleeps in 10 seconds total. If I then try to spawn 3 of these function calls, ideally I would want them to happen in parrallel and take 10 seconds. However, it takes 30 seconds to run it. Why do spawn and threads not find the empty threads to run it on? I’ve launched julia with 10 threads on a 20 thread machine.
Working example demonstrating
function test(str) Threads.@threads for i in 1:3 sleep(10) end return "$str done" end t1 = Threads.@spawn test("one") t2 = Threads.@spawn test("two") t3 = Threads.@spawn test("three") fetch(t1) fetch(t2) fetch(t3)
If 9 threads were used for each sleep, it would take 10 seconds total instead of the 30 seconds.
julia> Threads.nthreads() 10
[pmcvay@pmcvay ~]$ nproc 20