26.06.2015 Views

Parallel Programming in Fortran 95 using OpenMP - People

Parallel Programming in Fortran 95 using OpenMP - People

Parallel Programming in Fortran 95 using OpenMP - People

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

38 3. PRIVATE, SHARED & Co.<br />

Shared memory<br />

serial region<br />

thread 0<br />

a<br />

b<br />

E xecution<br />

parallel region<br />

❄ ❄ ❄<br />

thread 0 thread 1 thread N<br />

...<br />

a b a b a b<br />

Shared memory<br />

❄<br />

Figure 3.1: Graphical representation of the effect of the PRIVATE clause on the variables a and<br />

b of the presented example.<br />

directive-pair f<strong>in</strong>ishes, the orig<strong>in</strong>al variable will have an undef<strong>in</strong>ed value (which value<br />

from the available ones should it have!?).<br />

The fact, that a new object is created for each thread can be a very resource consum<strong>in</strong>g<br />

th<strong>in</strong>g: for example, if a 5Gb array (a common size for direct numerical simulations or<br />

complex chemically react<strong>in</strong>g flow applications) is specified to be private <strong>in</strong> a parallel<br />

region with 10 threads, then the total memory requirement will be of 55Gb 1 ,anamount<br />

of storage not available on all SMP mach<strong>in</strong>es!<br />

Variables that are used as counters for do-loops, forall commands or implicit do-loops<br />

or are specified to be THREADPRIVATE become automatically private to each thread, even<br />

though they are not explicitly <strong>in</strong>cluded <strong>in</strong>side a PRIVATE clause at the beg<strong>in</strong>n<strong>in</strong>g of the<br />

scope of the directive-pair.<br />

3.1.2 SHARED(list)<br />

In contrast to the previous situation, sometimes there are variables which should be<br />

available to all threads <strong>in</strong>side the scope of a directive-pair, because their values are needed<br />

by all threads or because all threads have to update their values. For example<br />

!$OMP PARALLEL SHARED(c, d)<br />

says that the variables c and d are seen by all threads <strong>in</strong>side the scope of the !$OMP<br />

PARALLEL/!$OMP END PARALLEL directive-pair. This example is shown <strong>in</strong> figure 3.2 <strong>in</strong> a<br />

graphical way.<br />

When a variable is said to be shared, noth<strong>in</strong>g happens to it: no new memory is<br />

reserved and its value before the start<strong>in</strong>g-directive is conserved. This means that all<br />

1 Although it is allowed that one thread reuses the orig<strong>in</strong>al memory location of the orig<strong>in</strong>al variable,<br />

this is someth<strong>in</strong>g not required by the <strong>OpenMP</strong> standard and it is left open to the developers of each<br />

<strong>OpenMP</strong> implementation to do it or not.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!