Threading with @views and @tensor

Hi,
personally, I have never heard of views not being threadsafe but there was a recent post that mentions thread-unsafe behaviour with pre-allocated Arrays that are indexed by threadid() whenever there is a “yield” involved:

https://juliafolds.github.io/FLoops.jl/dev/explanation/faq/#faq-state-threadid

On first glance, this doesnt seem to be the case here, but maybe there is something weird happening under the hood in the @tensor macro?
You can find out if your issue is connected with this by allocating W inside the loop ( just for testing, of course)

Likewise, if you really are suspicious of @views causing the issue, you could temporarily remove the macro and write the indices explicitly to see if the problem ramains.

Its curious that removing the second @tensor call seems to remove thread-unsafety, it might be worth to try and write the loops over a,b,c explicitly.

hopefully one of these ideas helps you :slight_smile: