Fortran stack to static warning
GCC / Gfortran 10 and newer warn for arrays too big for the current stack settings.
Having arrays that exceed the stack limit may cause unexpected behavior - they should use allocate() instead in general.
Example of improper use of stack memory:
subroutine big_array()
real :: big2(1000,1000)
end subroutineWarning: Array ‘big2’ at (1) is larger than limit set by ‘-fmax-stack-var-size=’, moved from stack to static storage. This makes the procedure unsafe when called recursively, or concurrently from multiple threads. Consider using ‘-frecursive’, or increase the ‘-fmax-stack-var-size=’ limit, or change the code to use an ALLOCATABLE array. [-Wsurprising]
This is generally a true warning when one has assigned arrays as above too large for the stack. Simply making the procedure recursive may lead to segfaults.
Correct the example above like:
subroutine big_array()
real, allocatable :: big2(:,:)
allocate(big2(1000,1000))
end subroutineFor multiple arrays of the same shape do like:
subroutine big_array()
integer :: M=1000,N=2000,P=500
real, allocatable, dimension(:,:,:) :: w,x, y, z
allocate(w(M,N,P))
allocate(x,y,z, mold=x)
end subroutineIntel oneAPI caution
Intel oneAPI has the option -heap-arrays, but we recommend avoiding this option as it can cause memory leaks.