|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.util.Attribute
ptolemy.actor.Director
ptolemy.domains.ddf.kernel.DDFDirector
public class DDFDirector
The dynamic dataflow (DDF) domain is a superset of the synchronous dataflow(SDF) and Boolean dataflow(BDF) domains. In the SDF domain, an actor consumes and produces a fixed number of tokens per firing. This static information makes possible compile-time scheduling. In the DDF domain, there are few constraints on the production and consumption behavior of actors, and the schedulers make no attempt to construct a compile-time schedule. Instead, each actor has a set of firing rules (patterns) and can be fired if one of them is satisfied, i.e., one particular firing pattern forms a prefix of sequences of unconsumed tokens at input ports. The canonical actors in the DDF domain include Select and Switch, which consume or produce tokens on different channels based on the token received from the control port. You can also use the two-channel versions BooleanSelect and BooleanSwitch.
The dynamic scheduler implemented in this director fires all enabled and non-deferrable actors once in a basic iteration. A deferrable actor is one that will not help one of the downstream actors become enabled because that downstream actor either already has enough tokens on the channel connecting those two actors or is waiting for tokens on another channel. If no actor fires so far, which means there is no enabled and non-deferrable actor, then among all enabled and deferrable actors, this director fires those which have the smallest maximum number of tokens on their output channels which satisfy the demand of destination actors. If still no actor fires, then there is no enabled actor. A user can treat several such basic iterations as a single iteration by adding a parameter with name requiredFiringsPerIteration to an actor (which is often a sink actor or an actor directly connected to output port of the composite actor) and specifying the number of times this actor must be fired in a single iteration. If the value of the parameter runUntilDeadlockInOneIteration is a BooleanToken with value true, one single iteration consists of repeating the basic iteration until deadlock is reached (thus overriding the previous definition of one iteration), which is the status of the model where all active actors under the control of this director are unable to fire because their firing rules are not satisfied. However, they may be able to fire again during next iteration when tokens are transferred in from an outside domain. Note runUntilDeadlockInOneIteration can be set to true only when this director is not on the top level.
The algorithm implementing one basic iteration goes like this:
E = set of enabled actors D = set of deferrable enabled actorsOne basic(default) iteration consists of:
if (E\D != empty set) { fire (E\D) } else if (D != empty set) { fire minimax(D) } else { declare deadlock }The function "minimax(D)" returns a subset of D with the smallest maximum number of tokens on their output channels which satisfy the demand of destination actors.
Note that any SDF model can be run with a DDF Director. However, the notion of iteration is different. One could try to imitate the SDF iteration in the DDF domain by controlling the number of firings in one iteration for some actors, such as requiring a plotter to plot a fixed number of points in each iteration.
In the DDF domain, the firing rule of any actor is specified by the token consumption rates of its input ports. A general DDF actor could change the consumption rates of its input ports after each firing of this actor. For multiports, an array token could be used to specify different rates for different channels connected to the same multiport. Note that in SDF, all channels connected to the same multiport have the same rate.
Based on DDFSimpleSched in Ptolemy Classic, by Edward Lee. See E. A. Lee et al., "The Almagest," documentation for Ptolemy Classic, Vol. 1, Chapter 7, 1997.
Yellow (cxh) |
Yellow (zgang) |
Nested Class Summary | |
---|---|
private static class |
DDFDirector.ActorInfo
This private class is data structure for recording an actor's information during the execution. |
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private java.util.HashMap |
_actorsInfo
A HashMap containing actors' information. |
private java.util.LinkedList |
_actorsToCheckNumberOfFirings
A list to store those actors for which positive requiredFiringsPerIteration has been defined. |
private java.util.Set |
_disabledActors
The set of actors that have returned false in their postfire() methods and therefore become disabled. |
private boolean |
_firedOne
A flag indicating whether at least one actor has been fired so far. |
private boolean |
_isTypeResolutionDisabled
A flag indicating whether type resolution is disabled. |
private int |
_iterationCount
The number of iterations. |
private boolean |
_runUntilDeadlock
A boolean initialized with value in the parameter runUntilDeadlockInOneIteration. |
Parameter |
iterations
A Parameter representing the number of times that postfire() may be called before it returns false. |
Parameter |
maximumReceiverCapacity
A Parameter representing the maximum capacity of each receiver controlled by this director. |
Parameter |
runUntilDeadlockInOneIteration
A parameter indicating whether one iteration consists of repeated basic iterations until deadlock. |
Fields inherited from class ptolemy.actor.Director |
---|
_actorsFinishedExecution, _currentTime, _finishRequested, _initializables, _stopRequested, timeResolution |
Fields inherited from class ptolemy.kernel.util.NamedObj |
---|
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
Fields inherited from interface ptolemy.actor.Executable |
---|
COMPLETED, NOT_READY, STOP_ITERATING |
Constructor Summary | |
---|---|
DDFDirector()
Construct a director in the default workspace with an empty string as its name. |
|
DDFDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name. |
|
DDFDirector(Workspace workspace)
Construct a director in the workspace with an empty name. |
Method Summary | |
---|---|
protected boolean |
_fireActor(Actor actor)
Iterate the actor once. |
protected ActorEnablingStatus |
_getActorStatus(Actor actor)
Determine actor enabling status. |
private int[] |
_getTokenConsumptionRate(IOPort port)
Get token consumption rate for the given port. |
private int |
_getTokenConsumptionRate(Receiver receiver)
Get token consumption rate for the given receiver. |
private int[] |
_getTokenProductionRate(IOPort port)
Get token production rate for the given port. |
private void |
_init()
Initialize the object. |
protected boolean |
_isDeferrable(Actor actor)
Check each remote receiver to see whether the number of tokens in the receiver is greater than or equal to the tokenConsumptionRate of the containing port. |
protected boolean |
_isEnabled(Actor actor)
Check to see whether the actor is enabled. |
protected void |
_updateConnectedActorsStatus(Actor actor)
Update the enabling status of the given actor and all actors connected to this actor. |
void |
attributeChanged(Attribute attribute)
If the attribute being changed is runUntilDeadlockInOneIteration and it is set to be true, then verify this director is not at the top level. |
void |
disableTypeResolution(boolean flag)
Set the flag indicating whether type resolution is disabled or not. |
void |
fire()
Execute the model for one iteration. |
void |
initialize()
Initialize the model controlled by this director. |
void |
initialize(Actor actor)
Initialize the given actor. |
void |
invalidateResolvedTypes()
Call base class method to invalidate resolved types if the flag to disable type resolution is set to false. |
void |
merge(DDFDirector insideDirector)
Merge an opaque composite actor controlled by an inside DDFDirector with the outside domain controlled by this director. |
Receiver |
newReceiver()
Return a new QueueReceiver. |
boolean |
postfire()
Increment the number of iterations. |
boolean |
prefire()
Check the input ports of the container composite actor (if there are any) to see whether they have enough tokens, and return true if they do. |
java.lang.String[] |
suggestedModalModelDirectors()
Return an array of suggested directors to use with an embedded ModalModel. |
boolean |
supportMultirateFiring()
Return true to indicate that a ModalModel under control of this director supports multirate firing. |
boolean |
transferInputs(IOPort port)
Override the base class method to transfer enough tokens to complete an internal iteration. |
boolean |
transferOutputs(IOPort port)
Override the base class method to transfer enough tokens to fulfill the output production rate. |
Methods inherited from class ptolemy.kernel.util.Attribute |
---|
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public Parameter iterations
public Parameter maximumReceiverCapacity
public Parameter runUntilDeadlockInOneIteration
private boolean _isTypeResolutionDisabled
private boolean _firedOne
private int _iterationCount
private boolean _runUntilDeadlock
private java.util.HashMap _actorsInfo
private java.util.LinkedList _actorsToCheckNumberOfFirings
private java.util.Set _disabledActors
Constructor Detail |
---|
public DDFDirector() throws IllegalActionException, NameDuplicationException
IllegalActionException
- If the name has a period in it, or
the director is not compatible with the specified container.
NameDuplicationException
- If the container already contains
an entity with the specified name.public DDFDirector(Workspace workspace) throws IllegalActionException, NameDuplicationException
workspace
- The workspace of this object.
IllegalActionException
- If the name has a period in it, or
the director is not compatible with the specified container.
NameDuplicationException
- If the container already contains
an entity with the specified name.public DDFDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container of this director.name
- Name of this director.
IllegalActionException
- Not thrown in this base class.
May be thrown in the derived classes if the director
is not compatible with the specified container.
NameDuplicationException
- If the name collides with
an attribute that already exists in the given container.Method Detail |
---|
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class Director
attribute
- The changed parameter.
IllegalActionException
- If this director is at top
level and runUntilDeadlockInOneIteration is set to be true,
or getToken() throws IllegalActionException.public void disableTypeResolution(boolean flag)
flag
- The flag to be set.public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class Director
IllegalActionException
- If any actor executed by this
actor returns false in prefire().public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class Director
IllegalActionException
- If the initialize() method of
one of the associated actors throws it.public void initialize(Actor actor) throws IllegalActionException
initialize
in class Director
actor
- The actor to be initialized.
IllegalActionException
- If the
requiredFiringsPerIteration parameter does not contain
an IntToken.public void invalidateResolvedTypes()
invalidateResolvedTypes
in class Director
public void merge(DDFDirector insideDirector)
insideDirector
- The inside DDFDirector to be merged.public Receiver newReceiver()
newReceiver
in class Director
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class Director
IllegalActionException
- If the iterations parameter
does not contain a legal value.public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class Director
IllegalActionException
- If any called method throws
IllegalActionException.public java.lang.String[] suggestedModalModelDirectors()
suggestedModalModelDirectors
in class Director
Director.suggestedModalModelDirectors()
public boolean supportMultirateFiring()
supportMultirateFiring
in class Director
public boolean transferInputs(IOPort port) throws IllegalActionException
transferInputs
in class Director
port
- The port to transfer tokens from.
IllegalActionException
- If the port is not an opaque
input port, or if there are not enough input tokens available.public boolean transferOutputs(IOPort port) throws IllegalActionException
transferOutputs
in class Director
port
- The port to transfer tokens from.
IllegalActionException
- If the port is not an opaque
output port, or if there are not enough output tokens available.protected boolean _fireActor(Actor actor) throws IllegalActionException
actor
- The actor to be fired.
IllegalActionException
- If any called method throws
IllegalActionException or the actor is not ready.protected ActorEnablingStatus _getActorStatus(Actor actor) throws IllegalActionException
actor
- The actor to be checked.
IllegalActionException
- If any called method throws
IllegalActionException.protected boolean _isDeferrable(Actor actor) throws IllegalActionException
actor
- The actor to be checked.
IllegalActionException
- If any called method throws
IllegalActionException.protected boolean _isEnabled(Actor actor) throws IllegalActionException
actor
- The actor to be checked.
IllegalActionException
- If any called method throws
IllegalActionException.protected void _updateConnectedActorsStatus(Actor actor) throws IllegalActionException
actor
- The actor to te checked.
IllegalActionException
- If _getActorStatus(Actor) throws
IllegalActionException.private int[] _getTokenConsumptionRate(IOPort port) throws IllegalActionException
port
- The port to get token consumption rate.
IllegalActionException
- If parameter throws it or the
length of tokenConsumptionRate array is less than port width.private int _getTokenConsumptionRate(Receiver receiver) throws IllegalActionException
receiver
- The receiver to get token consumption rate.
IllegalActionException
- If any called method throws
IllegalActionException.private int[] _getTokenProductionRate(IOPort port) throws IllegalActionException
port
- The port to get token production rate.
IllegalActionException
- If parameter throws it
or the length of tokenProductionRate array is less
than port inside width or the port in the argument is
not an output port of the container of this director.private void _init() throws IllegalActionException, NameDuplicationException
IllegalActionException
NameDuplicationException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |