I have N groups. For each group I have J*K options for each agent i. I want to find the maximum over j,k for each I, and do so for each group n. The problems are all separate from each others.
Threads.@threads for j in 1:J
for k in j+1:K
@inbounds x[j,k,:] = v[j,k,n] + shock[j,k,:]
end
end
maxJK = (x.==maximum(x,dims=[1,2]))
end
Then maxJK is used to fill some matrices, also indexed by n.
Here the third dimension of shock is the index of agent i. The dimension of I is large (about 10000). If I multithread in the outer loop, so that I multithread the max, I think the code messes up because multiple threads are using maxJK. Regardless, this code seems very slow. I wonder how it could be made faster.