Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

TARGET

OpenMP* Fortran Compiler Directive: Creates a device data environment and executes the construct on that device.

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:

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.

IEEE floating-point halting, rounding modes, or exception flags set prior to the target region are undefined in the target region. Any that are set during execution of the target region become undefined upon exiting the target region.

Variables not declared in the target region, or specified in the TARGET directive, that are referenced in the target region must appear in a DECLARE TARGET directive.

The behavior is unspecified if a MAP clause list item is an array section derived from a variable with either the ALLOCATABLE or POINTER attribute and that variable is modified during the target region.

On entry to a target region, the following occurs:

  • If a mapped ALLOCATABLE variable has a status of ALLOCATED, it has the status ALLOCATED at the start of the region, and its shape and allocation status cannot be modified in the region.

  • If a mapped ALLOCATABLE variable has a status of UNALLOCATED, it has the allocation status UNALLOCATED at the start of the region, and upon exit from the region it must have a status of UNALLOCATED.

  • If a mapped POINTER variable has the status ASSOCIATED, it must be associated with the same target upon exit from the region.

  • If a mapped POINTER variable is DISASSOCIATED, its association at the start of the region is DISASSOCIATED, and it must have a DISASSOCIATED status at the end of the region.

In a target region, the association status of a procedure pointer is undefined unless it is used as the only argument to the ASSOCIATED function, in a pointer assignment statement, or in an indirect procedure call.

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 both a DEVICE_TYPE clause and an IF clause appear, the expression of the IF clause must evaluate to true. If a DEVICE_TYPE(NOHOST) clause and a DEVICE clause appear, the specified device must be a non-host device. If a DEVICE_TYPE (HOST) and a DEVICE clause appear, the specified device must be a host device.

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.