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.3. Tim<strong>in</strong>g rout<strong>in</strong>es 65<br />

!---------------------------------------------------------!<br />

subrout<strong>in</strong>e substract(x,d)<br />

use omp_lib<br />

use data_types<br />

implicit none<br />

type(number) :: x<br />

<strong>in</strong>teger :: d<br />

call OMP_set_nest_lock(x%lck)<br />

call add(x,-d)<br />

call OMP_unset_nest_lock(x%lck)<br />

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

The subrout<strong>in</strong>e add is called once by each thread. In both calls the updat<strong>in</strong>g of the<br />

variable x is correctly done, s<strong>in</strong>ce a lock is allow<strong>in</strong>g the access to only one thread at a<br />

time. The reason why substract is impos<strong>in</strong>g the lock relays on the fact that substract<br />

is not obliged to know what the subrout<strong>in</strong>e add <strong>in</strong>ternally does.<br />

4.3 Tim<strong>in</strong>g rout<strong>in</strong>es<br />

The last set of rout<strong>in</strong>es <strong>in</strong> the <strong>OpenMP</strong> <strong>Fortran</strong> API run-time library allows to measure<br />

absolute values of wallclock times with the idea to serve as an evaluation tool for programs.<br />

4.3.1 OMP get wtime<br />

This function returns the absolute wallclock time <strong>in</strong> seconds. By two calls to this function,<br />

it is possible to measure the time required to compute the commands enclosed between<br />

the two calls, like <strong>in</strong> the follow<strong>in</strong>g example:<br />

start = OMP_get_wtime()<br />

... !work to be timed<br />

end = OMP_get_wtime()<br />

time = end - start<br />

The <strong>in</strong>terface declaration for this function is:<br />

function OMP_get_wtime()<br />

real(8) :: OMP_get_wtime<br />

end function OMP_get_wtime<br />

The times returned by this function are ”per-thread times” by which is meant they are<br />

not required to be globally consistent across all the threads participat<strong>in</strong>g <strong>in</strong> a program.

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

Saved successfully!

Ooh no, something went wrong!