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

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

TASKYIELD

OpenMP* Fortran Compiler Directive: Specifies that the current task can be suspended at this point in favor of execution of a different task.

!$OMP TASKYIELD

A taskyield region binds to the current task region. The binding thread set of the taskyield region is the current team.

Because the TASKYIELD construct is a stand-alone directive, there are some restrictions on its placement within a program:

  • The TASKYIELD directive can only be placed at a point where a Fortran executable statement is allowed.

  • The TASKYIELD directive cannot be used as the action statement in an IF statement or as the executable statement following a label if the label is referenced in the program.

The TASKYIELD construct includes an explicit task scheduling point in the current task region.

Example

The following example shows use of the TASKYIELD directive. It is non-conforming, because the FLUSH, BARRIER, TASKWAIT, and TASKYIELD directives are stand-alone directives and cannot be the action statement of an IF statement or a labeled branch target.

SUBROUTINE NONCONFORMING_STANDALONE()
   INTEGER A
   A = 1
   ! the FLUSH directive must not be the action statement in an IF statement
   !
   IF (A .NE. 0) !$OMP FLUSH(A)

   ! the BARRIER directive must not be the action statement in an IF statement
   !
   IF (A .NE. 0) !$OMP BARRIER

   ! the TASKWAIT directive must not be the action statement in an IF statement
   !
   IF (A .NE. 0) !$OMP TASKWAIT
    
   ! the TASKYIELD directive must not be the action statement in an IF statement
   !
   IF (A .NE. 0) !$OMP TASKYIELD

   GOTO 100
   
   ! the FLUSH directive must not be a labeled branch target statement
   !
   100 !$OMP FLUSH(A)
   GOTO 200

   ! the BARRIER directive must not be a labeled branch target statement
   !
   200 !$OMP BARRIER
   GOTO 300

   ! the TASKWAIT directive must not be a labeled branch target statement
   !
   300 !$OMP TASKWAIT
   GOTO 400

   ! the TASKYIELD directive must not be a labeled branch target statement
   !
   400 !$OMP TASKYIELD
END SUBROUTINE

The following version of the above example is conforming because the FLUSH, BARRIER, TASKWAIT, and TASKYIELD directives are enclosed in a compound statement.

SUBROUTINE CONFORMING_STANDALONE ()
   INTEGER N
   N = 1
   IF (N .NE. 0) THEN
       !$OMP FLUSH(N)
   ENDIF
   IF (N .NE. 0) THEN
       !$OMP BARRIER
   ENDIF
   IF (N .NE. 0) THEN
       !$OMP TASKWAIT
   ENDIF
   IF (N .NE. 0) THEN
       !$OMP TASKYIELD
   ENDIF
   GOTO 100
   100 CONTINUE
   !$OMP FLUSH(N)
   GOTO 200
   200 CONTINUE
   !$OMP BARRIER
   GOTO 300
   300 CONTINUE
   !$OMP TASKWAIT
   GOTO 400
   400 CONTINUE
   !$OMP TASKYIELD
END SUBROUTINE