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.
Chapter 2<br />
<strong>OpenMP</strong> constructs<br />
If only the previous parallel region constructor would exist, then the only possible th<strong>in</strong>g to<br />
do would be that all the threads perform exactly the same task, but this is not the aim of<br />
parallelism. Therefore, <strong>OpenMP</strong> def<strong>in</strong>es additional constructs which allow to distribute<br />
a given task over the different threads and achieve <strong>in</strong> this way a real parallel work<strong>in</strong>g<br />
program.<br />
Four different groups of <strong>OpenMP</strong> directives or constructs exist. Each group has a<br />
different aim and the selection of one directive or another <strong>in</strong>side the same group depends<br />
on the nature of the problem to be solved. Therefore, it is good to understand the<br />
pr<strong>in</strong>ciples of each of these directives <strong>in</strong> order to perform the correct choices.<br />
2.1 Work-shar<strong>in</strong>g constructs<br />
The first group of <strong>OpenMP</strong> directives looks forward to divide a given work <strong>in</strong>to pieces<br />
and to give one or more of these pieces to each parallel runn<strong>in</strong>g thread. In this way the<br />
work, which would be done by a s<strong>in</strong>gle thread <strong>in</strong> a serial program, is distributed over a<br />
team of threads achiev<strong>in</strong>g a faster runn<strong>in</strong>g program 1 .<br />
All work-shar<strong>in</strong>g constructs must be placed <strong>in</strong>side dynamic extends of parallel regions<br />
<strong>in</strong> order to be effective. If this is not the case, the work-shar<strong>in</strong>g construct will still<br />
work, but a team with only one thread will be used. The reason is that a work-shar<strong>in</strong>g<br />
construct is not able of creat<strong>in</strong>g new threads; a task reserved to the !$OMP PARALLEL/!$OMP<br />
END PARALLEL directive-pair.<br />
The follow<strong>in</strong>g restrictions need to be taken <strong>in</strong>to account when us<strong>in</strong>g a work-shar<strong>in</strong>g<br />
construct:<br />
• Work-shar<strong>in</strong>g constructs must be encountered by all threads <strong>in</strong> a team or by none<br />
at all.<br />
1 Obviously, this is only true, if the team of threads is executed on more than one processor, which is<br />
the case of SMP mach<strong>in</strong>es. Otherwise, when us<strong>in</strong>g a s<strong>in</strong>gle processor, the computational overhead due to<br />
the <strong>OpenMP</strong> directives as well as due to the need of execut<strong>in</strong>g several threads <strong>in</strong> a sequential way lead<br />
to slower parallel programs than the correspond<strong>in</strong>g serial versions!<br />
9