LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ending multiple loops when the first loop ends

Hi,

i am not sure how this can be done easily, however if i have 4 loops doing the same task, how can i end the 3 remaining loops when the first one has finished?  please take a look at the vi it is 4 loops all looking for a a certain random number.  every time it is run a different loop will find the number first and stop, how can i use that to then to stop the other loops early to save them doing unwanted tasks?

 

every method i come up with relies on dataflow and therefore all loops have to finish for the dataflow to continue, i cant use variables, i tried with semaphores. 

 

what ever method is used would need to scale up ie have more loops

 

i am wondering if labview has something to do this that i am not aware of?

0 Kudos
Message 1 of 7
(1,379 Views)

Create a notifier and pass the reference to each loop. Whenever a loop completes, it will send a notification. Each loop will check for a notification every iteration. You can use a 0 for the timeout value and ignore the value if the read notification timed out. After all of the loops complete after receiving the notification you can then destroy the notifier.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 7
(1,373 Views)

Can you explain in more detail what problem you are trying to solve, because your example makes little sense?

 

  • Why can't you use one loop where you generate all four numbers?
  • Why do you use greedy loops?
  • Please explain the real application where you need whatever you are trying to do. II am sure there are better ways.

 

(And, yes, there are plenty of ways to communicate across loops)

 

0 Kudos
Message 3 of 7
(1,340 Views)

@altenbach wrote:

 

  • Why can't you use one loop where you generate all four numbers?

Here's how that could look like. Note that you can easily expand it to 100 or 1000 numbers, which would be very difficult with your approach. Scalability!

 

altenbach_1-1623078969276.png

 

 

 

Message 4 of 7
(1,332 Views)

Thanks for your replies,

 

i am just trying to understand parallel processing.  i was trying to see if you have multiple loops is it running the loops serially  or  in parallel. so no real application in mind.  

 

the test was to look for a precise random number and time hope long it took and then keep adding more loops and timing it to see what makes a difference, so just a self learning exercise.

 

i did get it to work with the notifier however if there is a more efficient faster way (in terms of processing speed) then i would he happy to know how to do it. 

 

 

0 Kudos
Message 5 of 7
(1,277 Views)

Well, you could use a global variable... With care this could be an acceptable solution.

 

One way of enforcing reasonable use is to put the global variable in a library, and providing a public (make it preallocated reentrant) VI that reads the variable.

Make the variable itself private, and create a "Set" VI that changes it to true or false.

Perhaps make the setter community scope, and list the VIs that can use it (doesn't help if you only have one VI).

 

Then you can read your global variable anywhere, but only write it in specific locations, reducing the typical problems associated with global variables, like race conditions.

cbutcher_0-1623144420068.png

 

cbutcher_1-1623144447278.png

 

 


GCentral
0 Kudos
Message 6 of 7
(1,268 Views)

@Dave76 wrote:

...

every method i come up with relies on dataflow and therefore all loops have to finish for the dataflow to continue, i cant use variables, i tried with semaphores. 

 

Channel wires do not rely on dataflow. Here's a quick hack. It's a tag channel that sets the abort flag, and all loops check that flag:

thols_0-1623146541983.png

 

Certified LabVIEW Architect
0 Kudos
Message 7 of 7
(1,262 Views)