1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

52
Dr. Muhammed Al-Mulhem Dr. Muhammed Al-Mulhem ICS535-091 ICS535-091 1 Dataflow Programming

Transcript of 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Page 1: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 1

Dataflow Programming

Page 2: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 2

Pure Dataflow Model Programs are represented by a directed graph.Programs are represented by a directed graph. NodesNodes are primitive instructions such as are primitive instructions such as

arithmetic and comparison operations.arithmetic and comparison operations. ArcsArcs represent the data dependencies between represent the data dependencies between

the instructions.the instructions. Conceptually, data flows as tokens along the arcs Conceptually, data flows as tokens along the arcs

which behave like unbounded first-in, first-out which behave like unbounded first-in, first-out (FIFO) queues.(FIFO) queues.

Arcs that flow toward a node are said to be Arcs that flow toward a node are said to be input input arcs to that node, while those that flow away are arcs to that node, while those that flow away are said to be said to be output output arcs from that node.arcs from that node.

Page 3: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 3

Pure Dataflow Model (Cont.)

When the program begins, special activation nodes place data When the program begins, special activation nodes place data onto certain key input arcs, triggering the rest of the program.onto certain key input arcs, triggering the rest of the program.

Whenever a specific set of input arcs of a node (called a Whenever a specific set of input arcs of a node (called a firing firing set) has data on it, the node is said to be set) has data on it, the node is said to be fireablefireable..

A fireable node is executed at some undefined time after it A fireable node is executed at some undefined time after it becomes fireable. The result is that it removes a data token becomes fireable. The result is that it removes a data token from each node in the firing set, performs its operation, and from each node in the firing set, performs its operation, and places a new data token on some or all of its output arcs. places a new data token on some or all of its output arcs.

It then ceases execution and waits to become fireable again. It then ceases execution and waits to become fireable again.

Page 4: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 4

Pure Dataflow Model (Cont.)

By this method, instructions are scheduled By this method, instructions are scheduled for execution as soon as their operands for execution as soon as their operands become available. become available.

This stands in contrast to the von Neumann This stands in contrast to the von Neumann execution model, in which an instruction is execution model, in which an instruction is only executed when the program counter only executed when the program counter reaches it, regardless of whether or not it can reaches it, regardless of whether or not it can be executed earlier than this.be executed earlier than this.

The key advantage is that, in dataflow, more The key advantage is that, in dataflow, more than one instruction can be executed in than one instruction can be executed in parallel.parallel.

Page 5: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 5

Example

Page 6: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 6

Example (Cont.)

Under the von Neumann execution model, the Under the von Neumann execution model, the program in Figure 1(a) would execute program in Figure 1(a) would execute sequentially in three time units.sequentially in three time units.

Under the dataflow execution model, the Under the dataflow execution model, the program in Figure 1(b) would execute program in Figure 1(b) would execute sequentially in two time units.sequentially in two time units.

It is clear that dataflow provides the potential It is clear that dataflow provides the potential to provide a substantial speed improvement to provide a substantial speed improvement by utilizing data dependencies to locate by utilizing data dependencies to locate parallelism. parallelism.

Page 7: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 7

Open Problems in Dataflow Programming

Dataflow programming is an active Dataflow programming is an active area of research, and many problems area of research, and many problems remain open. Four of these are:remain open. Four of these are:

1.1. Iteration structures in textual dataflow Iteration structures in textual dataflow languages.languages.

2.2. Iteration structures in visual dataflow Iteration structures in visual dataflow languages.languages.

3.3. The use of data structures.The use of data structures.4.4. Nondeterminism.Nondeterminism.

Page 8: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 8

Your Assignments

1.1. Report # 1: Due Nov. 14Report # 1: Due Nov. 14

2.2. Report # 2: Due Dec. 12Report # 2: Due Dec. 12

3.3. Report # 3: Due Dec. 23Report # 3: Due Dec. 23

4.4. Final Report: Due Jan. 16Final Report: Due Jan. 16

Page 9: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 9

Format of Report # 1

TitleTitle Abstract – Leave it empty for time Abstract – Leave it empty for time

being.being. Introduction – Definition of Iteration in Introduction – Definition of Iteration in

Dataflow languages and motivation to Dataflow languages and motivation to study it.study it.

Related work – Extend the 2004 survey Related work – Extend the 2004 survey paper given to you, so that it includes paper given to you, so that it includes some references 2004-2009.some references 2004-2009.

Page 10: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 10

Format of Report # 2

TitleTitle Abstract – Leave it empty for time being.Abstract – Leave it empty for time being. Introduction – Report #1Introduction – Report #1 Related work – Report #1.Related work – Report #1. Give a list of different approaches reported in the Give a list of different approaches reported in the

