erotavlas
erotavlas

Reputation: 4493

How can pipeline tasks run concurrently if each task depends on the previous output?

On MSDN it says that each task is processed concurrently and each subsequent task depends on the output from the previous. However how can they occur concurrently if the processing of the subsequent task needs the output from the previous in order to even process something? Doesn't this imply that a task needs for the task that precedes it to complete it's execution before it can begin? (which doesn't sound very concurrent or parallel to me)

For example in their diagram they show the processing of a string with these steps

  1. Read string
  2. Correct case
  3. create sentences
  4. write output

How can i work on creating sentences before I read all the strings with corrected case?

The assembly line analogy also doesn't sound very parallel to me since if one stage in the assembly breaks then how can the partially constructed product move to the next state for further assembly.

Upvotes: 1

Views: 91

Answers (2)

Ross Bush
Ross Bush

Reputation: 15185

"...even though the values are processed in order. You can think of software pipelines as analogous to assembly lines in a factory, where each item in the assembly line is constructed in stages. The partially assembled item is passed from one assembly stage to another. The outputs of the assembly line occur in the same order as that of the inputs."

Here is more info on your topic.

In a nutshell, the tasks are broken out so if task(n+1) is given output from task(n), task(n+1) can start to process that data while task(n) is jammed up or really busy.

Upvotes: 1

1.618
1.618

Reputation: 1765

Individual items are processed sequentially, but the processing of the entire sequence of items happens in parallel (mostly). As soon as an item is finished being processed by a given task, it is sent to the next task, which starts processing it right away. Without pipelines, the first task would have to process the entire sequence of values before the second task could start. This image from the MSDN article should help:

enter image description here

Upvotes: 2

Related Questions