next up previous
Next: Actual Loop Parallelization Up: Class Hierarchy for Parallel Previous: LoopPool

RandomSync

  The class RandomSync defines an implementation of synchronization variables for random synchronization in DOACROSS-loops. A boolean arrays bits is used to implement the bit-array, while an integer low is used to record the lower bound of the execution set of the parallel loop:

tabular239

The following constructor can be used to obtain a synchronization variable for a parallel stride-1 loop with execution set tex2html_wrap_inline2390 . In this constructor, a new bit-array that has one bit for each iteration is obtained (viz. bit (i-low) belongs to iteration i), and the lower bound l is recorded:

tabular247

Setting the bit of iteration i of a synchronization variable is done by calling the following synchronized instance method doPost() on this variable. Likewise, calling the synchronized instance method doWait() shown below on a synchronization variable blocks until the bit of iteration j of this variable becomes set. The test low <= j, however, makes this method non-blocking for out-of-bounds tests (which only may go backwards in the iteration space of the DOACROSS-loop):

tabular256

tabular260

The call to notifyAll() will eventually wake up all threads that are blocked on some synchronization variable (although, of course, they only re-acquire the lock of the monitor one at the time).

Because being notified does not necessarily mean that the appropriate bit actually has been set, however, the wait()-statement appears in a while-statement (rather than in an if-statement).

Although in the implementation shown above, waiting threads do not compete for processor time, the overhead of frequently accessing synchronized methods may be substantial. In this particular case, mutual exclusion while accessing the bit-array is not really required, and we can also implement the methods shown above using busy-waiting by eliminating the qualifiers synchronized and and replacing the wait()-statement by the call `Thread.currentThread().yield()'. In section 4.3 we will see that this approach can substantially improve the performance of a DOACROSS-loop. However, because the Java language specification does not guarantee fairness between runnable threads, and in Java there is no way to declare the elements of an array as volatile (and since the elements of bits are accessed asynchronously, other processors may fail to see changes [12, ch.17,]), this approach may be unsuited for particular implementations of the Java Virtual Machine.


next up previous
Next: Actual Loop Parallelization Up: Class Hierarchy for Parallel Previous: LoopPool

ajcbik@extreme.indiana.edu