related work section above.related work section above. Compare these approaches in terms of Compare these approaches in terms of

SimilaritiesSimilarities DifferencesDifferences DependencyDependency AdvantagesAdvantages DisadvantagesDisadvantages

Build a dependency tree showing the dependency Build a dependency tree showing the dependency relation among the different approaches.relation among the different approaches.

Page 11: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 11

Format of Report # 3

Your approachYour approach

Page 12: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 12

Format of The Final Report Your report should have the Your report should have the

format of an IEEE or ACM journal format of an IEEE or ACM journal paper.paper.

Page 13: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 13

Format of The Final Report TitleTitle AbstractAbstract IntroductionIntroduction

– Problem definition with examples.Problem definition with examples. Related work .. No examplesRelated work .. No examples List of different approaches reported in the related work.List of different approaches reported in the related work. Details of those approaches with examples.Details of those approaches with examples. Comparison of those approachesComparison of those approaches

– Discussion of advantages, disadvantages, similarities, etc. Discussion of advantages, disadvantages, similarities, etc. – A summary of the comparison in Table form.A summary of the comparison in Table form.

Your approach.Your approach.– IdeaIdea– ExamplesExamples– How is your approach is different than the other approaches.How is your approach is different than the other approaches.

ConclusionConclusion References in IEEE format.References in IEEE format.

Page 14: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 14

Iteration in Textual Dataflow Iteration in Textual Dataflow PLsPLs

IntroductionIntroduction Most dataflow programming Most dataflow programming

languages provide loops of some languages provide loops of some form, but the way in which loops form, but the way in which loops are expressed as a dataflow are expressed as a dataflow graph is quite different from most graph is quite different from most other representations of iteration.other representations of iteration.

Page 15: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 15

Iteration (Cont.)Iteration (Cont.)

The problem The problem arises because

iteration does not fit neatly into the dataflow paradigm, as it involves repeated assignment to a loop variable and sequential processing.

Page 16: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 16

Iteration (Cont.)Iteration (Cont.)

Many dataflow languages provide iteration through tail-recursion.

The exact syntax of the various solutions offered differed, but they were all fundamentally the same.

The idea was to think of the body of an iteration as being executed in an environment where the loop variable had a certain value that remained the same throughout the iteration.

Page 17: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 17

Iteration (Cont.)Iteration (Cont.)

A single pass of the loop can be regarded as a set of definitions like any other.

The loop variable is updated by using an identifier such as “NEW” to refer to the value that the loop variable will have on the next iteration. For example,

NEW X = X + 1;

Page 18: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 18

Iteration (Cont.)Iteration (Cont.)

As the value of X has not actually been changed by this statement, this is a mathematically acceptable way of representing iteration.

When the loop has completed the iteration, the value of NEW X is assigned to X, but again, this is acceptable since all that is required is that the value of X remain unchanged during the single iteration.

Some languages use an “old” keyword to achieve the same effect.

Page 19: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 19

Iteration (Cont.)Iteration (Cont.)

A piece of code to calculate factorial (N) by iteration, when translated into the functional loop favored by dataflow programming languages, looks like this:

LOOP WITH i = N, fact = 1NEW fact = fact ∗ i;NEW i = i − 1;WHILE i > 1;

Page 20: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 20

Iteration (Cont.)Iteration (Cont.)

In this code, the values of “fact” and “i” are defined functionally, using the loop. They are modified using the keyword “NEW.”

Note that the definitions of “NEW fact” and “NEW i” can be placed in any order.

If the definition of “NEW i” were placed first, the definition of “NEW fact” would still be valid because the original value of i is unchanged until the end of the iteration.

LOOP WITH i = N, fact = 1NEW fact = fact ∗ i;NEW i = i − 1;WHILE i > 1;

Page 21: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 21

Iteration (Cont.)Iteration (Cont.)

Note also that the value “fact” must be declared as a loop variable in the dataflow version of the loop because that is the only way that a variable can be assigned multiple times in the manner required by iteration.

While this code definitely looks different from the imperative example, it does, nevertheless, retain a strong imperative feel and could be used more intuitively by programmers when compared to tail recursion.

LOOP WITH i = N, fact = 1NEW fact = fact ∗ i;NEW i = i − 1;WHILE i > 1;

Page 22: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 22

Iteration (Cont.)Iteration (Cont.)

Of course, this code has to be translated into a dataflow graph before it can be executed.

While a loop in a dataflow graph can look complicated, most loops can be coded in the same way.

Next Figure shows a dataflow graph that could result from the above dataflow code example.

LOOP WITH i = N, fact = 1NEW fact = fact ∗ i;NEW i = i − 1;WHILE i > 1;

Page 23: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 23

