I don’t really know what’s happening, but I can’t get it down to zero anymore. I can get it down to one by doing something really weird.
using StaticArrays
using LinearAlgebra
N=1000;
vertexList = Vector{StaticArrays.SVector{3,Float64}}(undef,N);
elements = Vector{StaticArrays.SVector{3,Int}}(undef,N);
for i in 1:1000
vertexList[i] = SA_F64[rand(),rand(),rand()];
elements[i] = SA[rand(1:N),rand(1:N),rand(1:N)];
end
elementLength = length(elements[1]);
function temp1(vertexList,elements)
elementLength = length(elements[1]);
acc = SA_F64[0,0,0];
for k in 1:size(elements,1)
vertices = vertexList[elements[k]];
edges = @SVector [vertices[v%elementLength+1]-vertices[v] for v in 1:elementLength];
edgesNorm = norm.(edges);
acc += edgesNorm;
end
return acc;
end
@time temp1(vertexList,elements);
Note that it only works if elementLength
is defined twice. Otherwise, I get 18k allocations.
Is someone is able to explain this?