public class DFSWorkStealing<V> extends ParIteratorAbstract<V>
ParIterator.SchedulechunkSize, collection, data, exceptions, flags, ignoreBarrier, numOfThreads, reclaimedElements, threadIDDEFAULT_CHUNKSIZE| Constructor and Description |
|---|
DFSWorkStealing(GraphAdapterInterface tree,
V root,
int numOfThreads) |
| Modifier and Type | Method and Description |
|---|---|
void |
forEachRemaining(java.util.function.Consumer<? super V> action) |
void |
globalBreak()
Causes all threads to stop processing elements at the next iteration boundary.
|
boolean |
hasNext()
Checks to see if any elements remain for the current thread.
|
boolean |
localBreak()
Attempts to excuse the current thread from continuing to iterate (and re-distribute all unprocessed elements to
the other threads).
|
V |
next()
Returns an element for the current thread to process.
|
allOtherThreadsHaveLocalBreaked, getAllExceptions, getID, register, register, remove, resetpublic DFSWorkStealing(GraphAdapterInterface tree, V root, int numOfThreads)
public boolean hasNext()
ParIteratortrue is returned
and the current thread must follow up with a binding call to next(). A thread must continue to obtain elements
in this fashion until this method returns false.
Note that this method involves an implicit barrier for the last call to hasNext() in order to ensure all threads
finish at the same time.
true if at least one element has been reserved for the calling thread (in which case it must follow up
with a call to next()).
false otherwise (in such a case, the calling thread blocks until all the other threads have completed
their iterations).ParIterator.next()public V next()
ParIteratorhasNext() (and received true).
Note that calls to hasNext() (that return true) only allow for one corresponding and binding call to
hasNext(). Therefore, multiple calls to hasNext() have no effect until the corresponding
call to next() takes place.
ParIterator.hasNext()public void globalBreak()
ParIteratorfalse is returned to every thread at the next call to
hasNext(). Therefore, all the threads safely stop iterating when they call hasNext() (includes
an implicit barrier to ensure all threads stop at the same time).globalBreak in interface ParIterator<V>globalBreak in class ParIteratorAbstract<V>ParIterator.localBreak()public boolean localBreak()
ParIterator
Therefore, (as opposed to globalBreak()) this method guarantees that even if all threads attempt to
localBreak(), at least one will fail and is left to traverse the remaining elements. Note that in many
cases, calling localBreak() will break the original scheduling policy.
true if the attempt is successful, false otherwise.ParIterator.globalBreak()public void forEachRemaining(java.util.function.Consumer<? super V> action)