Technical data
#pragma Directives [3]
For tasked loops, array variables that are sequentially indexed by the loop control
variable and modified inside the loop are often shared. Because each processor is
working with a different array element, there is no chance for two processors to
attempt to modify the same array element at the same time.
Conversely, scalar variables and array variables that are not sequentially indexed
by the loop control variable, but which are modified inside the loop, are usually
not shared. This is because their value at any given time, as well as their final
value, would then be indeterminate.
!
Caution:
• Modifying a scalar shared variable must be done inside a guarded region if
there is a possibility that two processors will attempt to update the variable at
the same time. This restriction applies to the increment (++) and decrement
(--) operators as well as the assignment operators.
• When modifying a shared bitfield or character, you must remember that
many bitfields and/or characters may be packed into a single word, and that
modifying one part of the word must be done with the assurance that no
other processor will be modifying any part of that word at the same time.
Some ways to avoid this problem include using a chunksize argument
that is a multiple of 8 for tasked loops that sequentially access an array of
characters, or placing the offending operation in a guarded region. See
Section 3.8.7, page 74, for a description of guarded regions and the guard
and endguard directives.
3.8.13.1.3 Performance Issues
Many times a variable can have shared or value context without affecting the
program results. For example, variables that are referenced but never modified in
the parallel region can usually be placed in either the shared or value context
lists. In such cases, run-time performance can be improved by adhering to the
following rules.
To achieve best performance:
• Place globally declared variables in the shared list.
• Place locally declared arrays, structures, and unions in the shared list.
• Place all other locally declared variables in the value list.
Putting stack variables (auto, register, and taskcommon variables) in
shared lists causes their addresses to be taken. This involves aliasing problems,
S–2179–36 81










