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

ID 767251
Date 3/22/2024
Public

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

Document Table of Contents

MASKED

OpenMP* Fortran Compiler Directive: Specifies a structured block to be executed by a subset of the threads of the current team. This feature is only available for ifx.

Syntax

!$OMP MASKED [clause]

   loosely-structured-block

!$OMP END MASKED

-or-

!$OMP MASKED [clause]

   strictly-structured-block

[!$OMP END MASKED]

clause

Is FILTER (thread_num), where thread_num is a scalar integer expression. The clause is optional and may appear at most once.

A thread that encounters a MASKED construct with a FILTER clause executes the block of the construct if its thread number matches the value of thread_num specified in the FILTER clause. Otherwise, the thread skips the block of code and continues execution after the MASKED construct. thread_num can be a variable expression, so the value of thread_num can vary across threads.

If the FILTER clause is not present, it is as if FILTER (0) has been specified. In this case, only the primary thread executes the enclosed block.

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 thread set for a MASKED construct is the current team. A master region binds to the innermost enclosing parallel region.

There is no implied barrier, either on entry to or exit from the masked section.

Examples

The following example forces the primary thread to execute the routines OUTPUT and INPUT:

  !$OMP PARALLEL DEFAULT(SHARED)
        CALL WORK(X)
  !$OMP MASKED									
  ! The above line is equivalent to MASKED FILTER(0)
        CALL OUTPUT(X)
        CALL INPUT(Y)
  !$OMP END MASKED
        CALL WORK(Y)
  !$OMP END PARALLEL

In the following example, only the even numbered threads execute INPUT and OUTPUT:

  !$OMP PARALLEL 
    BLOCK
      INTEGER :: me = omp_get_thread_num
        CALL WORK(X)
  !$OMP MASKED FILTER (me + mod (me,2))
        CALL OUTPUT(X)
        CALL INPUT(Y)
  !$OMP END MASKED
        CALL WORK(Y)
    END BLOCK
  !$OMP END PARALLEL