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.

56 4. The <strong>OpenMP</strong> run-time library<br />

The number of threads imposed by a call to this subrout<strong>in</strong>e has always precedence<br />

over the value specified <strong>in</strong> the OMP NUM THREADS environment variable.<br />

4.1.2 OMP get num threads<br />

This function allows to know the number of threads currently <strong>in</strong> the team execut<strong>in</strong>g<br />

the parallel region from which it is called. Therefore, this function is meant to be used<br />

from <strong>in</strong>side a parallel region; although when called from a serial region or from <strong>in</strong>side<br />

a serialized nested parallel region, it returns the correct result, namely 1 thread. Its<br />

<strong>in</strong>terface declaration is:<br />

function OMP_get_num_threads()<br />

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

end function OMP_get_num_threads<br />

where the returned value will be the number of threads <strong>in</strong> use.<br />

4.1.3 OMP get max threads<br />

This function returns the maximum number of threads that can be used <strong>in</strong> the program.<br />

Its result may differ from the one returned by the function OMP get num threads, ifthe<br />

dynamic adjustment of threads is enabled; otherwise, the results will be equal. Its <strong>in</strong>terface<br />

declaration is equivalent to the one of the function OMP get num threads:<br />

function OMP_get_max_threads()<br />

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

end function OMP_get_max_threads<br />

where the returned value is the maximum allowed number of threads. S<strong>in</strong>ce the<br />

returned value has noth<strong>in</strong>g to do with the actual number of threads used <strong>in</strong> a given<br />

parallel region, this function can be called from serial regions as well as from parallel<br />

regions.<br />

4.1.4 OMP get thread num<br />

This function returns the identification number of the current thread with<strong>in</strong> the team.<br />

The identification numbers are between 0, the master thread, and OMP get num threads()<br />

- 1, <strong>in</strong>clusive. The <strong>in</strong>terface of this function is:<br />

function OMP_get_thread_num()<br />

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

end function OMP_get_thread_num<br />

This function returns 0, when called from <strong>in</strong>side a serial region or a serialized nested<br />

parallel region, which is the identification number of the lonely master thread.

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

Saved successfully!

Ooh no, something went wrong!