# MASKED

OpenMP* Fortran Compiler Directive: Specifies a block of code to be executed by the primary thread of the 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 (scalar-integer-expression). The clause is optional and it can appear only 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 scalar-integer-expression specified in the FILTER clause. Otherwise, the thread skips the block of code and continues execution after the MASKED construct. Note that the scalar-integer-expression can contain variables, so the value of the expression 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)
      !$OMP END PARALLEL

Parent topic: M to N

## See Also

OpenMP Fortran Compiler Directives
Syntax Rules for Compiler Directives
Parallel Processing Model for information about Binding Sets