26.06.2015 Views

Parallel Programming in Fortran 95 using OpenMP - People

Parallel Programming in Fortran 95 using OpenMP - People

Parallel Programming in Fortran 95 using OpenMP - People

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4.1. Execution environment rout<strong>in</strong>es 57<br />

4.1.5 OMP get num procs<br />

This function returns the number of processors available to the program. Its <strong>in</strong>terface<br />

declaration is as follows:<br />

function OMP_get_num_procs()<br />

<strong>in</strong>teger(k<strong>in</strong>d = OMP_<strong>in</strong>teger_k<strong>in</strong>d) :: OMP_get_num_procs<br />

end function OMP_get_num_procs<br />

4.1.6 OMP <strong>in</strong> parallel<br />

This function allows to know, if a given region of the program is be<strong>in</strong>g computed <strong>in</strong> parallel<br />

or not. For that purpose, it looks at all the parallel regions which are surround<strong>in</strong>g the<br />

block of source code enclos<strong>in</strong>g the call to OMP <strong>in</strong> parallel and returns .TRUE., ifatleast<br />

one of them is be<strong>in</strong>g executed <strong>in</strong> parallel; otherwise, it returns .FALSE.. The <strong>in</strong>terface<br />

declaration of this function is the follow<strong>in</strong>g one:<br />

function OMP_<strong>in</strong>_parallel()<br />

logical(k<strong>in</strong>d = OMP_logical_k<strong>in</strong>d) :: OMP_<strong>in</strong>_parallel<br />

end function OMP_<strong>in</strong>_parallel<br />

S<strong>in</strong>ce the returned value will be .TRUE. as soon as one of the enclos<strong>in</strong>g parallel regions is<br />

be<strong>in</strong>g executed <strong>in</strong> parallel, this function returns .TRUE. from any po<strong>in</strong>t <strong>in</strong>side the dynamic<br />

extent of that parallel region, even <strong>in</strong>side nested serialized parallel regions (which are not<br />

considered as be<strong>in</strong>g executed <strong>in</strong> parallel!).<br />

4.1.7 OMP set dynamic<br />

The OMP set dynamic subrout<strong>in</strong>e enables or disables dynamic adjustment of the number<br />

of threads available for execution of parallel regions. Its <strong>in</strong>terface is:<br />

subrout<strong>in</strong>e OMP_set_dynamic(enable)<br />

logical(k<strong>in</strong>d = OMP_logical_k<strong>in</strong>d), <strong>in</strong>tent(<strong>in</strong>) :: enable<br />

end subrout<strong>in</strong>e OMP_set_dynamic<br />

When enable is set equal to .TRUE., the number of threads to be used by subsequent<br />

parallel regions can be adjusted automatically by the run-time environment <strong>in</strong> order to<br />

maximize the use of the SMP mach<strong>in</strong>e; otherwise, if enable is equal to .FALSE., the<br />

dynamic adjustment is disabled.<br />

As a consequence, the number of threads specified through the environment variable<br />

OMP NUM THREADS or by a call to the run-time library subrout<strong>in</strong>e OMP set num threads represents<br />

the maximum allowed number of threads which can be assigned to the program<br />

by the run-time environment.<br />

The work<strong>in</strong>g conditions specified <strong>in</strong> a call to OMP set dynamic have precedence over<br />

the sett<strong>in</strong>gs <strong>in</strong> the OMP DYNAMIC environment variable.<br />

The default for dynamic thread adjustment is <strong>OpenMP</strong>-implementation dependent,<br />

therefore a program need<strong>in</strong>g a specific number of threads to run correctly should explicitly

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!