Hi,
I'm experiencing strange behavior of the program while copying an array.
I made a simple test code to reproduce it.
program test integer :: ni, nj, nk integer, allocatable :: id(:) real*8, allocatable :: a(:,:,:), b(:,:,:) ni = 50 nj = 50 nk = 1 allocate(a(ni,nj,nk)) allocate(b(ni,nj,nk)) allocate(id(nk)) a = 1d0 do n = 1, nk id(n) = nk+1-n enddo call copy(a,b) print*, sum(a), sum(b) contains subroutine copy(aa,bb) real*8, intent(in) :: aa(ni,nj,nk) real*8, intent(out) :: bb(ni,nj,nk) do n = 1, nk bb(:,:,id(n)) = aa(:,:,n) enddo end subroutine copy end program test
I think the program should print out the sum value of 2500 for both array a and b.
However, the program prints out 2500 for array a, but 1250 for array b.
In this test, I used intel fortran compiler 2017 initial release.
Could you give me an advice for this problem?, or is there anything I'm doing wrong?
Thanks,