I’m not able to use Threads.@spawn
with the kind of performance I’d expect:
samuela@n64:~/dev/research/julia/odecontrol$ JULIA_NUM_THREADS=32 julia --project
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.4.2 (2020-05-23)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> using LinearAlgebra
julia> using BenchmarkTools
julia> @time svdvals(rand(1000, 1000))
0.102739 seconds (33 allocations: 15.859 MiB)
1000-element Array{Float64,1}:
499.9432747031465
⋮
0.009891244161685905
julia> @time svdvals(rand(1000, 1000))
0.104076 seconds (12 allocations: 15.839 MiB, 3.85% gc time)
1000-element Array{Float64,1}:
500.352084696701
⋮
0.0012637056839913821
Ok, so the SVD takes about 100ms. Got it.
julia> @time Threads.@spawn svdvals(rand(1000, 1000))
0.003804 seconds (6.58 k allocations: 380.660 KiB)
Task (runnable) @0x00007f829b07b340
julia> @time Threads.@spawn svdvals(rand(1000, 1000))
0.000123 seconds (27 allocations: 2.203 KiB)
Task (runnable) @0x00007f829d945870
We can spawn a thread for the SVD and get back a Task in ~0.1ms. It stands to reason then that we should be able to spin up 1000 Tasks in the same way in about 100ms. But instead this code just hangs forever:
julia> @time [Threads.@spawn svdvals(rand(1000, 1000)) for _ in 1:1000]
..................
Why is that? Am I hitting some kind of thread limit?