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.
60 4. The <strong>OpenMP</strong> run-time library<br />
4. Once it has f<strong>in</strong>ished its work, it releases the ownership so that another thread can<br />
fetch it.<br />
5. F<strong>in</strong>ally, once the lock is no longer needed, it is necessary to elim<strong>in</strong>ate it and its<br />
associated lock variable.<br />
Two different types of locks exist:<br />
simple locks : these locks cannot be locked if they are already <strong>in</strong> a locked state.<br />
nestable locks : these locks may be locked multiple times by the same thread before<br />
be<strong>in</strong>g unlocked. They have associated a nest<strong>in</strong>g counter which keeps track of the<br />
number of times a nestable lock has been locked and released.<br />
Each run-time library rout<strong>in</strong>e, which works with locks, has two different versions: one<br />
whichactsonsimplelocksandanotherwhichactsonnestablelocks.Itisnotallowedto<br />
call one k<strong>in</strong>d of rout<strong>in</strong>es with the type of variable of the other k<strong>in</strong>d!<br />
The run-time library rout<strong>in</strong>es needed to handle locks are described <strong>in</strong> the follow<strong>in</strong>g<br />
subsections.<br />
4.2.1 OMP <strong>in</strong>it lock and OMP <strong>in</strong>it nest lock<br />
These subrout<strong>in</strong>es <strong>in</strong>itialize a lock: a simple one and a nestable one, respectively. It is<br />
necessary to make a call to one of these subrout<strong>in</strong>es before any other of the follow<strong>in</strong>g<br />
rout<strong>in</strong>es can be used. Their <strong>in</strong>terface declarations are:<br />
subrout<strong>in</strong>e OMP_<strong>in</strong>it_lock(svar)<br />
<strong>in</strong>teger(k<strong>in</strong>d = OMP_lock_k<strong>in</strong>d), <strong>in</strong>tent(out) :: svar<br />
end subrout<strong>in</strong>e OMP_<strong>in</strong>it_lock<br />
subrout<strong>in</strong>e OMP_<strong>in</strong>it_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(out) :: nvar<br />
end subrout<strong>in</strong>e OMP_<strong>in</strong>it_nest_lock<br />
where the passed argument, called lock variable, is associated with a lock. Once a<br />
lock variable has been <strong>in</strong>itialized, it can be used <strong>in</strong> subsequent calls to rout<strong>in</strong>es to refer<br />
to the specified lock. If the lock variable is nestable, its nest<strong>in</strong>g counter is set to zero.<br />
It is not allowed to call these subrout<strong>in</strong>es us<strong>in</strong>g a lock variable that has already been<br />
associated to a lock, although it is not specified how an <strong>OpenMP</strong>-implementation has to<br />
react<strong>in</strong>suchacase.<br />
4.2.2 OMP set lock and OMP set nest lock<br />
When a thread wants to own a specific lock, it calls one of these subrout<strong>in</strong>es. If the<br />
specified lock is not owned by another thread, then it gets the ownership of that lock. If<br />
the specified lock is already owned by another thread, then it has to wait until the other<br />
thread releases its ownership over the lock. The <strong>in</strong>terface declarations of these subrout<strong>in</strong>es<br />
are as follows: