pgf90 size intrinsic wrong output for large arrays

Hi,

My system is “pgf90 6.1-6 64-bit target on x86-64 Linux”. The following code produces the wrong result. What am I missing?

program mem
  integer(8), parameter :: n=3000000000_8
  integer(8)            :: i, sz
  character             :: y(n)

  sz = size(y)
  print*, n, sz
  do i=1,n
     y(i) = 'c'
  end do
  print*, y(n)
  stop
end program mem



$ pgf90 -mcmodel=medium samp.f90
$ ./a.out
               3000000000              -1294967296
 c
FORTRAN STOP

I seem to recall documentation saying that by using -Mlarge_arrays, which is implicit with -mcmodel=medium, array intrinsics output INTEGER*8 quantities.

Ed

A similar issue was addressed in a different post “Large array sizes not allowed on 64-bit platforms”. The solution (workaround?) seems to be to use -i8.

$ pgf90 -mcmodel=medium -i8 samp.f90
$ ./a.out
               3000000000               3000000000
 c
FORTRAN STOP

Ed

Hi Ed,

The Fortran standard requires that lbound, size, and ubound return the default integer kind, which, even with -mcmodel=medium and -Mlarge_arrays, is INTEGER*4. Hence, to use these intrinsics with large arrays you need to change the default kind to 8 (i.e. -i8).

Although it hasn’t been added yet, we have a feature request in house to add a “-Mi8intrinsics” flag which would change the default integer kind only for intrinsics.

Thanks,
Mat