I’m using windows 10 and julia 1.0.3 and testing out the multi-threaded function.
I understand that when generating random numbers we would need a separate seed for each thread but ignoring that for the purpose of a very preliminary test, I created the following code. In the following im trying to assess the overheads of calling a multi-threaded for loop multiple times.
#set JULIA_NUM_THREADS=4
test = zeros(10000,1000);
@time for i in 1:10000
Threads.@threads for j in 1:1000
test[i,j] = rand(1)[1]
end
end
When I ran the above code, I was returned a continuous stream of error messages, their counts likely correlated to the number of times the threaded loop was called. Sample of the errors are:
Error thrown in threaded loop on thread 0: InexactError(func=:check_top_bit, T=Int64, val=-8)
Error thrown in threaded loop on thread 2: InexactError(func=:check_top_bit, T=Int64, val=-8)
Error thrown in threaded loop on thread 1: InexactError(func=:check_top_bit, T=Int64, val=-8)
Error thrown in threaded loop on thread 0: InexactError(func=:check_top_bit, T=Int64, val=-8)
Error thrown in threaded loop on thread 3: InexactError(func=:check_top_bit, T=Int64, val=-8)
Error thrown in threaded loop on thread 1: InexactError(func=:check_top_bit, T=Int64, val=-8)
Error thrown in threaded loop on thread 2: InexactError(func=:check_top_bit, T=Int64, val=-8)
Error thrown in threaded loop on thread 3: InexactError(func=:check_top_bit, T=Int64, val=-8)
True enough, when i did a sum to check the results, sum(sum(test,dims=1),dims=2)
, my output was about 40081, way lesser than the expected value of 0.5 \times 10000 \times 1000.
Wondering what mistake I may have made…
Edit1: To think of it I suspect it’s sychronization issues, some threads may have finished and moved on to the next loop?