LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute a reentrant vi?

Hello,

i am playing the first time with reentrant VIs.

For this i created a normal vi with a loop that opens n-times a reentrant-subvi.

The subvi contains only a Popup and a delay.

 

My thought was now that the subvi-popups are now opened all at the same time.

But actually the popups are appearing all one after one.

 

Whats wrong with my example?

 

Thanks for help

Download All
0 Kudos
Message 1 of 14
(4,239 Views)

OnlyOne,

 

A single reentrant VI instance is created for every time the reentrant VI is placed on a block diagram. Even if you call the reentrant VI in a loop, there is only one instance on the block diagram.

 

To start multiple instances from within a loop, you will need to call the reentrant VI with VI server.

 

There are two ways to do this; use standard VI rerences or strictly typed references. Strictly typed references are more convenient beacuse you can use the Start Asynchronous Call primitive to pass arguments to the reentrant VI instance when you call it. Note the options values passed to Open VI Reference.

 

reentrant options.png

~~
Message 2 of 14
(4,230 Views)

You misunderstood the concept of reentrant VIs.

The purpose of reentrant VIs is to execute the code in parallel with several instances while each instance keeps its own private data. It is no concept to "multiply GUIs" (aka front panels) by design (even though through "clones" you can get several GUIs).

 

Also, your example has the subVI as a static call in the loop. Therefore, dataflow requires the subVI to finish before the main VI can execute the next iteration (=> SubVI call!) of the loop. So in your use case, even disregarding above mentioned misunderstanding, a reentrant VI behaves exactly like a non-reentrant VI. You have to have different instances of calls in parallel to see a difference.

 

Norbert

 

EDIT: You can also spawn concurrent clones by placing static calls in parallel. The examples nick is providing are useful if you want to call clones dynamically as for instance it is common in application launchers.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 3 of 14
(4,228 Views)

My VIs are working if i change the For-Loop to "[X] enable loop interation parallelism".

Thanks for your examples.

0 Kudos
Message 4 of 14
(4,218 Views)

Hi nickf,

i am using now your option 2.

There is only one "Stativ VI reference" on the beginning. Question is:

Are all subvis of this vi also running parallel then?

How can i check if one/all "Start Asynchronous Call" is/are finished?

 

Thanks

 

0 Kudos
Message 5 of 14
(4,193 Views)

Wait on asynchronos call.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 14
(4,182 Views)

That means if i want to use the "Wait Async..." then i have to save all the references from the "Start Async...."?

 

I added a waittime of 6secs in my subvi that is started multiple times in a loop.

I thought because all VIs are started at the same time that i only have on time th 6secs delay (plus some milliseconds for execution).

But it looks different.

Can someone take a look in this example?

 

The Loop-Vi is starting in a while-loop the "Sub.vi" for three times.

Into the subvi i pass the index of the wile loop.

Inside of the sub-vi i use the index-parameter to access variables from a Global-vi that are used to popup a message with the conent of the array and the Index/Loop-Counter to see that the values are different.

After the popup there is in sequence to a 6secs waittime.

 

So when running the loop-vi there appear some popups. The Loop-vi is finished then and the popups keep on appearing as the sub-vis are not finished yet.

But the question is: Is there something wrong if doing it like this or why is it so slow? It is not really a parallel execution of the subvis.

 

Thanks for testing.

best regards

 

0 Kudos
Message 7 of 14
(4,173 Views)

OnlyOne,

 

Correct. If you use Wait on Async... then you have to keep track of the references. Furthermore, the wait functions will all happen synchronously so your main VI will have to wait until all reentrant VI instances are complete before returning. You need to use a different technique to collect results asynchronously.

 

Try something like the pattern shown in the following screen shots. The main idea is to pass an event or queue reference to the reentrant VI, then collect the results in the main VI. You can use a queue instead of a user event. I typically use user events because they're more flexible. 

 

Set the "Show front panel when called" and "Close afterwards if originally closed" view options on the reentrant VI to show each reentrant instance front panel.

 

async2_a.png

async2_b.png

~~
0 Kudos
Message 8 of 14
(4,157 Views)

Hello again,

 i tried now the Wait on Async - but i get an error.

i only need to know when is everything finished. No FP or result are needed.

Thx for help

0 Kudos
Message 9 of 14
(4,064 Views)

The error message is quite clear, isn't it?

Instead of 'x80' as option for the Open VI Reference, you have to use 'x100'....

 

Please refer to the help of Open VI Reference for detailed information.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 10 of 14
(4,059 Views)