LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Recursion

Hello,

 

I have a logic with recursion involving 2 subVIs (say A and B)

Will setting them both pre-allocated reentrant good Or should one of them be declared as shared clone and the other pre-allocated reentrant?

 

Thanks,

 

 

0 Kudos
Message 1 of 20
(2,506 Views)

Any VI that can call itself or that can be called by one of its subVIs is recursive and must be reentrant with shared clones, because the number of needed clones is not known in advance. Other subVIs can have any execution mode, so I guess answer 2.

Message 2 of 20
(2,481 Views)

Please describe your "logic with recursion".  In other words, what (exactly) are you trying to compute?  Asking such vague questions that you've been posing on the Forum are quite unusual ...

 

Bob Schor

0 Kudos
Message 3 of 20
(2,461 Views)

Hi Bob,

 

These vague questions are the ones which have perplexed me during CLA-R exam.

There is not much info with them.

0 Kudos
Message 4 of 20
(2,454 Views)

@raphschru wrote:

Any VI that can call itself or that can be called by one of its subVIs is recursive and must be reentrant with shared clones, because the number of needed clones is not known in advance.

Real question here b/c curious.

 

My thinking is that recursion often (usually?) involves maintaining internal state in the higher level clone as it "calls itself" as a lower level clone.   Thus, I'd expect that shared clones could lead to real trouble.

 

On the other hand, I don't think I have a good working theory for how preallocated clones can properly deal with the "unknown number" issue.

 

I toyed with a little recursion once upon a time, but mainly just for kicks.  I think that back at that time, I only *ever* chose preallocated clones (or perhaps it was before the shared clone option even existed?).  But the details are lost to the fog of time.

 

Anyone already have a MWE to demonstrate the right choice and show the pitfalls of the wrong one?

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 5 of 20
(2,416 Views)

Class member clones are required to be shared, and I know for sure they work fine for multiple (unknown number) levels of reentrancy.

 

If you put a 'normal' (no class member) pre-allocated reentrant VI in its own call chain, at any level, you get an error:

wiebeCARYA_0-1702396272199.png

If it's shared reentrant, it works fine.

 

This is rather simple to try...

 

You can however make the top level VI preallocated, and the 2nd level shared. Because the 2nd is shared, it breaks the problem and the main is not broken.

 

So, the answer AFAIK is shared reentrancy.

Message 6 of 20
(2,406 Views)

@Kevin_Price wrote:

My thinking is that recursion often (usually?) involves maintaining internal state in the higher level clone as it "calls itself" as a lower level clone.   Thus, I'd expect that shared clones could lead to real trouble.

 

On the other hand, I don't think I have a good working theory for how preallocated clones can properly deal with the "unknown number" issue.


Yes, it's quite important to keep the data at a higher level (or sent in as a parameter) to allow the code to be shared.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 20
(2,402 Views)

@Kevin_Price wrote:

On the other hand, I don't think I have a good working theory for how preallocated clones can properly deal with the "unknown number" issue.


Quite simplistically I think.

 

The code executes. When it calls a subVI, if it's a clone it allocates dataspace for a pre-allocated clone or re-uses dataspace for a shared clone if one is available. Repeat until done.

0 Kudos
Message 8 of 20
(2,392 Views)

Might be helpful- there's some good discussion in this thread.

Message 9 of 20
(2,386 Views)

@BertMcMahan wrote:

Might be helpful- there's some good discussion in this thread.


That's funny.

0 Kudos
Message 10 of 20
(2,381 Views)