Prev: question on ** operator
Next: existence of directory
From: JimBo on 17 Jul 2010 15:12 The following program works using intel fortran. But what bit of the 2d array 'arr' gets used in each in each invocation to fill? program sections real, allocatable, dimension(:,:),target :: arr real,pointer,dimension(:,:) :: arrptr allocate(arr(900,900)) arr = 0 arrptr=>arr(1:480,1:480) call fill(480,480,arrptr) call lookagain(480,480,arrptr) ! try it again this time 'arr' does not have correct view ! but it ok in lookagain anyway arr = 0 call fill(480,480,arr) call lookagain(480,480,arr) contains subroutine lookagain(nx,ny,arr) integer nx,ny real arr(nx,ny) do i = 1, 480 do j=1,480 if(arr(i,j) /= i+j)print *,'not ok here ',i,j enddo enddo end subroutine lookagain subroutine fill(nx,ny,arr) integer nx,ny real arr(nx,ny) do i = 1, 480 do j=1,480 arr(i,j) = i+j enddo enddo end subroutine fill end program sections
From: glen herrmannsfeldt on 17 Jul 2010 15:29 JimBo <user(a)compgroups.net/> wrote: > The following program works using intel fortran. > But what bit of the 2d array 'arr' gets used in each \ > in each invocation to fill? I believe it works as you say, and may go through a lot of work, including copying array sections back and forth, to make that true. > program sections > real, allocatable, dimension(:,:),target :: arr > real,pointer,dimension(:,:) :: arrptr > allocate(arr(900,900)) > > arr = 0 > arrptr=>arr(1:480,1:480) > call fill(480,480,arrptr) > call lookagain(480,480,arrptr) > ! try it again this time 'arr' does not have correct view > ! but it ok in lookagain anyway > arr = 0 > call fill(480,480,arr) > call lookagain(480,480,arr) > contains > > subroutine lookagain(nx,ny,arr) > integer nx,ny > real arr(nx,ny) > do i = 1, 480 > do j=1,480 > if(arr(i,j) /= i+j)print *,'not ok here ',i,j > enddo > enddo > end subroutine lookagain > subroutine fill(nx,ny,arr) > integer nx,ny > real arr(nx,ny) > do i = 1, 480 > do j=1,480 > arr(i,j) = i+j > enddo > enddo > end subroutine fill > > end program sections > > > >
From: Jimbo on 17 Jul 2010 15:46 Fill declares arr to be explicit shaped array. This occurs a lot when you interface f77 routines into a new f90 program. The f90 program allocates arrays. In the first call to fill/lookagain where a pointer is passed temp's get created. But in the second call no temps get created. This is the info provided by ifort -check all.
|
Pages: 1 Prev: question on ** operator Next: existence of directory |