LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

subVI inside loop memory

Solved!
Go to solution

Hello,

I have a loop that contains 3 subVIs that are exactly the same (that's why i use a subVI Smiley Wink ) Each subVI controls a device (again 3 devices that are the same). The inputs to each subVI come from a Mathscript node. So on every iteration of the loop (1s), the output of the Mathscript node will be input to the subVIs. 

The problem is that one of the 3 devices (the same one everytime) is giving an error after running for a few seconds. The error usually occurs because the device does not receive an acknowledgment message after 3 seconds of running. I renamed the subVI that controls that device, without changing anything to the code and everything seem to work normaly. Now since the subVIs are all the same, i interchanged two of them (the one that i renamed and another one) and the programs runs without problem.

 

I don't know how labview deals with same subVIs inside loops and this is what i am trying to find out. Even though the output of the Mathscript node occur at the same time (after the execution of all the node) and hence the input of the subVIs are all ready at the same time, the SubVIs seems to launch sequentially, or at least not instantaneously.

 The device that fires an error is the first to run and knowing that the subVI contains a time delay of 2000 ms, that device is not receiving acknowledgement after 3 s (because acknowledgment is sent on the next loop iteration, so the 3 subVIs should run first before the loop iterates). So here, i changed the subVI to decrease its time delay to 1710 ms, and use the same subVI for the 3 machines (without the unnecessary renaming) and the program works again without fault.

 

So i am just curious to know how Labview deals with same subvis that run simultaneously inside a loop. 

 

Thank you
0 Kudos
Message 1 of 7
(4,189 Views)

Please show us your code so we can better help you. Post a bunch of screen shots and let us know how they fit together.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 7
(4,182 Views)

Hey Beetho,

 

It sounds like the issue you facing is cause by the fact that your sub-vi is a non-reentrent VI. What this means is that only one instance of your sub-vi can be open at any given time. So, the sequential performance you are seeing with your three instances of your subvi would be expected. This same feature is what makes functional global variables a good way to protect critical code and avoid race conditions.

 

To avoid this sequential behavior, you could create three sub-vi's from your original sub-vi. This way you have the same code running, but they are actually different sub-vi's. Or, you could make your sub-vi a reentrant vi.

 

Hope this helps.
-Ben

WaterlooLabs
0 Kudos
Message 3 of 7
(4,150 Views)

Hello Ben,

 

The code is quiet long but i tried to make a very simple sketch of the stucture of the code. 

So you can see that 3 equivalent subVIs control 3 machines that get their input (start/stop, parameter, ...) from a MathScript node. As i wrote earlier, the machine should get the Ack message (on the next loop iteration) at most every 3 seconds, otherwise it fires an error. Second important fact is that every subVI includes a time delay. When that time delay was 2000 ms, the machine that started first fired an error because it did not receive its Ack within 3 sec. I could decrease the time delay to 1710 ms and all machines seem to start without errors.

 

To answer Ben's second post: as you said i think one instance of the subVI can be opened at a given time. Only opened but not executed until completion, right? otherwise the loop would have to wait for 3 x 1710 ms before the next iteration, which would cause an error again.

 

hope i clarified the situation as good as possible!

 

Thx 

Download All
0 Kudos
Message 4 of 7
(4,125 Views)
Solution
Accepted by Beetho

I have to agree with Ben. 

 

Mark your sub-VI as re-entrant to allow all three instance of the same VI to execute at the same time.

 

VI's by default are marked as not re-entrant so they have to take turns running the sub-VI.

 

In my Action Engine Nugget I included this image to illustrate how multiple calls to a  VI that is not re-entrant is shared between instances.

 

 

If you don't want to make the sub-VIs re-entrant you could also do a save As.. and use three identicle VI that differ only in name. I generally avoid this approach because code changes to the sub-VI require I edit all the different versions. Better to bite the bullet and learn how to set the VI as re-entrant. 

 

I hope that helps,

 

Ben

 

 

#10,000

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 7
(4,115 Views)

Hi,

 

I'm struggling with a similar problem which I've described in another Thread. I thought I'd ask here since it deals with a similar issue of re-entrant VIs. However, where mine differs is my identical SubVIs do not have loops inside of them. They all execute within the same outer loop of which they are all members. Is that a proper use of re-entrance?

 

The reason I asked is I've made my SubVIs re-entrant and "pre-allocated for each instance" but only the first one that loads seems to function properly, The rest seem to be acting like copies of the first which shouldn't happen because they're supposed to be working with different data (reading from different input channels). I can think of bugs (I'm not at work right now to check) which could also cause this problem but I just wanted to ask If I'm using the idea behind re-entrant VIs properly, even though these SubVIs do not execute their own loops but rather, work as single calls inside the main loop in which they all run.

0 Kudos
Message 6 of 7
(3,197 Views)

I replied in your other thread since re-entrant AE are a very unique challenge.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 7
(3,178 Views)