Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 36 ยท Dataflow and Structures

The Dataflow Execution Model

Understand LabVIEW dataflow in depth: node firing, parallel branches, race conditions, forcing order with error wires, and Highlight Execution.

Dataflow is the single most important idea in LabVIEW. If you understand exactly when a node runs, you will avoid most beginner bugs: mysterious ordering, race conditions and loops that never finish. This lesson explains the model, then shows how to control order when you need to. LabVIEW itself is not available on this site, so the demos are JavaScript stand-ins that model the same rules.

The firing rule

A node (a function, subVI or structure) executes when all of its inputs have received data. When it finishes, it hands all its outputs on at once. That is the whole rule. Notice what is missing: position on screen, creation time and wire length have no effect.

Consequences:

  • No wire, no order. If node A and node B are not connected, either may run first, or they may run at the same time.
  • A structure is one node. A loop or case structure starts when all its inputs have data and delivers its outputs only when it finishes. Data does not leave a loop mid-way unless you use a shift register or other mechanism.
  • Parallel by default. LabVIEW compiles independent diagram sections into separate tasks. On a multicore computer these really run at once, in an execution system managed by the runtime.

The firing rule

Wait For every input
Run The node executes
Pass All outputs together

Position on screen does not matter.

1 / 2

Forcing an order

When one action must happen before another, you have three honest tools.

  1. Wire data between them. If B needs A's result, wire it. Done.
  2. Error wires. Most I/O functions have error in and error out. Wire error out of A into error in of B. This creates a data dependency even when there is no other data to pass. It also stops B from running its work if A produced an error. This is the idiomatic pattern.
  3. Flat sequence structure. A flat sequence shows frames side by side and runs them left to right. Data wired across the frames is stored in sequence locals. Use it sparingly; heavy use hides parallelism and clutters the diagram. See case and sequence structures.

Do not try to use position or "wire the loop output to an unused input" tricks. They are fragile, and they hide your intent.

Race conditions

A race condition appears when two parallel pieces of code read and write the same data and the result depends on timing. The classic LabVIEW way to create one is with a local variable or global variable written in one loop and read in another:

  • Loop 1 writes Counter and then loop 2 reads it.
  • Sometimes the read sees the old value, sometimes the new.

Because the code looks sequential on the screen but is not, such bugs are hard to reproduce. Prefer wires, shift registers, queues and notifiers (see later chapters) over locals when the order matters.

Data copies and wire branches

A wire that splits to two destinations carries the same value to both. LabVIEW makes a copy only when a node needs to modify the data in place and the original is still needed elsewhere. Its compiler tries to avoid copies. You can inspect where it creates buffers with the Show Buffer Allocations tool (Tools > Profile). Usually you do not worry until you work with large arrays.

Seeing the flow: Highlight Execution

Click the light bulb on the block diagram toolbar and run the VI. LabVIEW slows execution and shows small bubbles moving along wires, with values displayed. You can also click Step Into, Step Over and Step Out to run a node at a time. Highlight Execution is slow, so use it on small examples or with sample data; turn it off afterward. This is the best way to prove to yourself that your picture of the order is correct. See debugging tools later in the course (see the track page).

Stand-in 1: a firing-rule scheduler

This JavaScript stand-in describes a tiny diagram as a graph and runs it by repeatedly firing every node whose inputs are ready. Each round, nodes that could fire "in parallel" are printed together. It is a model for thinking, not LabVIEW's actual scheduler.

JS Stand-in: which nodes can fire together?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that Square fires in round 2 alongside Add, because both only need constants. Nothing told them to wait for each other.

Stand-in 2: a race condition and the fix

The second stand-in imitates two loops sharing a "local variable". Both read, add, and write back, but the read and write happen at different moments (modeled with await). The result is wrong. The fix is to pass the value through one place, as a single shift register or an atomic update would.

JS Stand-in: lost updates with a shared variable

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The shared version always loses updates in this model, which is why LabVIEW developers avoid locals for cross-loop communication.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. When does a LabVIEW node execute?

    That is the dataflow firing rule.
  2. 2. What is the idiomatic way to force one I/O node to run after another?

    An error wire creates a data dependency and also skips work after an error.
  3. 3. Why are local variables risky between parallel loops?

    Reads and writes happen without a wire, so the outcome depends on timing.
  4. 4. Which toolbar button animates data moving along wires?

    Highlight Execution (the light bulb) slows the run and shows values on wires.

Summary

  • A node fires when all of its inputs have data, and outputs all leave together.
  • Unwired nodes have no defined order and may run in parallel.
  • Use data wires and error wires to enforce order; use flat sequences sparingly.
  • Local and global variables across parallel loops invite race conditions.
  • Highlight Execution and stepping tools show the real order.

Next: While Loops and For Loops