LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Run same vi multiple times simultaneously


@billko wrote:

Be aware that any non-reentrant code in your reentrant VI will cause waits as the requests for the non-reentrant code queue up.  This will cause all of the instances of your reentrant VI to wait on each other, almost as if they weren't reentrant.


Which means i have to make all VIs within VI1 reentrant too?

0 Kudos
Message 11 of 20
(1,545 Views)

@Wonano wrote:

@billko wrote:

Be aware that any non-reentrant code in your reentrant VI will cause waits as the requests for the non-reentrant code queue up.  This will cause all of the instances of your reentrant VI to wait on each other, almost as if they weren't reentrant.


Which means i have to make all VIs within VI1 reentrant too?


If you want full concurrency, yes. But please note that some VIs are used to share/store data on a global scope which will break when setting them to 'reentrant' (e.g. FGV/AE).

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 12 of 20
(1,538 Views)

It depends.  Even with multi-core processors, you can only have a few threads running truly simultaneously (they need to be on different cores), but LabVIEW is pretty good about time-slicing, particularly in recognizing which threads are "waiting" for something and thus can be temporarily kept "out of the loop".  In your case, you want to "share" the processing power so you can handle all of your satellites "simultaneously", i.e. have the processor automatically give each satellite a fair share of the CPU time so all the data from all the satellites get processed at the same rate.

 

Because you need to keep the data streams separate and isolated, you want N "independent" processes running simultaneously.  If you have a single Satellite Process, you can make a reentrant clone of it and simply clone it N times.  But what about its sub-VI's?

 

Things to consider are:  do the sub-VIs maintain internal data (i.e. are they Action Engines with data stored in Shift Registers between calls), do the sub-VIs deal with Satellite-specific hardware, or do the sub-VIs take appreciable time to do their task.  In the first two cases, you probably need to clone the sub-VI so that each Satellite Clone has its own "copy" of the sub-VI with the appropriate data or hardware links (this can get a bit tricky).

 

However, if all the sub-VI does is some computation or manipulation of its inputs, producing outputs, and does not save data internally, you probably can leave it as an "ordinary" VI, i.e. non-reentrant.  What does this mean?  Let's say this is a routine that takes an array of 1000 points and returns its Mean, Max, and Min.  This should take very little time (let's say 1 millisecond, though this is probably several orders of magnitude too high).  Let's say you have 10 Satellite clones, and they are taking data 10 times/second.  So every 100 milliseconds, a clone needs to call the sub-VI.  Ordinarily, this will "delay" the Clone 1 millisecond (as that's the time it takes for the sub-VI to work).  In the Worst Possible Scenario, all 10 Clones try to call this sub-VI at exactly the same time.  The first in line waits 1 millisecond, the second waits 2, and the 10th waits 10 milliseconds.  If we assume that the Clones are running asynchronously, the odds of two calling the sub-VI at the same time is rather small, so there may be an occasional "clash" resulting in an extra millisecond delay, but so what?

 

On the other hand, if the sub-VI takes an appreciable length of time (say it is doing disk i/o, and may need to open/close files or do some other possibly-lengthy operation), the second Clone will "get stuck" waiting for the first Clone to finish using the sub-VI if it is non-reentrant, i.e. if it is not using its own copy.  

 

BS

Message 13 of 20
(1,519 Views)

Just to add a point not yet mentioned-

 

"Reetrancy" has two flavors Shared Clones and Pre-allocated Clones: if you have a memory element (SR, FBN) you need to pre-allocate your reenterant clones.


"Should be" isn't "Is" -Jay
Message 14 of 20
(1,507 Views)

@JÞB wrote:

Just to add a point not yet mentioned-

 

"Reetrancy" has two flavors Shared Clones and Pre-allocated Clones: if you have a memory element (SR, FBN) you need to pre-allocate your reenterant clones.


I knew someone was going to bring that up.  I guess I was being lazy.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 15 of 20
(1,485 Views)

@billko wrote:

@JÞB wrote:

Just to add a point not yet mentioned-

 

"Reetrancy" has two flavors Shared Clones and Pre-allocated Clones: if you have a memory element (SR, FBN) you need to pre-allocate your reenterant clones.


I knew someone was going to bring that up.  I guess I was being lazy.


Not really "Lazy" the difference can cause you pain before you learn.  Or... A post on the forums could help set you straight!  Someone must have gone through that pain before!


"Should be" isn't "Is" -Jay
0 Kudos
Message 16 of 20
(1,476 Views)

@JÞB wrote:

@billko wrote:

@JÞB wrote:

Just to add a point not yet mentioned-

 

"Reetrancy" has two flavors Shared Clones and Pre-allocated Clones: if you have a memory element (SR, FBN) you need to pre-allocate your reenterant clones.


I knew someone was going to bring that up.  I guess I was being lazy.


Not really "Lazy" the difference can cause you pain before you learn.  Or... A post on the forums could help set you straight!  Someone must have gone through that pain before!


Hmmm... I think you just described exactly why I thought I was being lazy for not bringing it up when I knew that someone probably should have distinguished between the two from the start.

 

Anyway, it's good that you did bring it up because I think that distinction hasn't been made in the majority of posts that I've read about reentrancy.  Which is why you get the kudo from me.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 17 of 20
(1,461 Views)

Hello everyone,

 

If there is a real need for spawned parallel processes that behave "identical", then it might also be useful to take the Actor Framework into consideration.

However, this might be "overkill" if it can be resolved with making the subVI reentrant.

Tim: If the approach with the reentrant VI doesn't work, then please don't hesitate to share some code/example that shows the incorrect behavior with us.
In that case also include a description of how this wrong/incorrect behavior differs from the required behavior.

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
Message 18 of 20
(1,443 Views)

Hello all

 

May be it's the same question what is clear for averyone here, but new project makes new questions for me ))

 

I am tring to dev some data distribution system, where one vi gets data from hw to shared variable. It's compiled to app "sender.exe" The others should receive data and write it to serial ports.

 

Can this "receivers" vi's be the one vi, compiled to "receiver.exe" and executed many times with different settings (diff serial port number)? Or should i build many different vi (receiver1, receiver2, ... with actually the same content) into different .exe to run them at the same time?

 

The receivers number may vary at runtime, couse that i am asking for a best solution advice.

 

Please help)

0 Kudos
Message 19 of 20
(1,259 Views)
This is quite a different question. I recommend you start a new thread instead. Also provide more detail.
0 Kudos
Message 20 of 20
(1,256 Views)