LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to exchange data between parallel running subVIs

Hi all,

In my App I've got 4 subVIs running in parallel with while loops inside. Can you tell me the best way to communicate between them? For example a while loop in subVI_1 has to process the data from the while loop in subVI_2. Or while loop in main VI has to pass information to all subVIs to stop while loops an terminate operation.

My current solution is:

- in main VI I initialize a cluster with all data and control signals

- I pass to subVIs Reference of this cluster

- in subVIs I read / write to the cluster using Property Node and bundle/unbundle

 

I've tried ques but this solution seems to be cleaner for me. Can I do it better?

0 Kudos
Message 1 of 14
(3,846 Views)

reading/writing property nodes sometimes are slow, using queues are better.
Read/write pr.node only when something changed, i mean

0 Kudos
Message 2 of 14
(3,834 Views)

Hi Tomasz,

 

For example a while loop in subVI_1 has to process the data from the while loop in subVI_2.

Use a queue.

Think Producer-Consumer structure…

 

Or while loop in main VI has to pass information to all subVIs to stop while loops an terminate operation.

Use a notifier.

Or a global variable. (In WORM aka "write once read many" mode.)

Or stop the subVIs when the producer queue is killed…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 14
(3,821 Views)

Hi,

 

basically it seems as though you're using the cluster as a global variable and passing references to subvis to modifify the global variable.   If you want to use a global variable, just do that, no need for references.

 

That being said, global variables are usually a bad thing.  Funny things start to happen when you read/write from different locations in your code, like race conditions.  For passing data between loops, I would suggest queues, or channels.  Evaluate them, they are made for this kinda thing.

 

For your termination, I've always used a notifier.  I encapsulated this in an api which had 4 subvis (init, read termination notifier, write termination notifier, close).  This way, you have the notifier code centralised and can also react to any errors that might be passed.  

 

Depending on your requirements, there isn't a one-stop answer.  What I do know is that global variables tend to be a bad thing if not used properly.

0 Kudos
Message 4 of 14
(3,818 Views)

here's the example.

Yes it looks like a Global Variable but it's much faster (I've tested the performance)

The thing is that there's no an easy classification producer - customer. In target applications each while loop can produce something and be a customer for a data. So it need to access something and it need to be able to write its' own data. I'm passing the "terminate" information in cluster since it's already there and it costs me nothing to do it.

0 Kudos
Message 5 of 14
(3,808 Views)

Hi Tomasz,

 

The thing is that there's no an easy classification producer - customer. In target applications each while loop can produce something and be a customer for a data.

This leads to a discussion about using the proper code architecture…

 

So it need to access something and it need to be able to write its' own data.

What about CVT (current value tables) aka TagBus aka VariantAttributes implementations?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019