Try changing the order of your loops: for i in 1:nx, j in 1:ny, k in 1:nz
-> @inbounds for k in 1:nz, j in 1:ny, i in 1:nx (@inbounds disable bounds checking for arrays, it usually makes a small improvement).
Try changing the order of your loops: for i in 1:nx, j in 1:ny, k in 1:nz
-> @inbounds for k in 1:nz, j in 1:ny, i in 1:nx (@inbounds disable bounds checking for arrays, it usually makes a small improvement).