LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

parallel while-loops

Hi,

I´ve difficulties to understand how the following works:

When I build a VI that contains for example three while loops. In which
order will those loops be executed. Is it granted that each loop will be
executed before one loop starts its second execution? In an example I´ve
here three loops were connected to the same occurency. The occurrency is
connected to a quit button. Is this simply to end a VI correctly or is there
another reason?


thx András
0 Kudos
Message 1 of 3
(3,195 Views)
If your loops are really parallel with no connection between them, you have no control over the execution order. If you did not build in any synchronization, the loops will not wait for another loop to finish an iteration before proceding to its next iteration.
What do you want to do? Have one loop complete all its iterations before the next loop starts? Have each loop wait until all loops are done with a certain iteration before proceding? Have a loop wait until another loop completes a certain function?
Did you build any data dependency into your loops? In other words, does any loop depend on an output from another loop?
Search LabView Help for "dataflow" and review the topic Dataflow: The Concept Behind LabVIEW.
You can enforce a desired execution order in s
everal ways.
Create the appropriate data dependency: if loop B depends on the output of loop A, loop B will not start until loop A is finished.
Use a sequence structure or a state machine (cases in a loop) to execute the loops in a desired order.
Use local variables or semaphores and cases within the loops to force one loop to wait until another loop reaches a certain point.
If your relationships between loops is very complicated, you may want to look at combining the loops into one larger loop and using state machines or cases within the loop to control execution.
0 Kudos
Message 2 of 3
(3,195 Views)
> When I build a VI that contains for example three while loops. In which
> order will those loops be executed. Is it granted that each loop will be
> executed before one loop starts its second execution? In an example I´ve
> here three loops were connected to the same occurency. The occurrency is
> connected to a quit button. Is this simply to end a VI correctly or is there
> another reason?
>

Parallel loops, and parallel code in general doesn't specify any given
relationship between the code. It will potentially interleave the
loops, or if the loops run quickly, one may finish before the others
start. Conditions may change drastically if run on a multiprocessor
machine.

If you have conditions that you want synchronized, you can combine loops
so that
the contents of the diagram have to finish before the next
iteration can begin. You can also use the synchronization palette
functions such as semaphores to do more complex code synchronization,
but be sure you know what they do and look at examples before using them.

Greg McKaskle
0 Kudos
Message 3 of 3
(3,195 Views)