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.
4.2. Lock rout<strong>in</strong>es 61<br />
subrout<strong>in</strong>e OMP_set_lock(svar)<br />
<strong>in</strong>teger(k<strong>in</strong>d = OMP_lock_k<strong>in</strong>d), <strong>in</strong>tent(<strong>in</strong>out) :: svar<br />
end subrout<strong>in</strong>e OMP_set_lock<br />
subrout<strong>in</strong>e OMP_set_nest_lock(nvar)<br />
<strong>in</strong>teger(k<strong>in</strong>d = OMP_nest_lock_k<strong>in</strong>d), <strong>in</strong>tent(<strong>in</strong>out) :: nvar<br />
end subrout<strong>in</strong>e OMP_set_nest_lock<br />
A simple lock will be available if it is unlocked, while a nestable lock is available if it<br />
is unlocked or if it is already owned by the thread execut<strong>in</strong>g the subrout<strong>in</strong>e. In the latter<br />
case, the nest<strong>in</strong>g counter of a nestable lock variable is <strong>in</strong>cremented by one when it is set.<br />
4.2.3 OMP unset lock and OMP unset nest lock<br />
These subrout<strong>in</strong>es provide the means of releas<strong>in</strong>g the ownership of a lock. Their <strong>in</strong>terface<br />
declaration is:<br />
subrout<strong>in</strong>e OMP_unset_lock(svar)<br />
<strong>in</strong>teger(k<strong>in</strong>d = OMP_lock_k<strong>in</strong>d), <strong>in</strong>tent(<strong>in</strong>out) :: svar<br />
end subrout<strong>in</strong>e OMP_unset_lock<br />
subrout<strong>in</strong>e OMP_unset_nest_lock(nvar)<br />
<strong>in</strong>teger(k<strong>in</strong>d = OMP_nest_lock_k<strong>in</strong>d), <strong>in</strong>tent(<strong>in</strong>out) :: nvar<br />
end subrout<strong>in</strong>e OMP_unset_nest_lock<br />
In the first case, a call to the subrout<strong>in</strong>e releases the call<strong>in</strong>g thread from the ownership<br />
of the simple lock associated to the correspond<strong>in</strong>g lock variable svar, while <strong>in</strong> the second<br />
case the call to the subrout<strong>in</strong>e decreases by one the nest<strong>in</strong>g counter of nvar and only<br />
releases the call<strong>in</strong>g thread, if the counter reaches zero.<br />
To call these subrout<strong>in</strong>es only makes sense, if the call<strong>in</strong>g thread owns the correspond<strong>in</strong>g<br />
lock; the behaviour is unspecified if the call<strong>in</strong>g thread does not own the lock!<br />
4.2.4 OMP test lock and OMP test nest lock<br />
These functions attempt to set a lock <strong>in</strong> the same way as the subrout<strong>in</strong>es OMP set lock and<br />
OMP set nest lock do, but they do not force the call<strong>in</strong>g thread to wait until the specified<br />
lock is available. Their <strong>in</strong>terface declarations are the follow<strong>in</strong>g ones:<br />
function OMP_test_lock(svar)<br />
logical(k<strong>in</strong>d = OMP_logical_k<strong>in</strong>d) :: OMP_test_lock<br />
<strong>in</strong>teger(k<strong>in</strong>d = OMP_lock_k<strong>in</strong>d), <strong>in</strong>tent(<strong>in</strong>out) :: svar<br />
end function OMP_test_lock<br />
function OMP_test_nest_lock(nvar)<br />
<strong>in</strong>teger(k<strong>in</strong>d = OMP_<strong>in</strong>teger_k<strong>in</strong>d) :: OMP_test_nest_lock<br />
<strong>in</strong>teger(k<strong>in</strong>d = OMP_nest_lock_k<strong>in</strong>d), <strong>in</strong>tent(<strong>in</strong>out) :: nvar<br />
end function OMP_test_nest_lock