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.

18 2. <strong>OpenMP</strong> constructs<br />

thread 0 thread 1 thread N p<br />

!$OMP SINGLE<br />

❄<br />

❄<br />

❄<br />

E xecution<br />

parallel region<br />

write(*,*) "Hello"<br />

...<br />

!$OMP END SINGLE<br />

✞<br />

☎<br />

✝❝<br />

✆<br />

✞<br />

☎<br />

✝❝<br />

✆<br />

❄ ❄ ❄<br />

❄<br />

Figure 2.3: Graphical representation of the example expla<strong>in</strong><strong>in</strong>g the work<strong>in</strong>g pr<strong>in</strong>ciple of the<br />

!$OMP SINGLE/!$OMP END SINGLE directive-pair.<br />

be parallelized with the aid of the !$OMP WORKSHARE/!$OMP END WORKSHARE directive-pair:<br />

matmul, dot product, sum, product, maxval, m<strong>in</strong>val, count, any, all, spread, pack, unpack,<br />

reshape, transpose, eoshift, cshift, m<strong>in</strong>loc and maxloc. The syntax to be used is the<br />

follow<strong>in</strong>g one:<br />

!$OMP WORKSHARE<br />

...<br />

!$OMP END WORKSHARE end_clause<br />

where an implied synchronization exists <strong>in</strong> the clos<strong>in</strong>g-directive !$OMP END WORKSHARE,<br />

if the NOWAIT clause is not specified on the clos<strong>in</strong>g-directive.<br />

In contrast to the previously presented work-shar<strong>in</strong>g constructs, the block of code<br />

enclosed <strong>in</strong>side the present directive-pair is executed <strong>in</strong> such a way, that each statement<br />

is completed before the next statement is started. The result is that the block of code<br />

behaves exactly <strong>in</strong> the same way as if it would be executed <strong>in</strong> serial. For example,<br />

the effects of one statement with<strong>in</strong> the enclosed code must appear to occur before the<br />

execution of the follow<strong>in</strong>g statements, and the evaluation of the right hand side of an<br />

assignment must appear to have been completed prior to the effects of assign<strong>in</strong>g to the<br />

left hand side. This means that the follow<strong>in</strong>g example<br />

real(8) :: A(1000), B(1000)

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

Saved successfully!

Ooh no, something went wrong!