is it safe to allocate an already allocated array?

Most compilers I’ve tried (intel, gnu, pathscale, cray) will return an error when attempting to allocate an array that was already allocated. For example:

      program test2
      integer, allocatable, dimension(:) :: foo
      integer ierr
      allocate(foo(100), STAT=ierr)
      write(*,*) 'status = ', ierr
      allocate(foo(100), STAT=ierr)
      write(*,*) 'status = ', ierr
      end program test2

But PGI seems to handle this fine (even when a different size is used).

Is it safe to do this?

Hi generic_user_nam,

This is a known issue (TPR#17662) where we should be returning an error code. Right now “foo” get allocated again so this has code will cause a memory leak. It’s not a catastrophic error but an error no the less.

  • Mat