LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

recursion with reentrant vi's

Hi all,
 
I have some problems with creating recursively function:
 
For example, I have 5 VI's that call each other in chain VI1->VI2->VI3->VI4->VI5->VI1->VI2...
 
At First , I made each VI as VIT and called them dynamically, it worked fine. But, calling VIT dynamically is very slow, so I've changed each VI to a reentrant and called them as is (not dynamically), and the recursion didn't worked.  Only if some VI's is VIT and some are reentrant, the recursion works.
 
I thought that calling VIT and reentrant VI works the same, can someone explain what is the difference between calling a reentrant and calling a VIT dynamically?
 
Nadav Chernin
0 Kudos
Message 1 of 13
(4,943 Views)
Hi Nadav,

check here:
Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 13
(4,935 Views)

Reentrant VIs and VITs are not the same. A reentrant VI a VI which has a seperate memory space allocated for each call that's made for it (i.e. if you call it in 5 different places in your code, the compiler will allocate 5 seperate memory spaces in advance for it). With a VIT, a full copy of the VI is made in memory when it is called (with a seperate front panel and everything and you can even save it). Doing this only when the VI is called takes a lot more time.

As for why it's not working - it should probably work if you make all the VIs reentrant and if you make sure you have 8 (prepare for reentrant exec) wired into the options input of the Open VI Reference function. Also, make sure that the VIs are completely dependent on their inputs.


___________________
Try to take over the world!
0 Kudos
Message 3 of 13
(4,909 Views)
Hi Nadav,
      I tried this too - using a reentrant VI recursively - and concluded that LabVIEW doesn't allow it.  But before replying to this thread, I found this which seems to confirm our experimental evidence.  Note the text in the second paragraph:
 
"The most often cited deficiency [with LabVIEW] is native recursion and recursive datatypes,.."
 
If you find a way, please share!
 
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 4 of 13
(4,885 Views)
TbD your right there is no native way to have recursion, but off course you can call your VI dynamically!



Ton:

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 5 of 13
(4,881 Views)

Hi TonP,

      Having just reinstalled my OS, LabVIEW (7.1) isn't installed yet, so I can't test this.  Assuming it works, thanks for the solution!

Cheers.

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 6 of 13
(4,879 Views)

Hey TonP,

      (If you're still around (?) ) What version of LabVIEW is your example from?  I'm using 7.1 and it refuses to allow a recursive Static reference! Smiley Sad

Is there a trick?

Cheers.

Message Edited by tbd on 01-20-2007 02:43 AM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 7 of 13
(4,767 Views)
A bit more info.
      I followed your example, TonP, and wired a VI name to Open, then right-clicked on the VI-type connector and created a constant.  This constant-reference let me make a recursive association!(?)  Still, when the diagram executes it produces the following error:
 
 
 
... regarding your example, I'm feeling a bit skeptical right now! Smiley Wink
(any ideas gratefully accepted)
 
Cheers.
 
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 8 of 13
(4,763 Views)
Hi tbd,

yes I'm still around Smiley Very Happy

I'm using 8.2, but I missed one thing in my screenshot that the VI options should be 0x8 (listed as action 7)
Another thing you can try is not using the VI name but the VI path to open it?

Ton
EDIT:
quicly build an example that runs on my LV OK:

Message Edited by TonP on 01-20-2007 02:15 PM

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 9 of 13
(4,752 Views)

Hi Ton,

      Huge THANKS!   - have recursion working under 7.1 now!  Awsome! Smiley Happy

I DID notice your instructions re option=8, but thought I knew what I was doing Smiley Tongue

... and used the IsReentrant property

Have realized that this doesn't work for recursive-call:

 

But this does!(?)

Will probably use the Open option=8 to avoid confusion!

Thanks again!

Message Edited by tbd on 01-20-2007 12:46 PM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Download All
0 Kudos
Message 10 of 13
(4,741 Views)