Visible to Intel only — GUID: GUID-AD753AD3-59A4-4E86-98A1-596CFD029814
Visible to Intel only — GUID: GUID-AD753AD3-59A4-4E86-98A1-596CFD029814
heap-arrays
Puts automatic arrays and arrays created for temporary computations on the heap instead of the stack.
Linux: |
-heap-arrays [size] -no-heap-arrays |
macOS: |
-heap-arrays [size] -no-heap-arrays |
Windows: |
/heap-arrays[:size] /heap-arrays- |
size |
Is an integer value representing the size of the arrays in kilobytes. Arrays smaller than size are put on the stack. |
-no-heap-arrays or /heap-arrays- |
The compiler puts automatic arrays and temporary arrays in the stack storage area. |
This option puts automatic arrays and arrays created for temporary computations on the heap instead of the stack.
If size is specified:
Automatic (temporary) arrays that have a compile-time size greater than the value specified for size are put on the heap, rather than on the stack. If the compiler cannot determine the size at compile time, it puts the automatic array on the heap.
The value is only used when the total size of the temporary array or automatic array can be determined at compile time, using compile-time constants.
Any arrays known at compile-time to be larger than size are allocated on the heap instead of the stack. For example, if 10 is specified for size:
All automatic and temporary arrays equal to or larger than 10 KB are put on the heap.
All automatic and temporary arrays smaller than 10 KB are put on the stack.
If size is omitted, and the size of the temporary array or automatic array cannot be determined at compile time, it is assumed that the total size is greater than size and the array is allocated on the heap.
Linux and macOS
You can use the shell command unlimit to increase the size of the run-time stack before execution.
Windows
You can use compiler option /F to tell the linker to increase the size of the run-time stack to allow for large objects on the stack.
Visual Studio: Optimization > Heap Arrays
None
Example
In Fortran, an automatic array gets its size from a run-time expression. In the following example, array X is affected by the heap-array option; array Y is not:
RECURSIVE SUBROUTINE F( N )
INTEGER :: N
REAL :: X ( N ) ! an automatic array
REAL :: Y ( 1000 ) ! an explicit-shape local array on the stack
Temporary arrays are often created before making a routine call, or when an array operation detects overlap. In the following example, the array assignment uses a temporary intermediate array because there is clearly an overlap between the right hand side and the left hand side of the assignment:
integer a(10000)
a(2:) = a(1:ubound(a,dim=1)-1)
If you specify the heap-arrays option and omit size, the compiler creates the temporary array on the heap.
If you specify the heap-arrays option with size 50, the compiler creates the temporary array on the stack. This is because the size of the temporary intermediate array can be determined at compile time (40Kb), and it's size is less than the size value.
In the following example, a contiguous array is created from the array slice declaration and passed on:
call somesub(a(1:10000:2))
If you specify the heap-arrays option and omit size, the compiler creates the temporary array on the heap.
If you specify the heap-arrays option with size 25, the compiler creates the temporary array on the stack. This is because the size of the temporary intermediate array at compile time is only 20Kb.