Package edu.rit.pj

Class ParallelTeam

java.lang.Object
edu.rit.pj.ParallelTeam

public class ParallelTeam extends Object
Class ParallelTeam provides a team of threads for executing a ParallelRegion in parallel.

To execute a parallel region, create a ParallelTeam object; create an instance of a concrete subclass of class ParallelRegion; and pass this instance to the parallel team's execute() method. For further information, see class ParallelRegion.

Version:
19-May-2008
Author:
Alan Kaminsky
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a new parallel team with the default number of threads.
    ParallelTeam(int K)
    Construct a new parallel team with the given number of threads.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Execute the given parallel region.
    static int
    Determine the default number of threads for a parallel team.
    final int
    Determine the number of threads in this parallel team.
    final boolean
    Determine if this parallel team is executing a parallel region.
    Returns the parallel region of code that this parallel team is executing.
    void
    Kills the team's threads run() methods so that they are no longer GC roots.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ParallelTeam

      public ParallelTeam()
      Construct a new parallel team with the default number of threads. If the "pj.nt" Java property is specified, that property gives the default number of threads, which must be an integer greater than or equal to 1. If the "pj.nt" Java property is not specified, the default number of threads is the value returned by the Runtime.availableProcessors() method. You can specify the default number of threads on the Java command line like this:
           java -Dpj.nt=4 . . .
       
      Throws:
      IllegalArgumentException - (unchecked exception) Thrown if the "pj.nt" property value is not an integer greater than or equal to 1.
    • ParallelTeam

      public ParallelTeam(int K)
      Construct a new parallel team with the given number of threads.
      Parameters:
      K - Number of threads.
      Throws:
      IllegalArgumentException - (unchecked exception) Thrown if K is less than 1.
  • Method Details

    • execute

      public final void execute(ParallelRegion theRegion) throws Exception
      Execute the given parallel region.
      Parameters:
      theRegion - Parallel region.
      Throws:
      NullPointerException - (unchecked exception) Thrown if theRegion is null.
      IllegalStateException - (unchecked exception) Thrown if this parallel team is already executing a parallel region. Thrown if theRegion is already being executed by a parallel team.
      Exception - Exception thrown by the parallel region's start(), run(), or finish() methods.
      Exception - if any.
    • isExecutingInParallel

      public final boolean isExecutingInParallel()
      Determine if this parallel team is executing a parallel region.
      Returns:
      True if this parallel team is executing a parallel region, false otherwise.
    • region

      public final ParallelRegion region()
      Returns the parallel region of code that this parallel team is executing.
      Returns:
      Parallel region.
      Throws:
      IllegalStateException - (unchecked exception) Thrown if this parallel team is not executing a parallel region.
    • getThreadCount

      public final int getThreadCount()
      Determine the number of threads in this parallel team.
      Returns:
      Number of threads in the team.
    • getDefaultThreadCount

      public static int getDefaultThreadCount()
      Determine the default number of threads for a parallel team. If the "pj.nt" Java property is specified, that property gives the default number of threads, which must be an integer greater than or equal to 1. If the "pj.nt" Java property is not specified, the default number of threads is the value returned by the Runtime.availableProcessors() method. You can specify the default number of threads on the Java command line like this:
           java -Dpj.nt=4 . . .
       
      Returns:
      Default number of threads for a parallel team.
      Throws:
      IllegalArgumentException - (unchecked exception) Thrown if the "pj.nt" property value is not an integer greater than or equal to 1.
    • shutdown

      public void shutdown() throws Exception
      Kills the team's threads run() methods so that they are no longer GC roots. Useful if you are repetitively constructing ParallelTeam objects, although it is slightly more elegant just to keep the same ParallelTeam objects through the entire execution of a program.
      Throws:
      Exception - if any.