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.
3.2. Other clauses 47<br />
do i = 1, N<br />
...<br />
enddo<br />
!$OMP END DO<br />
!$OMP END PARALLEL<br />
the do-loop is executed <strong>in</strong> parallel only, if the number of iterations is greater than<br />
1000, otherwise the do-loop is executed <strong>in</strong> a serial fashion.<br />
3.2.2 NUM THREADS(scalar <strong>in</strong>teger expression)<br />
For certa<strong>in</strong> parallel runn<strong>in</strong>g source code l<strong>in</strong>es it could be desirable to use a fixed number<br />
of threads, for example, if a certa<strong>in</strong> set of tasks has been def<strong>in</strong>ed us<strong>in</strong>g an !$OMP SECTIONS<br />
directive. The use of the clause would look as follows:<br />
!$OMP PARALLEL NUM_THREADS(4)<br />
where four threads are requested for the specific parallel region.<br />
When a NUM THREADS clause is used at the beg<strong>in</strong>n<strong>in</strong>g of a parallel region, it overwrites<br />
any sett<strong>in</strong>gs imposed by the environmental variable OMP NUM THREADS or by a call to the<br />
run-time library subrout<strong>in</strong>e OMP set num threads 3 . The specified number of threads only<br />
affects the present parallel region and not the future ones.<br />
3.2.3 NOWAIT<br />
Under certa<strong>in</strong> circumstances it is not necessary that all threads f<strong>in</strong>ish a given parallel<br />
executed task at the same time, because the follow<strong>in</strong>g operations are not depend<strong>in</strong>g on<br />
what has been done before. In such cases it is possible to avoid the implied synchronization<br />
present <strong>in</strong> many <strong>OpenMP</strong> directives by add<strong>in</strong>g the NOWAIT clause to their clos<strong>in</strong>g-directive.<br />
In the follow<strong>in</strong>g example<br />
!$OMP PARALLEL<br />
!$OMP DO<br />
do i = 1, 1000<br />
a = i<br />
enddo<br />
!$OMP END DO NOWAIT<br />
!$OMP DO<br />
do i = 1, 1000<br />
b = i<br />
enddo<br />
!$OMP END DO<br />
!$OMP END PARALLEL<br />
3 The run-time rout<strong>in</strong>e OMP set num threads, expla<strong>in</strong>ed later on, allows to specify the number of<br />
threads to be used <strong>in</strong> the follow<strong>in</strong>g parallel regions.