Parallel Programming in Fortran 95 using OpenMP - People
Parallel Programming in Fortran 95 using OpenMP - People
Parallel Programming in Fortran 95 using OpenMP - People
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
32 2. <strong>OpenMP</strong> constructs<br />
!$OMP END DO<br />
Even though, it is possible to have a do-loop with different ORDERED sections, if and<br />
only if only one of these sections is seen by each iteration. For example:<br />
!$OMP DO ORDERED<br />
do i = 1, 1000<br />
...<br />
if(i < 10) then<br />
!$OMP ORDERED<br />
write(4,*) i<br />
!$OMP END ORDERED<br />
else<br />
!$OMP ORDERED<br />
write(3,*) i<br />
!$OMP END ORDERED<br />
endif<br />
...<br />
enddo<br />
!$OMP END DO<br />
2.4 Data environment constructs<br />
The last set of <strong>OpenMP</strong> directives is meant for controll<strong>in</strong>g the data environment dur<strong>in</strong>g<br />
the execution <strong>in</strong> parallel. Two different k<strong>in</strong>ds of data environment constructs can be<br />
found:<br />
• Those which are <strong>in</strong>dependent of other <strong>OpenMP</strong> constructs.<br />
• Those which are associated to an <strong>OpenMP</strong> construct and which affect only that<br />
<strong>OpenMP</strong> construct and its lexical extend (also known as data scope attribute<br />
clauses).<br />
The formers are go<strong>in</strong>g to be described <strong>in</strong> the present section, while the latters are<br />
expla<strong>in</strong>ed <strong>in</strong> chapter 3 due to their extend and importance. Also the rema<strong>in</strong><strong>in</strong>g clauses,<br />
which are not data environment constructs, are go<strong>in</strong>g to be presented <strong>in</strong> chapter 3, lead<strong>in</strong>g<br />
to a unified view of all <strong>OpenMP</strong> clauses.<br />
2.4.1 !$OMP THREADPRIVATE (list)<br />
Sometimes it is of <strong>in</strong>terest to have global variables, but with values which are specific<br />
for each thread. An example could be a variable called my ID which stores the thread<br />
identification number of each thread: this number will be different for each thread, but it<br />
would be useful that its value is accessible from everywhere <strong>in</strong>side each thread and that<br />
its value does not change from one parallel region to the next.