I have a question regarding LoopVectorization.jl. I’ve been trying to integrate it into my project but am stuck with some errors. Here is a MWE that reproduces it:
function F!(xllp ::Vector{Vector{Int}}, xllw ::Vector{Vector{Float64}}, yllp ::Vector{Vector{Int}}, yllw ::Vector{Vector{Float64}}, Zp ::Array{Int,2}, Zw ::Array{Float64,2}) ::Nothing
m, n = size(Zw,1), length(xllp)
@tturbo for k=1:n
t = Threads.threadid()
for i=1:m Zw[i,t]=0 end # clear from previous computation
for j=1:length(xllp[k])
v, w = xllp[k][j], xllw[k][j]
Zw[v, t] += w end # sum weights with same position
i=1
for ii=1:m # recover sorted unique positions
Zp[i,t] = ii
Zw[i,t] = Zw[ii,t]
i += (Zw[ii,t]==0 ? 0 : 1) end
i-=1
yllp[k], yllw[k] = Zp[1:i,t], Zw[1:i,t] # store result permanently
end; return nothing end;
m,n,s, nt = 10^1,10^1,5, Threads.nthreads() # create toy data
xllp = [rand(1:m,rand(0:s)) for j=1:n]
xllw = [rand(Float64,length(l)) for l in xllp]
yllp, yllw = Vector{Vector{Int}}(undef,n), Vector{Vector{Float64}}(undef,n)
Zp, Zw = fill(Int(0),m,nt), fill(Float64(0),m,nt) # temporary arrays for calculations
F!(xllp,xllw,yllp,yllw,Zp,Zw) # run F! on toy data
If you run this, you’ll get:
ERROR: LoadError: UndefVarError: `k` not defined
Stacktrace:
[1] F!(xllp::Vector{Vector{Int64}}, xllw::Vector{Vector{Float64}}, yllp::Vector{Vector{Int64}}, yllw::Vector{Vector{Float64}}, Zp::Matrix{Int64}, Zw::Matrix{Float64})
@ Main E:\Dropbox\programming_Julia\Q06\Q06.jl:6
[2] top-level scope
@ E:\Dropbox\programming_Julia\Q06\Q06.jl:26
[3] include(fname::String)
@ Base.MainInclude .\client.jl:478
[4] top-level scope
@ REPL[10]:1
in expression starting at E:\Dropbox\programming_Julia\Q06\Q06.jl:26
However, running the same code without @tturbo
works as desired. Any idea on what the issue is? Is there a way to reorganize my code to be accepted by @tturbo
?