Question about @threads

I have some workload and want to work on it using all threads. If I do

Threads.@threads for _ in 1:nthreads()
    # doit
end 

Is it guaranteed, that all threads are used, or could it be that one thread occurs multiple times?
For instance does the following always hold:

using Base.Threads: threadid, nthreads, @threads
ret = fill(-1, Threads.nthreads())
@threads for _ in 1:nthreads()
    ret[threadid()] = threadid()
end
@test ret == 1:nthreads()

No that will not be guaranteed whether or not the current implementation has this property.

1 Like

Actually, I just realized that the bandaid I put in there for nested threaded loop is still there (I thought is is gone with the merge of the partr branch but apparently not…) so no the current implementation does not have such a property either.

1 Like

Thanks for the clarification!