This widget could not be displayed.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for a way to synchronize two subview at some point

Hi all,

  I have two individual subview, says SVA and SVB. They are place in the same code so they will run in parallel. SVA performs heave IO operation (read data from a big file) while SVB will run some code first, then it will use the data in read by SVA. Since SVA and SVB runs in parallel, it is hard to tell when SVB is able to read the data from SVA so I add a timer to wait some times before it reads the data from SVA.

 

the main program is like

 

 

in SVB, the code is like the follow, I add a timer to delay 35 secs so SVA will finish.

 

 

 

But if I do this way, the waiting time is not precise, if we set too short time, it will not works. If we set too long time, it works but wait too long. I am thinking to use sequence to resolve the problem

 

 

will this will solve the problem but since the first part of SVB also takes quite a long time. If I make SVA and SVB in sequence, it also wait so long to finish the code. I am thinking if it is possible to run SVA and SVB in parallel but in some way SVB can check if SVA finish so to advance to next step.

0 Kudos
Message 1 of 20
(3,376 Views)

The images you tried to insert into your post did not show up.  Did you use the "tree" icon in the toolbar at the top of the text box to insert the image?

 

Without the images it is difficult to tell what is happening.

 

From your description I sugest that you consider splitting SVB into two separate VIs. The fisrt would contain the code which can run in parallel with SVA. The second would use the output of SVA (and perhaps outputs from SVB_1) to complete the process. Then everything would be controlled by dataflow. No sequences. No timers. Minimal executon time.

 

Lynn

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

How are you passing data between your subVIs?  If you are using a queue, then you shouldn't have to worry about this timing.  SVA will write data into the queue when it is available and SVB will read data from the queue when the data becomes available.  If there is no data in the queue, SVB will sit there idle until there is data.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 20
(3,363 Views)

@johnsold wrote:

The images you tried to insert into your post did not show up.  Did you use the "tree" icon in the toolbar at the top of the text box to insert the image?

 

Without the images it is difficult to tell what is happening.

 

From your description I sugest that you consider splitting SVB into two separate VIs. The fisrt would contain the code which can run in parallel with SVA. The second would use the output of SVA (and perhaps outputs from SVB_1) to complete the process. Then everything would be controlled by dataflow. No sequences. No timers. Minimal executon time.

 

Lynn


Hi, it is weird. When I post that the images were there, I don't know why it all gone.

 

Here I post it again. Originally, I have two progra, SVA and SVB running in parallel

 

SVABO.jpg

 

and in SVB, the code looks like

 

SVB.jpg

 

I add the delay inbetween so it has enough time to wait SVA finish. However, the time change if the data length in SVA changed, so I can only use big number for estimation.

 

One way to resolve this issue is to put SVA and SVB in sequence

 

SVABN.jpg

 

But since some part in SVB (before the delay) will run for long time too. If I do this way, the total time to run the whole code is too long. I am looking for a way to run SVA and SVB in parallel but after the first part of SVB finished it wait until SVA to finish instead of using a 'random' delay to achieve it .

0 Kudos
Message 4 of 20
(3,352 Views)

@johnsold wrote:

The images you tried to insert into your post did not show up.  Did you use the "tree" icon in the toolbar at the top of the text box to insert the image?

 

Without the images it is difficult to tell what is happening.

 

From your description I sugest that you consider splitting SVB into two separate VIs. The fisrt would contain the code which can run in parallel with SVA. The second would use the output of SVA (and perhaps outputs from SVB_1) to complete the process. Then everything would be controlled by dataflow. No sequences. No timers. Minimal executon time.

 

Lynn


hi Johnsold, yes what you describe is correct. That's what I mean to do. Once I read your reply, I asked my lab supervisor and he said SVA is not going to pass anything to SVB but SVA will write all stuff to an external device in GBIP and the second part of SVB will not start until everything was sent to the device.

0 Kudos
Message 5 of 20
(3,351 Views)

Even if you do not pass any data from one subVI to the other, you can still use dataflow to control the sequence of the tasks. The error clusters are very useful for this.  In the image below SVB1 contains the code in the left frame of your sequence structure and SVB2 contains the code in the right frame. No sequence structures and no Wait required. SVB2 will not start until both SVA and SVB1 have completed.  SVA and SVB1 run in parallel because they do not depend on each other.

 

Lynn

 

dataflow.png

0 Kudos
Message 6 of 20
(3,310 Views)

@johnsold wrote:

Even if you do not pass any data from one subVI to the other, you can still use dataflow to control the sequence of the tasks. The error clusters are very useful for this.  In the image below SVB1 contains the code in the left frame of your sequence structure and SVB2 contains the code in the right frame. No sequence structures and no Wait required. SVB2 will not start until both SVA and SVB1 have completed.  SVA and SVB1 run in parallel because they do not depend on each other.

 

Lynn

 

dataflow.png


Thanks for the suggestion. It works well. But the only problem is for some reason, it is not feasible to break SVB into two separate code. But your code inspire me to use global variable to achieve it. Thanks anyway

0 Kudos
Message 7 of 20
(3,296 Views)

Global variables for passing changing data are usually a bad idea as they can lead to race conditions.

 

If SVB was really structured the way you showed it in an earlier post, it will definitely be separable.  Can you post SVB along with a description of what parts run parallel to SVA and what parts run after SVA?

 

Lynn

0 Kudos
Message 8 of 20
(3,292 Views)

@johnsold wrote:

Global variables for passing changing data are usually a bad idea as they can lead to race conditions.

 

If SVB was really structured the way you showed it in an earlier post, it will definitely be separable.  Can you post SVB along with a description of what parts run parallel to SVA and what parts run after SVA?

 

Lynn


I know it is not a good idea to use global variable. But up to now seems there is no other choice. Well, the real code of SVB is really a big one, it occupies almost 10 screens and there are so many subvis linking to that subvi. Not all vi using that SVB needs to worry about the time as described as in this post. But if I break that into too parts, all other vi linking to this one will be rewrite or relink or something anyway needed to be done. This is the problem of labview coding, so many cross-reference and I don't even dare to touch some critical code written by someone else in a big project.

0 Kudos
Message 9 of 20
(3,275 Views)

What you think if you use Rendezvous in your code.

Thanks and Regards
Himanshu Goyal | LabVIEW Engineer- Power System Automation
Values that steer us ahead: Passion | Innovation | Ambition | Diligence | Teamwork
It Only gets BETTER!!!
0 Kudos
Message 10 of 20
(3,270 Views)