Happy new year.
I thought I had written the following function to do only in-place
operations, yet the @time macro gives:
@time TB.evalSiteFunction!(frcMM, geom, Y, Frc)
>>> elapsed time: 0.547410386 seconds (167131408 bytes allocated, 20.08% gc
time)
where is memory being allocated?
Are there other performance-critical mistakes I made here?
Many thanks,
Christoph
notes:
* frcMM, geom are some specialised types, Y and Frc are 2 x N arrays, N
\approx 10^4
* the outer loop runs over approx. 10^4 indices (but could range from
10^3 to 10^9)
* the inner loop runs over about 40 indices
* geom.I is a 2 x 2 Int64 array, sp.stencil is a 2 x nneig array
function evalSiteFunction!(sp::SiteLinear, geom::tbgeom,
Y::Array{Float64,2},
Frc::Array{Float64,2} )
# extract dimension information (d1, d2 \in \{2, 3\})
d1, d2, nneig = size(sp.coeffs)
# allocate some variables
kX = 0::Int; jX = 0::Int; jI = zeros(Int, d1)
# assert type of the index set over which we are looping
J = geom["iMM"]::Array{Int, 1}
for jX in J
# get lattice position of point jX
jI[:] = geom.X2I[:, jX]
# initialise force to 0
Frc[:,jX] = 0.0
# loop over neighbouring sites
for n in 1:nneig
# get the X-index of the current neighbour
kX = geom.I[ jI[1]+sp.stencil[1,n], jI[2]+sp.stencil[2,n] ]
# evaluate the term (devectorized for performance)
# f[:] += slice(sp.coeffs, :, :, n) * Y[:, kX]
for i = 1:d1, j = 1:d2
Frc[i,jX] += sp.coeffs[i, j, n] * Y[j, kX]
end
end
end
end
@profile TB.evalSiteFunction!(frcMM, geom, Y, Frc)
elapsed time: 0.641862345 seconds (167115424 bytes allocated, 26.21% gc time)
Profile.print()
1 ...ia/lib/julia/sys.dylib; disassociate_julia_struct; (unknown line)
1 abstractarray.jl; checkbounds; line: 65
1 array.jl; getindex; line: 247
803 task.jl; anonymous; line: 340
803 .../IJulia/src/IJulia.jl; eventloop; line: 123
803 ...rc/execute_request.jl; execute_request_0x535c5df2; line: 140
803 loading.jl; include_string; line: 97
802 profile.jl; anonymous; line: 14
1 ...qmmm/TBmultiscale.jl; evalSiteFunction!; line: 56
2 ...qmmm/TBmultiscale.jl; evalSiteFunction!; line: 196
4 ...qmmm/TBmultiscale.jl; evalSiteFunction!; line: 200
4 multidimensional.jl; getindex; line: 50
1 multidimensional.jl; _getindex!; line: 37
1 ...qmmm/TBmultiscale.jl; evalSiteFunction!; line: 202
1 abstractarray.jl; checkbounds; line: 65
1 ...qmmm/TBmultiscale.jl; evalSiteFunction!; line: 204
47 ...qmmm/TBmultiscale.jl; evalSiteFunction!; line: 206
5 array.jl; getindex; line: 247
745 ...qmmm/TBmultiscale.jl; evalSiteFunction!; line: 210
1 .../lib/julia/sys.dylib; *; (unknown line)
1 .../lib/julia/sys.dylib; +; (unknown line)
6 array.jl; getindex; line: 247
9 array.jl; setindex!; line: 308