access violation on argument array copy

Hello.
I am getting failure in my program on copying array. I have written test that simulates call hierarchy of my program. It fails either. I am not sure, if it is is totally language-correct. But it doesn’t look wrong. The program fails with access violation error on call to s2 subroutine, when array copy performed. What is wrong? The fortran source or pgi generated machine code?

tested on pvf 13.10 on win 7.

subroutine s2(A)
  real :: A(:)
  print*, 'size=', size(A)
  end

subroutine s1(P1)
  real, pointer :: P1(:,:,:,:)
  
  print*, 'size=', size(P1(1,1,:,1))
  call s2(P1(1,1,:,1))
  end
  
program pr
  real, allocatable, target:: R(:,:,:,:)
  real, pointer :: P(:,:,:,:)
  
  allocate(R(3,4,5,6))
  P => R
  call s1(P)
  
  end

And I also want to ask. If there any limit for size of array, that is passed as subroutine argument?

Hi Senya,

You need to add an interface otherwise F77 calling convensions are used. The easiest thing to do is put these routines into a module which implicitly creates an interface.

% cat test2.f90

module foo

contains
subroutine s2(A)
   real :: A(:)
   print*, 'size=', size(A)
   end subroutine

 subroutine s1(P1)
   real, pointer :: P1(:,:,:,:)

   print*, 'size=', size(P1(1,1,:,1))
   call s2(P1(:,1,1,1))
   end subroutine
end module foo

 program pr
   use foo
   real, allocatable, target:: R(:,:,:,:)
   real, pointer :: P(:,:,:,:)

   allocate(R(3,4,5,6))
   P => R
   call s1(P)

   end



And I also want to ask. If there any limit for size of array, that is passed as subroutine argument?

If it’s over 2GB, add the “-Mlarge_arrays” compilation flag for allocatable arrays and/or “-mcmodel=medium” if the array is static.

  • Mat

Thanks. Your answers helped me.

If there any limit for size of array, that is passed as subroutine argument?








\

GuL

Hi GuL,

If there any limit for size of array, that is passed as subroutine argument?

Your limit will be the amount of global memory you have available on the device. If any single allocatable array is larger than 2GB, then you’ll need to add “-Mlarge_arrays”. Also, you’ll need to use INTEGER(8) index variables if the number of elements exceeds 2 billion.

  • Mat