# IF Clause

Parallel Directive Clause: Specifies a conditional expression. If the expression evaluates to .FALSE., the construct is not executed.

## Syntax

IF ([directive-name-modifier:] scalar-logical-expression)

directive-name-modifier | Names the associated construct that the IF clause applies to. Currently, you can specify one of the following associated constructs (directives): PARALLEL, SIMD, TARGET DATA, TARGET, TARGET UPDATE, TARGET ENTER DATA, TARGET EXIT DATA, TASK, or TASKLOOP. These directives are only available on Linux* systems: TARGET DATA, TARGET, TARGET UPDATE, TARGET ENTER DATA, TARGET EXIT DATA.
scalar-logical-expression | Must be a scalar logical expression that evaluates to .TRUE. or .FALSE..

At most one IF clause can appear in a non-combined directive. In combined directives, IF clauses with different directive-name-modifiers can occur, at most one for each constituent directive making up the combined directive where IF is allowed.

## Description

The effect of the IF clause depends on the construct to which it is applied:

- For combined or composite constructs, the IF clause only applies to the semantics of the construct named in the directive-name-modifier if one is specified.

- If no directive-name-modifier is specified for a combined or composite construct then the IF clause applies to all constructs to which an IF clause can apply.

The following are additional rules that apply to specific OpenMP Fortran directives:

- For the CANCEL OpenMP* Fortran directive, if scalar-logical-expression evaluates to false, the construct does not request cancellation. Note that directive-name-modifier cannot specify CANCEL.

- For the PARALLEL OpenMP Fortran directive:

  - The enclosed code section is executed in parallel only if scalar-logical-expression evaluates to .TRUE.. Otherwise, the parallel region is serialized. If this clause is not used, the region is executed as if an IF(.TRUE.) clause were specified.

  - This clause is evaluated in the context outside of this construct.

- For the SIMD OpenMP Fortran directive, if scalar-logical-expression evaluates to .FALSE., the number of iterations to be executed concurrently is one.

- For the TARGET OpenMP Fortran directive, if scalar-logical-expression evaluates to .FALSE., the target region is not executed by the device. It is executed by the encountering task.

- For the TARGET DATA OpenMP Fortran directive, if scalar-logical-expression evaluates to .FALSE., the new device data environment is not created.

- For the TARGET UPDATE OpenMP Fortran directive, if scalar-logical-expression evaluates to .FALSE., the TARGET UPDATE directive is ignored.

- For the TASK OpenMP Fortran directive:

  - If scalar-logical-expression evaluates to .FALSE., the encountering thread must suspend the current task region and begin execution of the generated task immediately. The suspended task region will not be resumed until the generated task is completed.

  - This clause is evaluated in the context outside of this construct.

Parent topic: H to I