Figure 17 Example of odd-even transposition sorting
In the Parallaxis program, first the variable lhs determines whether a PE is in the role of the left or the right partner of a comparison. This role changes for each loop iteration. During each pass, the PEs get the data values of their left and right neighbor in l and r, respectively. The partner on the left-hand side uses the right neighbor's value for comparison, while the partner on the right-hand side uses the value of its left neighbor. The complicated comparison `lhs = (comp<val)' is true for the left PE partner when the right comparison value is greater than its own value; it is also true for the right PE partner, if the left comparison value is smaller than its own value. So a single key comparison is sufficient for all PEs to find out where swapping of data values are required. By applying a more complex compound topology, the program could be optimized further, such that only a single data exchange operation would be required for each pass through the loop.
MODULE sort; (* Odd-Even Transposition Sorting *)
CONST n = 10;
CONFIGURATION list [1..n];
CONNECTION left : list[i] <-> list [i-1] :right;
VAR step : INTEGER;
a : ARRAY[1..n] OF INTEGER;
val,comp: list OF INTEGER;
lhs : list OF BOOLEAN;
BEGIN
WriteString('Enter 10 values: ');
FOR step:=1 TO n DO ReadInt(a[step]) END;
LOAD(val,a);
lhs := ODD(ID(list)); (* PE is left-hand-side of comparison *)
FOR step:=1 TO n DO
IF lhs THEN comp := RECEIVE.left(val)
ELSE comp := RECEIVE.right(val)
END;
IF lhs = (comp<val) THEN val:=comp END;(* lhs & (comp< val) *)
lhs := NOT lhs; (* or rhs & (comp>=val) *)
END;
STORE(val,a);
FOR step:=1 TO n DO WriteInt(a[step],10); WriteLn END;
END sort.
Figure 18 shows the runtiof the OETS sorting algorithm for sorting of 1000
numbers. The PE load curve shows a continuous high processor utilization.
active PEs
time in program steps
Figure 18 Processor utilization of the sorting algorithm