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

ID 767251
Date 7/13/2023
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:

  • 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.

  • 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.

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. This form of the directive has been deprecated in OpenMP 5.2 and replaced by the ALLOCATORS construct. It associates an allocator with each allocate item in the associated ALLOCATE statement. The following are other rules for this form:

  • 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.

  • An allocate object in an ALLOCATE statement associated with an ALLOCATE directive can be associated with only one allocator, either explicitly (as a list item) or implicitly (if no list appears in an ALLOCATE directive) for that 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; therefore, it cannot be a common block name enclosed in slashes. 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 an allocate object in an ALLOCATE statement associated with an OpenMP ALLOCATE directive does not appear as a list item in the directive, the allocate object is ALLOCATED as if it appeared in a Fortran ALLOCATE statement that was not associated with an OpenMP 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.