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.
10 2. <strong>OpenMP</strong> constructs<br />
• Work-shar<strong>in</strong>g constructs must be encountered <strong>in</strong> the same order by all threads <strong>in</strong> a<br />
team.<br />
All work-shar<strong>in</strong>g constructs have an implied synchronization <strong>in</strong> their clos<strong>in</strong>g-directives.<br />
This is <strong>in</strong> general necessary to ensure that all the <strong>in</strong>formation, required by the code<br />
follow<strong>in</strong>g the work-shar<strong>in</strong>g construct, is uptodate. But such a thread synchronization<br />
is not always necessary and therefore a mechanism of suppress<strong>in</strong>g it exists, s<strong>in</strong>ce it is a<br />
resource wast<strong>in</strong>g affair 2 . For that purpose a special clause exists which is l<strong>in</strong>ked to the<br />
clos<strong>in</strong>g-directive: NOWAIT. Further <strong>in</strong>formation regard<strong>in</strong>g this clause is given <strong>in</strong> chapter 3,<br />
page 47.<br />
2.1.1 !$OMP DO/!$OMP END DO<br />
This directive-pair makes the immediately follow<strong>in</strong>g do-loop to be executed <strong>in</strong> parallel.<br />
For example<br />
!$OMP DO<br />
do i = 1, 1000<br />
...<br />
enddo<br />
!$OMP END DO<br />
distributes the do-loop over the different threads: each thread computes part of the<br />
iterations. For example, if 10 threads are <strong>in</strong> use, then <strong>in</strong> general each thread computes<br />
100 iterations of the do-loop: thread 0 computes from 1 to 100, thread 1 from 101 to 200<br />
and so on. This is shown graphically <strong>in</strong> figure 2.1.<br />
serial region<br />
thread 0<br />
E xecution<br />
!$OMP DO<br />
parallel region<br />
❄ ❄ ❄<br />
thread 0 thread 1 thread 9<br />
...<br />
do i = 1, 100 do i = 101, 200 do i = 901, 1000<br />
❄<br />
Figure 2.1: Graphical representation of the example expla<strong>in</strong><strong>in</strong>g the general work<strong>in</strong>g pr<strong>in</strong>ciple<br />
of the !$OMP DO/!$OMP END DO directive-pair.<br />
2 Threads that reach the implied synchronization are idle until all the other threads reach the same<br />
po<strong>in</strong>t.