Hello,
I have code, which assembles coefficients into large sparse matrix. My coding seems to be inefficient as I use 3 loops, so I'm trying to improve the code to get better pefromance. I think it would be nice to reduce the number of loops to single loop and run it parallel (parfor), but I'm struggling to do that..
The main matrix sig is a matrix of size LX,LY,LZ and vectors dx, dy, dz holds the distances between nods along the diretion X, Y an Z.
for i = 2:LX-1 for j = 2:LY-1 for k = 2:LZ-1 Ctop(i,j,k) = (-1/dz(k-1))*((sig(i-1,j ,k-1)*((dx(i-1)*dy(j ))/4))+... (sig(i ,j ,k-1)*((dx(i )*dy(j ))/4))+... (sig(i-1,j-1,k-1)*((dx(i-1)*dy(j-1))/4))+... (sig(i ,j-1,k-1)*((dx(i )*dy(j-1))/4))); end end endC1v=reshape(Ctop,[],1);
thanks for help!
Best Answer