LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reentrancy for multiple operations

Hey everybody,
  I understand that there is a subtle dislike for reentrancy, and I can see how it could be a problem if you weren't careful with it.  However, I have a set of code that I need to run on six concurrent rigs from the same PC.  There are parts of it that I know I'll have to duplicate and change, but I was wondering: If there are VIs that I want to run multiple times concurrently and that shouldn't share data, is there a reason not to make them reentrant?  Is the overhead not worth it?


Message Edited by JeffOverton on 01-23-2008 10:15 AM
0 Kudos
Message 1 of 11
(4,015 Views)
I've had great success with a reentrant vi that was a TCP/IP data handler (since shared variables are still a work in progress).  Because part of the vi waits for the other computer to respond, running the vi iteravely for multiple communications (multiple compactRIO's) caused any delay from one computer to cause delays in all the rest.  I had to set up multiple identical while loops to talk to all the comactRIOs in parallel with the reentrant vi in the while loops.  NI application engineers couldn't think of any better way to do this, and I recommended a later version of Labview provide some sort of reentrant FOR loop structure that would allow you to do this with one structure instead of having to redraw the same loop for every instance of a reentrant vi.  I think the caution associated with reentrants pertains to the possiblity of having a runaway of multiple copies running, as opposed to your six.
0 Kudos
Message 2 of 11
(4,007 Views)

JeffOverton  asked "If there are VIs that I want to run multiple times concurrently and that shouldn't share data, is there a reason not to make them reentrant?"

No. That's why reentrant vis exist.

Reentrant vis are not bad, you just have to be carefull. Don't make a vi reentrant if there is no reason.

0 Kudos
Message 3 of 11
(4,000 Views)
Thanks, both of you.  I just wanted to double check, because there is a definite caution about them, but I had never heard anything specific.  I wasn't sure if it was as serious as globals, or just a "be careful" situation.
 
Thanks again.
0 Kudos
Message 4 of 11
(3,995 Views)

I think part of the confusion with reentrancy has to do with its changes through the history of LabVIEW. Before LabVIEW 8.0, you couldn't debug reentrant VIs, which made them much more difficult to use. Also, before LabVIEW 8.0, you couldn't view a reentrant VIs front panel, which made it impossible to use for dynamically spawned dialogs. That also made it difficult to do pseudo-debugging by viewing front panel controls to track the progress of the VI. The workaround in case of dynamically spawned dialogs was to use template VIs.

LabVIEW 8 helped make reentrancy more usable. You can now debug reentrant VIs (except when deployed to RT, I believe) and view their front panels. This makes them a more attractive option for dynamically spawned dialogs than template VIs. When opening a template VI, LabVIEW had to make a copy of the entire VI's data space, code, front panel, etc. With reentrant VIs in LabVIEW 8.x (to the best of my knowledge), LabVIEW only copies what's necessary. It doesn't need to duplicate the code itself, just the data space. And if the front panel isn't open, then LabVIEW doesn't need to copy that either for reentrant copies.

LabVIEW 8.5 added yet another piece to the puzzle for reentrancy. That's the ability to share clones. This might be confusing to some, but very powerful to others. Reentrant VIs allow you to call the same subVI concurrently in multiple places, but the downside is that every instance on the block diagram creates a separate copy of the necessary resources. So if you call your subVI in 100 different places, you'll get 100 copies, even if you only expect a few of those copies to ever execute concurrently.

The Share Clones option tells LabVIEW to only make copies when all the existing copies are in use and another call needs to be made. In other words, if I have 100 different calls to a Share Clones reentrant subVI, then LabVIEW will start off with only 1 copy of that subVI in memory. As soon as that copy is being called by A, and B wants to make a call to it, you'll get your second copy so B doesn't have to wait for A. If A finishes executing its copy, and C tries to call the subVI while B is still calling it, then C can call A's copy, since it's no longer in use. This allows a minimal amount of subVI resources to be loaded, while maintaining the ability to call a subVI concurrently.

The downside here is that you really don't know which copy you'll end up getting. A might get copy 1 now, but copy 2 or 3 later. This means you can't rely on cached data in the subVI,  such as uninitialized shift registers that store data from a previous run. You can't be sure that previous run was your previous run, or if this copy has ever had a previous run.

Sorry if this post is more confusing than helpful, but reentrancy is a powerful tool that should be explored.

Jarrod S.
National Instruments
Message 5 of 11
(3,978 Views)
Thank you, for explaining Jarrod
0 Kudos
Message 6 of 11
(3,956 Views)

Actually, one more question.  Can a reentrant VI call a non-reentrant VI?

I have several test VIs that ensure conditions are proper for the next step, and they are reentrant because they depend only on previously passed data.  However, my fault handler calls on a non-reentrant functional global VI (unique for each fixture) to store the fault data for processing.  With the exception of maybe waiting a few milliseconds, is there anything unfortunate that might happen in this scenario?

0 Kudos
Message 7 of 11
(3,933 Views)
If you're fine with waiting a few milliseconds, then no, nothing bad will happen. You can basically think of two reentrant copies of a VI as being two separate subVIs, for all practical purposes.
Jarrod S.
National Instruments
0 Kudos
Message 8 of 11
(3,925 Views)


Jarrod S. wrote:
You can basically think of two reentrant copies of a VI as being two separate subVIs, for all practical purposes.

That's a great explanation which really simplifies things when people ask this question. Unfortunately, as you mentioned, with the new pool sharing option that's not always strictly true, but it's a good way of explaining it to people.

___________________
Try to take over the world!
0 Kudos
Message 9 of 11
(3,920 Views)

I am trying to control a step motor type NMB PM55L-048 (I just want simple CW, CCW and change velocity).

I am using LabVIEW 8 with NI USB 6251 and  Darlington array ULN 2064.

 

I already have all the electrical connections.

I just need the Block Diagram and Front Panel for LabVIEW 8.

 

Who can help me?

 

Telmo.santos@ist.utl.pt

 

Thank you.

0 Kudos
Message 10 of 11
(3,916 Views)