pt.runtime
Class TaskIDGroup<E>

java.lang.Object
  extended by pt.runtime.TaskID<E>
      extended by pt.runtime.TaskIDGroup<E>
Type Parameters:
E -

public class TaskIDGroup<E>
extends TaskID<E>

An extension of TaskID to contain multiple tasks. In particular, a TaskIDGroup is returned for all multi-task invocations. Users may also instantiate a TaskIDGroup and populate it with multiple TaskIDs (and TaskIDGroups). This would be useful, for example, when invoking many different tasks, allowing a collective approach to synchronise on those tasks (i.e. wait on the TaskIDGroup rather than the on each individual TaskID.

Author:
Nasser Giacaman, Oliver Sinnen

Field Summary
 
Fields inherited from class pt.runtime.TaskID
cancelled, CANCELLED, cancelRequested, CREATED, enclosingTask, globalID, group, hasCompleted, hasSlots, hasUserError, nextGlobalID, relativeID, STARTED, status, taskInfo
 
Constructor Summary
TaskIDGroup(int groupSize)
          This public constructor is actually used to group a bunch of tasks, which may include one-off task or multi task, should not give any id to this group.
 
Method Summary
 void add(TaskID<E> id)
           
 boolean cancelAttempt()
          Canceling a group is currently not supported.
 java.lang.Throwable getException()
          Returns the exception that occurred while this task executed.
protected  boolean getExpanded()
           
 E getInnerTaskResult(int relativeID)
          Returns the result of a particular task.
 E getReturnResult()
          Get the result of a group of tasks.
 E getReturnResult(Reduction<E> red)
          Perform a reduction on the results contained in the group.
 java.util.Iterator<TaskID<E>> groupMembers()
          Return an iterator for the set of TaskIDs contained in this group.
 int groupSize()
          Returns the group size.
 boolean hasCompleted()
          Checks to see whether all the inner tasks have completed.
 boolean hasUserError()
          Checks to see whether any of the inner tasks contained an error.
 boolean isMultiTask()
          Checks whether this TaskIDGroup represents a multi-task.
 E reduce(Reduction<E> red)
          Perform a reduction on the set of results.
protected  void setExpanded(boolean isExpanded)
           
 void waitTillFinished()
          Waits for all the contained inner tasks to complete.
 
Methods inherited from class pt.runtime.TaskID
cancelChildTasks, cancelledSuccessfully, cancelRequested, currentThreadIsTheRegisteredThread, executeIntermediateSlots, executeSlots, getCount, getExceptionHandler, getGroup, getOutputQueue, getOutputQueue, getProgress, getTaskArguments, getTaskName, globalID, isInteractive, isPipeline, isSubTask, multiTaskSize, relativeID, setCount, setGlobalID, setPipelineThread, setSubTask, unregisterOutputQueue, writeToOutputQueues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskIDGroup

public TaskIDGroup(int groupSize)
This public constructor is actually used to group a bunch of tasks, which may include one-off task or multi task, should not give any id to this group.

Method Detail

isMultiTask

public boolean isMultiTask()
Checks whether this TaskIDGroup represents a multi-task. This is because users may use TaskIDGroup to group a set of TaskIDs, but those TaskIDs might not necessarily be part of a multi-task.

Overrides:
isMultiTask in class TaskID<E>
Returns:
true if this TaskIDGroup represents an actual multi-task, false otherwise

add

public void add(TaskID<E> id)
Since:
10/05/2013 Do not set relative id here. Instead, before a TaskID is added into a group, a relative id should be given first. However if do not set relative id here, when trying to add a TaskID into a user defined group, this TaskID become untraceable through relative id. It still can be traced through its global id. Because of the same reason, do not set part of group here. Instead, set part of group when a multi task is expanded just like set relative id there. Maybe a good idea that only allow to call this method paratask runtime internally, which means it is used for multi task group only but not user defined group.

groupSize

public int groupSize()
Returns the group size.

Returns:
The group size.

reduce

public E reduce(Reduction<E> red)
         throws java.util.concurrent.ExecutionException,
                java.lang.InterruptedException
Perform a reduction on the set of results. A reduction is only to be performed once. If this is called a second time then the pre-calculated answer is returned.

Parameters:
red - The reduction to perform
Returns:
The result of performing the reduction on the set of TaskIDs contained in this group.
Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException

getInnerTaskResult

public E getInnerTaskResult(int relativeID)
                     throws java.util.concurrent.ExecutionException,
                            java.lang.InterruptedException
Returns the result of a particular task.

Parameters:
relativeID - The relative ID of the task whose result is wanted.
Returns:
The result for that task.
Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException
See Also:
CurrentTask.relativeID(), TaskID.relativeID()

groupMembers

public java.util.Iterator<TaskID<E>> groupMembers()
Return an iterator for the set of TaskIDs contained in this group.

Returns:
An iterator for this group of TaskIDs.

getException

public java.lang.Throwable getException()
Description copied from class: TaskID
Returns the exception that occurred while this task executed.

Overrides:
getException in class TaskID<E>
Returns:
The exception that occurred.

getReturnResult

public E getReturnResult()
                  throws java.util.concurrent.ExecutionException,
                         java.lang.InterruptedException
Get the result of a group of tasks. This is not a supported method for TaskIDGroup. To get the results, must either perform a reduction or get results of the individual tasks.

Overrides:
getReturnResult in class TaskID<E>
Returns:
The result of the task.
Throws:
java.lang.UnsupportedOperationException
java.util.concurrent.ExecutionException
java.lang.InterruptedException
See Also:
getReturnResult(Reduction), getInnerTaskResult(int)

getReturnResult

public E getReturnResult(Reduction<E> red)
                  throws java.util.concurrent.ExecutionException,
                         java.lang.InterruptedException
Perform a reduction on the results contained in the group.

Parameters:
red - The reduction to perform on the results of the contained TaskIDs
Returns:
The result after performing the specified reduction.
Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException

hasCompleted

public boolean hasCompleted()
Checks to see whether all the inner tasks have completed.

Overrides:
hasCompleted in class TaskID<E>
Returns:
true if it has completed, false otherwise
See Also:
TaskID.getProgress(), CurrentTask.getProgress()

hasUserError

public boolean hasUserError()
Checks to see whether any of the inner tasks contained an error.

Overrides:
hasUserError in class TaskID<E>
Returns:
true if there was an error, false otherwise

cancelAttempt

public boolean cancelAttempt()
Canceling a group is currently not supported. Users must cancel each inner task individually.

Overrides:
cancelAttempt in class TaskID<E>
Returns:
true if it has cancelled successfully, false otherwise.
Throws:
java.lang.UnsupportedOperationException
See Also:
TaskID.cancelRequested(), CurrentTask.cancelRequested(), TaskID.cancelledSuccessfully()

waitTillFinished

public void waitTillFinished()
                      throws java.util.concurrent.ExecutionException,
                             java.lang.InterruptedException
Waits for all the contained inner tasks to complete.

Overrides:
waitTillFinished in class TaskID<E>
Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException

setExpanded

protected void setExpanded(boolean isExpanded)
Since:
08/05/2013 After a multi task worker thread expand a mult task, call this method to set a "true" value.

getExpanded

protected boolean getExpanded()