SHARED
Purpose
All sections use the same copy of the variables and common blocks you specify in data_scope_entity_list.
The SHARED clause specifies variables that must be available to all threads. If you specify a variable as SHARED, you are stating that all threads can safely share a single copy of the variable.
Syntax
- data_scope_entity
-
- named_variable
- is a named variable that is accessible in the directive construct
- common_block_name
- is a common block name that is accessible in the directive construct
Rules
A variable in the SHARED clause
must not be either:
- A pointee
- A runtime size array, which can be an assumed-shape array, an allocatable array, an array pointer, or an explicitly array with runtime bounds
- A THREADLOCAL common block.
- A THREADPRIVATE common block or its members.
- A THREADPRIVATE variable.
If a SHARED variable, a subobject
of a SHARED variable, or an object associated
with a SHARED variable or subobject of a SHARED variable
appears as an actual argument in a reference to a non-intrinsic procedure
and:
- The actual argument is an array section with a vector subscript; or
- The actual argument is
- An array section,
- An assumed-shape array, or,
- A pointer array
Example for OpenMP
In the following example,
the procedure reference with an array section actual argument is required
to be synchronized with references to the dummy argument by placing
the procedure reference in a critical section, because the associated
dummy argument is an explicit-shape array.
INTEGER :: abc(10)
i = 2
j = 5
!$OMP PARALLEL DEFAULT(NONE), SHARED(abc, i, j)
!$OMP CRITICAL
! Actual argument is an array section.
! The procedure reference must be in a critical section.
CALL sub1(abc(i: j))
!$OMP END CRITICAL
!$OMP END PARALLEL
CONTAINS
SUBROUTINE sub1(arr)
INTEGER:: arr(1: 4)
DO i = 1, 4
arr(i) = i
END DO
END SUBROUTINE
END