Iteration in Dataflow

Page 24: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 24

Iteration (Cont.)Iteration (Cont.)

It cannot be denied that this representation is much less succinct than the text-based loop.

However, the point is not that a loop can be drawn directly as a graph, but that the text-based loop can be converted into a well-behaved dataflow graph.

Few dataflow researchers would expect any programmer to manually generate the graph shown in the Figure.

LOOP WITH i = N, fact = 1NEW fact = fact ∗ i;NEW i = i − 1;WHILE i > 1;

Page 25: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 25

Iteration (Cont.)Iteration (Cont.)

This also illustrates one of the failings of early graphical dataflow languages.

However, recent development in visual dataflow research permit programs to be specified graphically without this level of detail.

Visual dataflow programming is outside the scope of this course.

Page 26: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 26

Iteration (Cont.)Iteration (Cont.)

In the Figure: The “Merge” gate takes two data input arcs,

labeled true and false inputs, as well as a “control” input arc that carries a Boolean value.

When the node fires, the control token is absorbed first.

If the value is true, the token on the true input is absorbed and placed on the output.

If it is false, then the token on the false input is absorbed and placed on the output.

Page 27: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 27

Iteration (Cont.)Iteration (Cont.)

The “Switch” gate operates in much the same way, except that there is a single input and the control token determines on which of two outputs it is placed.

Page 28: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 28

Iteration (Cont.)Iteration (Cont.)

The “Delay” gate simply waits until data appears at both inputs before outputting the data on the left arc and discarding the data on the right arc.

This acts as a trigger, preventing the loop from executing infinitely.

With the Delay gate, a single token passed down the trigger arc will cause one execution of the loop.

Page 29: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 29

Iteration (Cont.)Iteration (Cont.)

The squares with “1” in them are constants, that repeatedly generate tokens with the value “1.”

The circles are nodes that perform operations.

These operations produce either numerical or Boolean results.

The small grey circles labeled “F” signify tokens that are defined to be present on the given arcs when the program first activates.

Page 30: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 30

Iteration (Cont.)Iteration (Cont.)

Three horizontal parallel lines denote a sink, which destroys any tokens that fall into it.

A small open square at a crossing of two arcs indicates that the arcs are joined.

In all other cases, arcs pass over each other without being joined.

The left-hand side of the graph produces a sequence of tokens representing the counter “i,” starting at 1.

Page 31: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 31

Iteration (Cont.)Iteration (Cont.)

The right-hand side produces a series of tokens representing the accumulating factorial by multiplying the previous factorial token by a token from the first sequence each time.

The node in the center of the graph halts the feedback once the value of i ≤ N becomes false, and the Switch gates are used to output the completed values.

The value of “i” is discarded, while the value of the factorial is sent out of this portion of the graph.

Page 32: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 32

Iteration in Visual Dataflow Iteration in Visual Dataflow PLsPLs

Existing dataflow VPLs adopt different solutions to face the problem of how to implement iterations within a dataflow program.

Here, the solutions presented by a number of visual dataflow languages are shown.

Page 33: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 33

Show and Tell

Show and Tell is a general-purpose language mainly intended for school children.

Graphically, it is based on boxes, i.e. rectangles which can represent functions, constants, variables, and other elements of the language.

Data flows through links (lines with arrows) connecting boxes.

The concept of variable also exists in Show and Tell. Practically, a variable is an empty box which can contain data.

A boxgraph consists of one or more boxes, possibly connected by links.

Page 34: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 34

Show and Tell

When a data value is transferred to a box which already holds a different value or when an open box containing a predicate (e.g. ‘>0’) is evaluated to be false, the box’s boxgraph becomes inconsistent.

Inconsistency is a key concept in Show and Tell, in that it allows a form of control over the computation.

Page 35: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 35

Show and Tell

Next Figure shows a Show and Tell program which calculates the factorial of a positive integer.

The program visually implements the above textual C code fragment, where ‘n’ is the number whose factorial is to be calculated.

Page 36: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 36

Figure

Page 37: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 37

Show and Tell

The big double rectangle in the Figure is an iteration box, which means that what is included within it constitutes the body of an iteration.

The empty arrows on the left and on the right of the box are sequential ports.

The two boxes on the left contain constant values and, precisely, ‘4’, in this example, is the number whose factorial is to be calculated.

Function boxes ‘-1’ and ‘x’ perform the corresponding arithmetic operations on their inputs, once they are all available (according to the dataflow model).

Page 38: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 38

Show and Tell

When program execution starts, values ‘4’ and ‘1’ are provided to the iteration box.

Therewith, the ‘4’ value is first transferred to a variable box (the empty one) and, from here, to function ‘x’, function ‘-1’ and to predicate ‘>0 ’ . At the same time, value ‘1’ is provided to function ‘x’.

