Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

ALLOCATE Directive

OpenMP* Fortran Compiler Directive: Specifies memory allocators to use for object allocation and deallocation. This feature is only available for ifx.

Syntax

!$OMP ALLOCATE (list) [clause [[,] clause]...]

-or-

!$OMP ALLOCATE [(list)] [clause [[,] clause]...]

[!$OMP ALLOCATE (list) [clause [[,] clause]...]

[...]]

ALLOCATE statement

list

Is a comma separated list of variables or named common blocks. A common block name must be enclosed in slashes (/ /).

clause

Is one of the following:

  • ALLOCATOR (allocator)

    allocator is an integer expression with a kind type of omp_allocator_handle_kind.

    If the ALLOCATOR clause is not specified, the list items in that directive will be allocated using the allocator specified by the def-allocator-var internal control variable (ICV).

    At most one ALLOCATOR clause is permitted in the ALLOCATE directive.

  • ALIGN (alignment)

    alignment is a positive integer scalar expression with a value that is a positive power of two.

    Each list item is allocated with a byte alignment of at least the maximum of the following:

    1. The required alignment specified by Fortran

    2. The alignment trait of the specified allocator

    3. The alignment value specified by the ALIGN clause

    If the ALIGN clause is not specified, each list item is allocated with a byte alignment of at least the maximum of the following:

    1. The required alignment specified by Fortran

    2. The alignment trait of the specified allocator

    At most one ALIGN clause is permitted in the ALLOCATE directive.

The first form of the directive is not associated with an ALLOCATE statement. It is a declarative directive and must appear in the specification part where the list items are declared, and after all declarations of the list items. The storage for each list item will be allocated by the specified memory allocator and deallocated by the same memory allocator when the list item goes out of scope.

The list items in a declarative ALLOCATE directive must not have the POINTER or ALLOCATABLE attribute. If a list item has the SAVE attribute (implicitly or explicitly), is a common block name, or is declared in the scope of a module or submodule, then the specified allocator must be one of the pre-defined memory allocators. The list items in a declarative ALLOCATE directive cannot be an array element, a structure component, or a variable in a common block. The declaration of all list items must be in the same scope as the declarative ALLOCATE directive and must precede the ALLOCATE directive.

A list item can appear once in a declarative ALLOCATE directive and it can appear in only one declarative ALLOCATE directive.

The second form of the ALLOCATE directive is associated with an ALLOCATE statement and can appear in the executable statement part of a subprogram after the first executable statement or OpenMP* construct. It associates an allocator with each allocate item in the associated ALLOCATE statement. If an ALLOCATE directive with no list items appears, all the allocate list objects in the ALLOCATE statement that are not listed in an ALLOCATE directive associated with the same ALLOCATE statement, are allocated by the allocator specified in the ALLOCATE directive with no list items specified. Multiple ALLOCATE directives with list items can be specified for an ALLOCATE statement.

A list item can not appear in more than one ALLOCATE directive associated with a given ALLOCATE statement, or appear more than once in the same directive. Each list item must have the ALLOCATABLE or POINTER attribute. A list item can be a POINTER or ALLOCATABLE component of a derived type. A list item cannot be an associate name.

If an object appears as a list item of an ALLOCATE directive, it must also appear in the allocation list of the associated ALLOCATE statement. When an object is deallocated, it is deallocated using the same allocator used to allocate it. If an object is deallocated and reallocated during intrinsic assignment, the same allocator is used for the deallocation and reallocation; otherwise, the allocator specified for a list item is used to allocate the list item only in the ALLOCATE statement associated with the ALLOCATE directive.

If multiple ALLOCATE directives are associated with an ALLOCATE statement, only one ALLOCATE directive can appear with no list items.

An ALLOCATOR must be specified in ALLOCATE directives that appear in a TARGET region, unless a REQUIRES directive with the DYNAMIC_ALLOCATORS clause is specified in the same compilation unit.

When a list item goes out of scope, if it has not been deallocated, it is automatically deallocated with the same allocator that allocated it.