Hi all,
I feel like this brings yet another problem.
Suppose you have a dataflow graph that looks like:
-------- -----------------
| A |--------->| |
-------- | BooleanSelect |--->
+---->| |
-------- | -----------------
| B |----|
--------
In the case where A sends a token at time t, it means that you actually
wouldn't have to compute B at all since you know it will be flushed. The
same problem arises with logical operators (e.g. AND, OR) and IFs. I'm
worried about these issues since it has real consequences when dealing
with real-time video for instance. Imagine A and B compute video and
replace the BooleanSelect by a VideoSwitch actor that would allow you to
choose wether you play A or B. In that case you need to know that you
actually don't need to compute one of the two branches.
Is there a solution for this in PtII? Is there a domain that can deal
with these issues?
Thanks,
++ js
Richard van der Laan wrote:
Hello,
I want to share a problem I ran into while executing a model containing an
instance of the BooleanSelect actor.
In my scenario I embedded the Ptolemy kernel as a precalculation engine to
render motion setpoints
for servomotors. Here the setpoints are eventually buffered in actors which
abstract the servos.
The model execution thread is temporary paused when the buffers are full and is
continued after hitting a certain
buffer threshold. Meanwhile in a different thread, batches of these buffered
setpoints are dispatched
to the servos. The execution of this process can last for hours.
I discovered that only when my model contains a BooleanSelect actor the vm will
eventually run out of memory.
After some profiling I traced the problem down to one of the receiver queues of
the BooleanSelect actor.
The PTII6 beta code shows that depending on the control state, either tokens of
trueInput or falseInput will be used:
public void fire() throws IllegalActionException {
super.fire();
if (_control) {
// Redo this check in case the control has changed since prefire().
if (trueInput.hasToken(0)) {
output.send(0, trueInput.get(0));
}
} else {
if (falseInput.hasToken(0)) {
output.send(0, falseInput.get(0));
}
}
}
When the control state of the actor is true for all model iterations, only the
tokens of trueInput are removed
from the underlying receiver queue. This means that all falseInput tokens
remain in the other receiver queue, which
will eventually lead to an out of memory. I fixed this problem by removing
tokens from both the true and false inputs.
Depending on the control state, either the true or false tokens are send to the
output:
public void fire() throws IllegalActionException {
final boolean trueInputHasToken = trueInput.hasToken(0);
final boolean falseInputHasToken = falseInput.hasToken(0);
Token trueInputToken = null;
Token falseInputToken = null;
if (trueInputHasToken) {
trueInputToken = trueInput.get(0);
}
if (falseInputHasToken) {
falseInputToken = falseInput.get(0);
}
if (_control) {
// Redo this check in case the control has changed since prefire().
if (trueInputHasToken) {
output.send(0, trueInputToken);
}
} else {
if (falseInputHasToken) {
output.send(0, falseInputToken);
}
}
}
I'm not sure if I discovered a bug in the original implementation, but
nevertheless I like to share this with you all.
Kind regards,
Richard van der Laan, Luminis
Mobile: +31 (0)65 105 22 57
Office: +31 (0)26 365 34 70
Email : [EMAIL PROTECTED]
TheWeb: http://www.luminis.nl
LOSS : https://opensource.luminis.net
----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list. Please send administrative
mail for this list to: [EMAIL PROTECTED]
--
J. S. Senécal
http://drone.ws
----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list. Please send administrative
mail for this list to: [EMAIL PROTECTED]