I have some medium sized 3d arrays (approx 500x500x10) for which I sometimes need to copy a section of the array to a different (non-intersecting) section of the same array. E.g.:
a(:,:,1:3) = a(:,:,4:6)
I was surprised to find out that a temporary copy is made (inferred from the stack overflow I get which I don't get if the last subscripts are constants) in this case since it's trivial to confirm that the sections do not overlap. The sollution is then to use a loop, but I find that "unattractive" compared to using the array section language feature.
Is it possible to avoid a copy in some other way?
And another, related question: if the subscript bounds are not literal constants but (scalar) variables I find that not even the loop approach works, i.e.
j = 3 DO i = 1,3 a(:,:,i) = a(:,:,i+j) END DO
also produce a stack overflow. I fail to see what could possibly require the temporary copy in this case... Is it possible to circumvent that in this case?
I know that I can increase the stack size to fix the overflow issue, but performance is somewhat important and so i really would like to minimize unnecessary copying.