Jump to content

How to call a reentrant subvi for each member of an array parallel.


Recommended Posts

I have a subvi A which takes as an input an arbitrary sized array of double values. The subvi A calls a subvi B which is a reentrant.

Now I would like to call the subvi B for each double member of the input array. This would be no problem if I could use for loop.

However I want call the subvi B for each double member simultaneously. The subvi B has an output value.

A parallel for loop could be a solution, but that is only available in LabVIEW 2009.

Is there anyway to do this with labVIEW 7.1? Sounds something that could maybe be done with dynamically called subvis, but Is there any neater way?

Link to comment

Are you sure there is no way VI B can't operate on the array?

If not then I think you will have to put n instances of B on A's block diagram. (This is annoying and even more trouble since you don't know the array size ahead of time. If you at least can bound the array size you can use case structures, but this is ugly.) If there is any way to operate on the array that is the way to go!

Link to comment

I'd be surprised if a parallel loop would be ideal for this case since you can't define the array size.

I'd use VI Server to launch up to N versions of the VI asynchronously. SubVI A takes the array, iterates on each element. Each iteration opens a reference to the VI, supplying the proper argument to prepare it for re-entrancy (Options |= 8), sets the appropriate control values via an invoke node, then the VI is started (also via an invoke node) instructing it to not wait for a return. Return values could be handled via a queue, which SubVI A would have to properly reassemble in the correct order before it returns.

Ugly? Depends on your point of view. The only thing I don't like about this method is how you have to pass parameters by setting control values via an invoke method. Slow and clumsy, I don't know how well it would work in a tight loop. What I've always wanted was the ability to do stuff like this directly via the Call By Reference primitive, but that can't handle asynchronous calls.

Link to comment

I'd be surprised if a parallel loop would be ideal for this case since you can't define the array size.

I'd use VI Server to launch up to N versions of the VI asynchronously. SubVI A takes the array, iterates on each element. Each iteration opens a reference to the VI, supplying the proper argument to prepare it for re-entrancy (Options |= 8), sets the appropriate control values via an invoke node, then the VI is started (also via an invoke node) instructing it to not wait for a return. Return values could be handled via a queue, which SubVI A would have to properly reassemble in the correct order before it returns.

Ugly? Depends on your point of view. The only thing I don't like about this method is how you have to pass parameters by setting control values via an invoke method. Slow and clumsy, I don't know how well it would work in a tight loop. What I've always wanted was the ability to do stuff like this directly via the Call By Reference primitive, but that can't handle asynchronous calls.

The Open VI Reference function is a very bad function to call in a tight loop. Don't do that ever as it needs to execute in the UI thread and will slow down your loop tremendously.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.