Reputation: 669
I know that I can use multiple threads on Julia by initializing a REPL with
julia --threads 4
but is there a way to add threads from within Julia? I can change nthreads by doing this
julia> Threads.nthreads()
1
julia> Threads.nthreads() = 4
julia> Threads.nthreads()
4
but I don't notice any performance increase. I have a feeling that setting the number of threads this way does not work the way I am expecting it to.
Upvotes: 2
Views: 1700
Reputation: 42244
You cannot increase the thread pool once Julia is started.
Perhaps the best option is to use auto
with the thread number parameter:
$ julia --threads auto
julia> Threads.nthreads()
8
Another important thing to know is that Julia can call C libraries that have their own independent thread pools. Linear algebra BLAS is the most notable example:
$ julia --threads 2
julia> using LinearAlgebra
julia> BLAS.get_num_threads()
8
julia> Threads.nthreads()
2
Upvotes: 2