Parallel Programming in Fortran 95 using OpenMP - People
Parallel Programming in Fortran 95 using OpenMP - People
Parallel Programming in Fortran 95 using OpenMP - People
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 3<br />
PRIVATE, SHARED & Co.<br />
In many of the previously presented <strong>OpenMP</strong> directives it is possible to modify their way<br />
of work<strong>in</strong>g by add<strong>in</strong>g so called clauses. Two different k<strong>in</strong>ds of clauses can be identified.<br />
The first k<strong>in</strong>d, called data scope attribute clauses, specify how each variable is handled<br />
and who is allowed to see its value and to change it. The second k<strong>in</strong>d <strong>in</strong>cludes all the<br />
clauses which do not fit <strong>in</strong>to the first k<strong>in</strong>d.<br />
Not all of the follow<strong>in</strong>g data scope attribute clauses are allowed by all directives, but<br />
the clauses that are valid on a particular directive are <strong>in</strong>dicated <strong>in</strong> the previous descriptions<br />
of the directives.<br />
Although most of the examples presented <strong>in</strong> the follow<strong>in</strong>g descriptions make use of the<br />
directive-pair !$OMP PARALLEL/!$OMP END PARALLEL, this does not mean that their use is<br />
only restricted to that directive-pair, but most of the concepts are easier to understand<br />
with it than with other directive-pairs.<br />
3.1 Data scope attribute clauses<br />
3.1.1 PRIVATE(list)<br />
Sometimes certa<strong>in</strong> variables are go<strong>in</strong>g to have different values <strong>in</strong> each thread. This is only<br />
possible if and only if each thread has its own copy of the variable. This clause fixes which<br />
variables are go<strong>in</strong>g to be considered as local variables to each thread. For example<br />
!$OMP PARALLEL PRIVATE(a, b)<br />
says, that the variables a and b will have different values <strong>in</strong> each thread: they will be<br />
local to each thread.<br />
When a variable is said to be private, a new object of the same type is declared once<br />
for each thread <strong>in</strong> the team and used by each thread <strong>in</strong>side the scope of the directive-pair<br />
(<strong>in</strong> the previous example <strong>in</strong>side the parallel region) <strong>in</strong>stead of the orig<strong>in</strong>al variable. This<br />
idea is shown <strong>in</strong> figure 3.1 <strong>in</strong> a graphical way.<br />
Variables declared as private have an undef<strong>in</strong>ed value at the beg<strong>in</strong>n<strong>in</strong>g of the scope<br />
of the directive-pair, s<strong>in</strong>ce they have just been created. Also when the scope of the<br />
37