# FLUSH Directive

OpenMP* Fortran Compiler Directive: Identifies synchronization points at which the threads in a team must provide a consistent view of memory.

!$OMP FLUSH [(list)]

list | Is the name of one or more variables to be flushed. Names must be separated by commas.

The binding thread set for a FLUSH construct is the encountering thread.

The FLUSH directive must appear at the precise point in the code at which the synchronization is required. To avoid flushing all variables, specify a list.

Thread-visible variables are written back to memory at the point at which this directive appears. Modifications to thread-visible variables are visible to all threads after this point. Subsequent reads of thread-visible variables fetch the latest copy of the data.

Thread-visible variables include the following data items:

- Globally visible variables (common blocks and modules)

- Local variables that do not have the SAVE attribute but have had their address taken and saved or have had their address passed to another subprogram

- Local variables that do not have the SAVE attribute that are declared shared in a parallel region within the subprogram

- Dummy arguments

- All pointer dereferences

The FLUSH directive is implied for the following directives (unless the NOWAIT keyword is used):

- ATOMIC and END ATOMIC

- BARRIER

- CRITICAL and END CRITICAL

- END DO

- END PARALLEL

- END SECTIONS

- END SINGLE

- END WORKSHARE

- ORDERED and END ORDERED

- PARALLEL and END PARALLEL

- PARALLEL DO and END PARALLEL DO

- PARALLEL SECTIONS and END PARALLEL SECTIONS

- TARGET

- TARGET DATA

- TARGET ENTER DATA on entry

- TARGET EXIT DATA on exit

- TARGET UPDATE on entry if TO is present and on exit if FROM is present

These directives are only available on Linux* systems: TARGET, TARGET DATA, TARGET ENTER DATA, TARGET EXIT DATA, TARGET UPDATE.

## Example

The following example uses the FLUSH directive for point-to-point synchronization between pairs of threads:

      !$OMP PARALLEL DEFAULT(PRIVATE) SHARED(ISYNC)
            IAM = OMP_GET_THREAD_NUM( )
            ISYNC(IAM) = 0
      !$OMP BARRIER
            CALL WORK( )
      C I AM DONE WITH MY WORK, SYNCHRONIZE WITH MY NEIGHBOR
            ISYNC(IAM) = 1
      !$OMP FLUSH(ISYNC)
      C WAIT TILL NEIGHBOR IS DONE
            DO WHILE (ISYNC(NEIGH) .EQ. 0)
      !$OMP FLUSH(ISYNC)
            END DO
      !$OMP END PARALLEL

Parent topic: E to F

## See Also

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