Tullio.jl icon indicating copy to clipboard operation
Tullio.jl copied to clipboard

Make sure to avoid race conditions with nontrivial LHS indexing

Open piever opened this issue 4 years ago • 1 comments

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.

piever avatar Feb 18 '21 16:02 piever

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).

mcabbott avatar Feb 18 '21 17:02 mcabbott