Intel® Fortran Compiler 17.0 Developer Guide and Reference

TASKLOOP

OpenMP* Fortran Compiler Directive: Specifies that the iterations of one or more associated DO loops should be executed in parallel using OpenMP* tasks. The iterations are distributed across tasks that are created by the construct and scheduled to be executed.

Syntax

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

   do-loop

[!$OMP END TASKLOOP]

clause

Is one of the following:

  • COLLAPSE (n)

  • DEFAULT (PRIVATE | FIRSTPRIVATE | SHARED | NONE)

  • FINAL (scalar-logical-expression)

  • FIRSTPRIVATE (list)
  • GRAINSIZE (grain-size)

    Specifies that the number of logical loop iterations assigned to each created task is greater than or equal to the minimum of the value of the grain-size positive integer expression and the number of logical loop iterations, but less than two times the value of the grain-size expression.

    At most one GRAINSIZE clause can appear in a TASKLOOP directive.

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

    If the scalar-logical-expression evaluates to false, undeferred tasks are generated. If a variable appears in the IF clause expression, it causes an implicit reference to the variable in all enclosing constructs.

    At most one IF clause can appear in a TASKLOOP directive.

  • LASTPRIVATE (list)

  • MERGEABLE

  • NOGROUP

    Specifies that no implicit taskgroup region is created.

  • NUM_TASKS (num-tasks)

    Causes the TASKLOOP construct to create as many tasks as the minimum of the num-tasks positive scalar integer expression and the number of logical loop iterations. Each task must have at least one logical loop iteration.

  • PRIORITY (priority-value)

  • PRIVATE (list)
  • SHARED (list)
  • UNTIED

do-loop

Is one or more DO iterations (DO loops). The DO iteration cannot be a DO WHILE or a DO loop without loop control. The DO loop iteration variable must be of type integer.

If an END TASKLOOP directive follows a DO construct in which several loop statements share a DO termination statement, then the directive can only be specified for the outermost of these DO statements. The TASKLOOP construct inherits the restrictions of the loop construct.

If any of the loop iteration variables would otherwise be shared, they are implicitly made private for the loop-iteration tasks created by the TASKLOOP construct. Unless the loop iteration variables are specified in a LASTPRIVATE clause on the TASKLOOP construct, their values after the loop are unspecified.

You cannot branch out of a DO loop associated with a TASKLOOP directive.

If you do not specify GRAINSIZE or NUM_TASKS, the number of loop tasks created and the number of logical loop iterations assigned to these tasks is implementation defined. The GRAINSIZE clause and NUM_TASKS clauses are mutually exclusive; they cannot appear in the same TASKLOOP directive.

The binding thread set of the TASKLOOP region is the current team. A TASKLOOP region binds to the innermost enclosing parallel region.

By default, the TASKLOOP construct executes as if it was enclosed in a TASKLOOP construct with no statements or directives outside of the TASKLOOP construct. This means that unless NOGROUP is specified, the TASKLOOP construct creates an implicit taskgroup.

When a thread encounters a TASKLOOP construct, the construct partitions the associated loops into tasks for parallel execution of the loop iterations. The data environment of the created tasks is created according to the clauses specified in the TASKLOOP construct, any data environment ICVs, and any defaults that apply. The order of the creation of the loop tasks is unspecified. Programs that rely on any execution order of the logical loop iterations are non-conforming.

If used, the END TASKLOOP directive must appear immediately after the end of the loop. If you do not specify an END TASKLOOP directive, an END TASKLOOP directive is assumed at the end of the do-loop.

The following restrictions also apply:

See Also