Hi, I am trying to implement some multi-threading on my project written in julia. Although, it seems that @threads macro does not work as I intended. I have tried almost every solutions / multithreading methods I could find online, but none of them worked.
Here is the simplified code of what I have tried to do.
function part_myfunc(tmpobj, array1, array2) # array1 and array2 has same size
for i in eachindex(array2)
tmpobj= calc(tmpobj, array1[i], array2[i])
end
tmpobj
end
function myfunc(myobj, matrix1, matrix2)
_, k = size(matrix2)
tmpobjs = Array{MyObject, 1}(undef, k)
for i = 1 : k
tmpobjs[i] = initialise()
end
@threads for i = 1 : k
tmpobjs[i] = part_myfunc(tmpobjs[i], array1[:, i], array2[:, i])
end
for i = 1 : k
myobj = part_myfunc2(myobj, tmpobjs[i])
end
myobj
end
This code returns a valid output when I get rid of @threads from the second for loop in the function myfunc, but with @threads, it does not. I don’t even have a slightest clue why it returns an invalid output. I have read the julia docs but it wasn’t very helpful. Is there anything that I’m missing?