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 4<br />
The <strong>OpenMP</strong> run-time library<br />
In some of the examples presented <strong>in</strong> previous chapters it has been mentioned the existence<br />
of a run-time library. It is the aim of the present chapter to <strong>in</strong>troduce the so called<br />
<strong>OpenMP</strong> <strong>Fortran</strong> API run-time library, describe the subrout<strong>in</strong>es and functions it<br />
<strong>in</strong>cludes and to expla<strong>in</strong> its capabilities as well as its limitations.<br />
The <strong>OpenMP</strong> run-time library is meant to serve as a control and query tool for the<br />
parallel execution environment, which the programmer can use from <strong>in</strong>side its program.<br />
Therefore, the run-time library is a set of external procedures with clearly def<strong>in</strong>ed <strong>in</strong>terfaces.<br />
These <strong>in</strong>terfaces are explicitly delivered by the <strong>OpenMP</strong>-implementation through<br />
a <strong>Fortran</strong> <strong>95</strong> module named omp lib. In the follow<strong>in</strong>g descriptions of the different rout<strong>in</strong>es,<br />
<strong>in</strong>terfaces for them are shown: these may vary from one <strong>OpenMP</strong>-implementation<br />
to another <strong>in</strong> the precision/size of the variables, but <strong>in</strong> essence will be all equal.<br />
4.1 Execution environment rout<strong>in</strong>es<br />
The follow<strong>in</strong>g functions and subrout<strong>in</strong>es, part of the <strong>OpenMP</strong> <strong>Fortran</strong> API run-time<br />
library, allow to modify, from <strong>in</strong>side of a program, the conditions of the run-time environment<br />
that controls the parallel execution of the program:<br />
4.1.1 OMP set num threads<br />
This subrout<strong>in</strong>e sets the number of threads to be used by subsequent parallel regions.<br />
Therefore, it can only be called from outside of a parallel region. Its <strong>in</strong>terface declaration<br />
looks as follows:<br />
subrout<strong>in</strong>e OMP_set_num_threads(number_of_threads)<br />
<strong>in</strong>teger(k<strong>in</strong>d = OMP_<strong>in</strong>teger_k<strong>in</strong>d), <strong>in</strong>tent(<strong>in</strong>) :: number_of_threads<br />
end subrout<strong>in</strong>e OMP_set_num_threads<br />
where number of threads is the number of threads to be set. If dynamic adjustment is<br />
disabled, the value of number of threads is used as the number of threads for all subsequent<br />
parallel regions prior to the next call to this subrout<strong>in</strong>e; otherwise, if dynamic adjustment<br />
is enabled, number of threads is the maximum number of threads that is allowed.<br />
55