LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

for loop iteration parallelism - stopping

Solved!
Go to solution

Hello,

 

is it possible to stop a for loop with enabled loop iteration parallelism when the first instance is finished?

I have x loop instances and the x is every time different so i couldn't make x while loops.

 

Best regards
Stefan

0 Kudos
Message 1 of 8
(2,433 Views)

No, or condition, or parallelism, but not together.
But why do you need a cycle if you only need one action?
And you can run any number of clones (reentrant functions)

0 Kudos
Message 2 of 8
(2,424 Views)

With parallelism enabled the short answer is no, you can't stop the for loop after the first iteration. Other iterations have already run since it's running in parallel. Perhaps with a better description of what you're trying to do (and even some example code of what you've tried) there may be other ways to accomplish what you want. For example, do you really need parallelism? If so, why do you need to stop after the first iteration? I don't understand what you mean by "I have x loop instances and the x is every time different so I couldn't make x while loops." Are you saying that you want to run x instances of a loop and make all of them stop when one of them stops? You could put the loop in a subvi and call it x times asynchronously. There are various ways that you could signal between the asynchronous calls. 

0 Kudos
Message 3 of 8
(2,419 Views)

I want to start asynchronously a VI x times (x = number of data blocks to be processed). If one of the started instances returns a valid result, the remaining results are no longer significant so all instances can be stopped and the valid result returned.

I tried the following howto (Variation: Collecting Outputs from Multiple Calls to Unique VI References):

https://zone.ni.com/reference/en-XX/help/371361P-01/lvhowto/acbr_call_and_collect/

I can now process my data blocks simultaneously, but how do I stop processing when an instance satisfies my condition and the rest are no longer significant?

0 Kudos
Message 4 of 8
(2,384 Views)
Solution
Accepted by topic author kuegerls

I would obtain a notifier and send that reference to each of the cloned VI's when you start them.

When a VI finishes, I would have it send out a True notification which would signal all the other VI's finish whatever iteration they are on and end their loop.

0 Kudos
Message 5 of 8
(2,376 Views)

@RavensFan wrote:

I would obtain a notifier and send that reference to each of the cloned VI's when you start them.

When a VI finishes, I would have it send out a True notification which would signal all the other VI's finish whatever iteration they are on and end their loop.


This is exactly what I was going to suggest.

0 Kudos
Message 6 of 8
(2,370 Views)

IMHO a good option would be to compare the speed and resource requirements:
- no parallelism, the check goes step by step, stop at the first success. It requires less memory, but the test can take a long time (what is the probability that you need to stop after the first iteration and what is the probability that you have to do everything?)
- calculations are parallel, then a choice from all results.
It requires more memory (to store the results and run the clones of the functions), but the test may end up faster (but are the calculations really parallel?)

 

And main question: is it real speed up? May be you now spend time for developing, but real benefit is too small

0 Kudos
Message 7 of 8
(2,368 Views)

All you probably need is a small, non-reentrant subVI that acts like an action engine where a boolean can be set or reset to be seen by all. This would act as critical section but won't hurt parallelism if the rest of the loop code is significantly more complex. What do the iterations actually do? If the iterations are really fast to begin with, you might be faster without parallelism anyway.

 

Can you show us some code?

0 Kudos
Message 8 of 8
(2,363 Views)