Hi, I’m getting an allocation from the following code, which results in a factor 20x slowdown in this MWE:
using SharedArrays,BenchmarkTools,StaticArrays
U = SharedArray{Float64}(zeros(100,100,100))
function mytestfun(U)
function getIndices(i,j,k)
#return U[i,j,k]
return U[mod(i,3)+1,j,k]
end
uvals = @SArray [getIndices(i,j,k) for i in 1:4, j in 1:4, k in 1:4]
return uvals[1]
end
@btime mytestfun($U)
Compare the code above to the same code but with line 7 uncommented, which results in it having zero allocations. Does anyone know what is going on?