I just switched to 1.3 to try out implementing multithreaded algorithms. I tried a very simple loop, from the announcement post:
Threads.@threads for i = 1:10
println(Threads.threadid(), " of ", Threads.nthreads())
end
However, this only printed 1 of 4 every time I ran it, no matter how many iterations. Clearly, nthreads() shows that I have 4 threads available - how do I make sure my loops use all of them?
I’m using juno, which I thought automatically set it to the number of cores. Since nthreads() returns 4, doesn’t that mean that it has been properly set?
Hello,
I am having the same problem… I am trying to use 12 threads to perform a task. I checked that 12 threads are available to Julia by running: Threads.nthreads()
which gives me 12.
Then I test if multithreading works on a simple example:
z = zeros(10)
Threads.@threads for i = 1:10
z[i] = Threads.threadid()
end
z
Has you checked the JULIA_NUM_THREADS variable? I have just update that variable, and later I have run your code, obtaining different values in z array, one different for each thread.
Yes, JULIA_NUM_THREADS variable was 12. I now solved the problem after restarting Julia 2 times from when it wasn’t working. Not sure what went wrong the first 2 times… Thank you for the reply!