Package edu.rit.pj
Class ParallelTeam
java.lang.Object
edu.rit.pj.ParallelTeam
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
ConstructorDescriptionConstruct 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 TypeMethodDescriptionfinal void
execute
(ParallelRegion theRegion) 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.final ParallelRegion
region()
Returns the parallel region of code that this parallel team is executing.void
shutdown()
Kills the team's threads run() methods so that they are no longer GC roots.
-
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 theRuntime.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
Execute the given parallel region.- Parameters:
theRegion
- Parallel region.- Throws:
NullPointerException
- (unchecked exception) Thrown iftheRegion
is null.IllegalStateException
- (unchecked exception) Thrown if this parallel team is already executing a parallel region. Thrown iftheRegion
is already being executed by a parallel team.Exception
- Exception thrown by the parallel region'sstart()
,run()
, orfinish()
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
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 theRuntime.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
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.
-