Intel® Fortran Compiler 17.0 Developer Guide and Reference

heap-arrays

Puts automatic arrays and arrays created for temporary computations on the heap instead of the stack.

Syntax

Linux and macOS:

-heap-arrays [size]

-no-heap-arrays

Windows:

/heap-arrays[:size]

/heap-arrays-

Arguments

size

Is an integer value representing the size of the arrays in kilobytes. Arrays smaller than size are put on the stack.

Default

-no-heap-arrays or /heap-arrays-

The compiler puts automatic arrays and temporary arrays in the stack storage area.

Description

This option puts automatic arrays and arrays created for temporary computations on the heap instead of the stack.

When this option 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 always puts the automatic array on the heap.

If size is specified, 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:

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.

IDE Equivalent

Visual Studio: Optimization > Heap Arrays

Eclipse: None

Xcode: Data > Allocate Automatics to the Heap

Alternate Options

None

Example

In Fortran, an automatic array gets its size from a run-time expression. For example:


RECURSIVE SUBROUTINE F( N )
INTEGER :: N
REAL :: X ( N )     ! an automatic array
REAL :: Y ( 1000 )  ! an explicit-shape local array on the stack 

Array X in the example above is affected by the heap-array option; array Y is not.

Temporary arrays are often created before making a routine call, or when an array operation detects overlap. For example:


integer a(10000)
a(2:) = a(1:ubound(a,dim=1)-1)

In this case, 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.

If you specify the heap-arrays option, 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, 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.