I might have misunderstood something about the expected behavior of the bitwise AND or the
@threads macro, but I have observed something I think is odd.
Suppose we have a function that uses a for loop with
@threads to perform the bitwise AND of two bitarrays in an element-wise fashion. That should agree with the result of using
a & b, right? The toy example below disagrees with this when using
function bitwise_and2(a::BitArray, b::BitArray) n = length(a) res = falses(n) Threads.@threads for i = 1:n res[i] = a[i] & b[i] end res end function trials(n, n_iter) for i = 1:n_iter a = bitrand(n) b = bitrand(n) y1 = bitwise_and2(a, b) y2 = a & b println(i) @assert y2 == y1 end end trials(100, 1000) # throws AssertionError
@threads macro from the
bitwise_and2() function seems to consistently give results that agree with
a & b.
Have I missed something obvious concerning
@threads or the bitwise AND? I would appreciate any guidance on what is causing this behavior.