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

TARGET

OpenMP* Fortran Compiler Directive: Creates a device data environment and executes the construct on that device. This feature is only available for ifx.

Syntax

!$OMP TARGET [clause[[,] clause]... ]

   loosely-structured-block

!$OMP END TARGET

-or-

!$OMP TARGET [clause[[,] clause]... ]

   strictly-structured-block

!$OMP END TARGET

clause

Is one or more of the following:

  • ALLOCATE ([allocator :] list)

  • DEFAULTMAP (implicit-behavior:SCALAR)

    Causes a scalar variable to be treated as if it appeared in a MAP clause with the map-type specified by implicit-behavior.

    The implicit-behavior can be ALLOC, TO, FROM, TOFROM, FIRSTPRIVATE, NONE, PRESENT, or DEFAULT. See MAP clause for a description of the ALLOC, TO, FROM, and TOFROM map types.

    If the implicit-behavior is DEFAULT, the clause has no effect for scalar variables.

    If the implicit-behavior is PRESENT, each scalar variable behaves as if it appeared in a MAP clause with a map-type of ALLOC and a map-type-modifier of PRESENT.

    If the implicit-behavior is NONE, a variable referenced in the TARGET construct that does not have a predetermined data scoping attribute must have appeared in a TO clause of a DECLARE TARGET directive, or it must appear in one of the following:

    • A data mapping attribute clause

    • A data scoping attribute clause, including a data scoping attribute clause of a combined construct where TARGET is one of the constructs of the combined construct

    If this clause is not specified, a scalar variable is not mapped; instead it has an implicit attribute of FIRSTPRIVATE. At most one DEFAULTMAP clause can appear in the directive.

  • DEPEND (dependence-type : list)

  • DEVICE (integer-expression)

  • FIRSTPRIVATE (list)

  • HAS_DEVICE_ADDR (list)

    Specifies variables that have device addresses and can be directly accessed by the target device. Each list item must have valid device address for the device data environment. You can specify an array section as a list item.

    If you access a list item whose device address is on a device other than the device that executes the TARGET construct, it causes undefined behavior.

    A list item that appears in a HAS_DEVICE_ADDR clause cannot also appear in an IS_DEVICE_PTR clause in the same TARGET directive.

  • IF ([TARGET:] scalar-logical-expression)

  • IN_REDUCTION (reduction-identifier : list)

  • IS_DEVICE_PTR (list)

  • MAP ([[map-type-modifier[,]] map-type: ] list)

  • NOWAIT

  • PRIVATE (list)

  • SUBDEVICE ([integer-constant ,] integer-expression [ : integer-expression [ : integer-expression] ] )

loosely-structured-block

Is a structured block (section) of statements or constructs. You cannot branch into or out of the block.

strictly-structured-block

Is a Fortran BLOCK construct. You cannot branch into or out of the BLOCK construct.

The binding task for a TARGET construct is the encountering task. The target region binds to the enclosing parallel or task region.

This construct provides a superset of the functionality provided by the TARGET DATA construct, except for the clauses USE_DEVICE_PTR and USE_DEVICE_ADDR.

A list item in an IS_DEVICE_PTR clause that has a type other than C_PTR is the same as if it was a list item in a HAS_DEVICE_ADDR clause. List items specified in a IS_DEVICE_PTR or HAS_DEVICE_ADDR clause cannot appear in a data sharing attribute clause in the same TARGET directive. Note that the OpenMP* Specification has deprecated non-C_PTR type list items in an IS_DEVICE_PTR clause.

The TARGET construct also specifies that the region is executed by a device. The encountering task waits for the device to complete the target region at the end of the construct.

If a TARGET, TARGET DATA, or TARGET UPDATE construct appears within an OMP TARGET region, the construct is ignored.

Execution of the target task may be deferred if the NOWAIT clause is specified; if it is not specified, the target task is an included task.

If a variable or part of a variable does not appear in an IN_REDUCTION clause and is mapped by the TARGET construct, the variable's default data-sharing attribute is shared in the data environment of the target task.

A variable that appears as a list item in an IN_REDUCTION clause is implicitly mapped as if it appears in a MAP clause with a map-type of TOFROM, and a map-type-modifier of ALWAYS.

A variable that is fully or partially mapped by the TARGET construct and that is not a list item in an IN_REDUCTION clause within the construct has a default data-sharing attribute of SHARED in the target tasks data environment.

If a variable appears in a REDUCTION or LASTPRIVATE clause in a combined TARGET construct, it is treated as if it had appeared in a MAP clause with a map-type of TOFROM for REDUCTION and a map-type of FROM for LASTPRIVATE:

! SUM is treated as MAP (TOFROM)
!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO REDUCTION(+:SUM)

! X is treated as MAP (FROM)
!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO LASTPRIVATE(X)

A non-scalar variable referenced in a TARGET region and not explicitly mapped is implicitly treated as MAP (TOFROM):

INTEGER A(10)
!$OMP TARGET
  A(5) = 5          ! A is treated as MAP (TOFROM)
!$OMP  END TARGET

If only a subsection of a non-scalar variable has been mapped in an outer target region, and that variable is then mapped implicitly inside a nested target region, that variable should not access memory outside of the mapped subsection of the variable.