From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

AF vs Preallocated Clones in S&V

Hello there,

It was great to meet many of you in Geneva a few weeks ago. 

I have a pretty large AF project underway and I've just realised I've got a pretty awful problem - I have a bunch of actors that are dynamically launched to support different measurement types (eg names 'Live FFT - Accelerometer', 'CPB Measurement - Microphones') and I'm using VIs from the Sound & Vibration Toolkit for tasks such as the FFT/CPB averaging. I just momentarily wondered why when I launched a second live FFT actor the FFT averaging kept reseting but of course these S&V VI's are stateful and require preallocated clones, whereas of course I have to use shared clones for my dyamic dispatch methods.

Is there anything to be done to square this circle, other than me making stateless versions of the problem VI's (which I really don't want to do)?

Thanks,

Martin

Message 1 of 13
(8,271 Views)

Thanks, I was reading through your post before I posted this and adding the relevent kodus.  I think I'm in denial at the moment. I guess if I have to make stateless versions it isn't so bad, it's just not ideal for a Friday evening realisation.

0 Kudos
Message 3 of 13
(4,418 Views)

Yes, there is one strategy.

Take your stateful S&V VI. Open a VI reference to it in your caller actor. Before you launch a nested actor, write that VI refnum into the nested actor. When the nested actor needs to invoke the S&V VI, it calls the VI refnum through a Call By Reference.

When your nested actor quits, the caller actor gets the VI refnum back in the Last Ack message. When the caller is ready to launch the next nested actor, it gives it the same S&V VI refnum.

In this way, you keep using the same stateful S&V VI across multiple actor launches.

0 Kudos
Message 4 of 13
(4,418 Views)

There is a second approach:

Create a non-reentrant wrapper VI that has the S&V VI on its block diagram. That gives you one clone of the S&V VI. Use that same wrapper VI in all of your nested actors. As long as you only have one nested actor running at a time, they all use the same instance. If you have N sets of mutually exclusive actors, create N wrapper VIs.

0 Kudos
Message 5 of 13
(4,418 Views)

AristosQueue wrote:

Open a VI reference to it in your caller actor.

You can also just have a static VI reference in the Actor Core of the launched actor (no need to "Open" a reference) and pass that into the Actor object.  Then each Actor Core will have its own copy of the fully reentrant subVI.

0 Kudos
Message 6 of 13
(4,418 Views)

drjdpowell wrote:

You can also just have a static VI reference in the Actor Core of the launched actor (no need to "Open" a reference) and pass that into the Actor object.  Then each Actor Core will have its own copy of the fully reentrant subVI.

He's trying to get them to all share the same instance... the bug is coming from each one having its own currently.

0 Kudos
Message 7 of 13
(4,418 Views)

Thank you both very much, this has cheered me up no end.  I opened a static VI reference to the S&V VI within the measurement actor's Pre Launch Init and I was then able to use it in my ProcessRawData method with the Call By Reference Node. I then closed the reference in the actor's Handle Last Ack Core.  I can launch multiple instances of the actor and it works perfectly.

I  tried not opening the reference and just passing in the static vi reference constant but that gave an error in the Call By Reference node 'invalid reference', I guess I'm missing something? I'm happy with either method anyway, it is great news that it works. Time for a celebratory beer. Thanks again for the help.

0 Kudos
Message 8 of 13
(4,418 Views)

AristosQueue wrote:


He's trying to get them to all share the same instance... the bug is coming from each one having its own currently.

Oh, I thought the issue was that he was calling preallocated clones from within the shared-reentrant methods, and that he really wants a separate clone associated with each actor.

Martin, if one method works there is little reason trying for the other, but I believe just using a static reference should work also.  In either case your just explicitly getting a specific clone and attaching it to the Actor object.

0 Kudos
Message 9 of 13
(4,418 Views)

Ah, I misread his intent, too. My problem was trying to get simultaneously running actors to each get their own instance with some VIs that were non-reentrant and stateful.

0 Kudos
Message 10 of 13
(4,418 Views)