If the variable box’s content is not greater than zero, an inconsistency is generated and program execution halts.

Page 39: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 39

Show and Tell

Otherwise, the value in the variable box is decreased by one by function ‘-1’ and placed into the upper box outside the iteration structure.

Concurrently, function ‘x’ multiplies its two inputs (‘4’ and ‘1’) and gives out the result, which is placed into the lower box outside the iteration structure.

Page 40: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 40

Show and Tell

At this point, the first step of the iteration is finished and a new one starts.

Values within the boxes on the right of the iteration box virtually re-enter the boxes on the left, whose initial values are now substituted with the new ones.

The process goes on until the variable box’s contents reaches ‘0’.

Page 41: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 41

Show and Tell

In practice, such an iteration mechanism behaves as if subsequent identical boxgraphs (one for each step of the iteration) were arranged so that a boxgraph’s outputs are the inputs for the next one.

Page 42: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 42

LabView

LabView is a language designed to create software interfaces for hardware devices, especially in the field of real time data acquisition.

Program modules (or procedures) are called virtual instruments (VIs).

Essentially, a LabView program is made up of a graph whose nodes identify functions, variables and constants.

Page 43: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 43

LabView

Two iterative forms are available in LabView: the FOR loop and the WHILE loop.

In both the iteration’s body, that is the program subgraph whose execution is to be repeated, is placed within a proper pane (a square-shaped special big block).

For the FOR loop, an integer value indicating the number of iterations to be accomplished must be specified, whereas in the case of the WHILE loop the cycle execution is repeated for as long as a boolean condition, visually expressed, is satisfied.

Page 44: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 44

LabView For

Since LabView’s program graphs are acyclic (data flows from left to right only), a mechanism for updating possible variables depending on previous iterations is necessary.

Next Figure shows a LabView program which calculates the factorial of a positive integer using the FOR loop construct.

Page 45: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 45

Figure - For 1

Page 46: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 46

LabView -For

In the program, the ‘n’ in the double box on the left is a control, that is, an input specifying the integer number whose factorial is to be calculated.

It is connected to the ‘N’ in the upper left corner of the FOR loop pane representing the iteration body, meaning that the loop will be executed for ‘n’ times.

The ‘i’ in the single box within the pane is the loop variable and is initialized to zero. The ‘1’s in the single boxes are constants.

Page 47: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 47

LabView - For

A downward arrow and an upward represent input and output ports for the loop: an arc connected to an upward arrow on the right virtually re-enters through the horizontally corresponding downward arrow on the left during the next iteration step, thus implementing a virtual cycle.

A loop (both FOR and WHILE) can have any number of input and output ports, according to its needs.

Page 48: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 48

LabView - For

Referring to the Figure, at the beginning of the iteration, constant ‘1’ is provided to the FOR loop (through the downward arrow) as an initial value.

Such a value is an input for function ‘x’, along with the loop index ‘i’ (whose initial value is zero) increased by one by function ‘+’.

The output of function ‘x’ represents the partial factorial and is connected to the upward arrow on the right of the loop pane, thus exiting it.

At this point, the current iteration step is finished, the partial factorial re-enters the loop body through the downward arrow on the left and a new step starts.

Iteration stops when variable ‘i’ reaches ‘n-1’.

Page 49: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 49

LabView - While

Next Figure shows a LabView program using the WHILE loop construct.

Its purpose is to calculate the square root of a number through the Newton algorithm.

Page 50: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 50

LabviewLabview

Page 51: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 51

LabView - While

As can be noted from the textual transposition of the visual program, despite its name, the WHILE construct is really a DO ... WHILE (or REPEAT ... UNTIL) loop structure.

Referring the Figure, ‘x0’ is a control (that is, an input in the user interface) indicating the initial value from which to start with the Newton algorithm.

Along with control ‘noise limit’, which simulates a noise component, it is actually an input to the loop. ‘alfa’ is the number whose square root is to be calculated.

Page 52: 1 Dr. Muhammed Al-Mulhem ICS535-091 Dataflow Programming.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-091ICS535-091 52

LabView - While

Once the first step of the WHILE iteration has been completed, predicate ‘>’ tests whether the error is greater than the value specified through control ‘residual error’.

If so, iteration must go on. Otherwise, iteration must stop.

Therefore, in this example, predicate ‘>’ is actually the WHILE loop condition, as indicated by the fact that its output is connected to the circular arrow icon in the lower right-hand corner.

The output of the upper ‘-’ function is connected to the upward arrow on the right of the WHILE loop pane and re-enters from the downward arrow on the left at the next iteration step.

The iteration process ends when the WHILE loop condition is no longer true.