Visible to Intel only — GUID: GUID-EF182A4D-E7A7-48C1-8AF2-FD8816BFA731
Visible to Intel only — GUID: GUID-EF182A4D-E7A7-48C1-8AF2-FD8816BFA731
SCOPE
OpenMP* Fortran Compiler Directive: Specifies a block of code to be executed by all threads in a team; it may contain additional OpenMP constructs. This feature is only available for ifx.
!$OMP SCOPE [clause[[,] clause]... ]
loosely-structured-block
!$OMP END SCOPE [NOWAIT]
-or-
!$OMP SCOPE [clause[[,] clause]... ]
strictly-structured-block
!$OMP END SCOPE [NOWAIT]
clause |
Is one or more of the following: |
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 the SCOPE region is the current team.
The SCOPE region binds to the innermost parallel region in which it is enclosed. All threads of a team that execute the binding parallel region, and only those threads, execute the statements of the block. The block may contain additional OpenMP constructs.
If NOWAIT is not specified, the participating threads execute an implicit barrier at the end of the SCOPE block.
The following code performs a reduction on the array arr. Each thread produces a sum of the elements dispatched to it. The SCOPE directive is used to perform a reduction of each partial sum. The sum of the array, and the number of threads that participate, is printed.
SUBROUTINE sum_reduce (arr)
IMPLICIT NONE
REAL,DIMENSION(:) :: arr
REAL :: sum = 0.0, partial_sum = 0.0
INTEGER :: i, num_threads = 0
!$omp PARALLEL FIRSTPRIVATE (partial_sum), SHARED (num_threads, arr)
!$omp DO
DO i = 1, SIZE (arr)
partial_sum = partial_sum + arr(i)
END DO
!$omp END DO
!$omp SCOPE reduction (+ : sum, num_threads)
sum = sum + partial sum
num_threads = num_threads + 1
!$omp END SCOPE
!$omp END PARALLEL
PRINT *, "sum of arr = ", sum, " number of threads participating = ", num_threads
RETURN
END SUBROUTINE