For Sun-style (C$PAR) explicit directives, the compiler uses default rules to determine whether a scalar or array is shared or private. You can override the default rules to specify the attributes of scalars or arrays referenced inside a loop. (With Cray-style !MIC$ directives, all variables that appear in the loop must be explicitly declared either shared or private on the DOALL directive.)
The compiler applies these default rules:
All scalars are treated as private. A processor local copy of the scalar is made in each processor, and that local copy is used within that process.
All array references are treated as shared references. Any write of an array element by one processor is visible to all processors. No synchronization is performed on accesses to shared variables.
If inter-iteration dependencies exist in a loop, then the execution may result in erroneous results. You must ensure that these cases do not arise. The compiler may sometimes be able to detect such a situation at compile time and issue a warning, but it does not disable parallelization of such loops.
Example: Potential problem through equivalence:
equivalence (a(1),y) C$PAR DOALL do i = 1,n y = i a(i) = y end do
In the preceding example, since the scalar variable y has been equivalenced to a(1), it is no longer a private variable, even though the compiler treats it as such by the default scoping rule. Thus, the presence of the DOALL directive might lead to erroneous results when the parallelized i loop is executed.
You can fix the example by using C$PAR DOALL PRIVATE(y).