Tullio.jl
Tullio.jl copied to clipboard
Make sure to avoid race conditions with nontrivial LHS indexing
The following is valid Tullio code:
@tullio C[i ÷ 2, k] += A[i, j] * B[j, k]
but a naive implementation could incur in a race condition (as different values of i end up writing in the same slot in C). Following a conversation on slack, the default should be "safe but slow", so avoid multithreading on unsafe indices.
Thanks for the issue. Sadly I think it gets this wrong at present, and may divide i up among threads. There will be other examples too, like C[mod(i),k] += ... -- all things which aren't allowed on the LHS when making a new array. They should probably be marked "unsafe" like the index i in @tullio C[I[i], k] += ... (which I believe it gets right).