next up previous contents index
Next: Statements Up: Promotion Previous: Parameter Promotion

Procedure Promotion

     

Procedures can be promoted by passing in parallel parameters where sequential parameters are expected. The procedure is logically applied to each element of its parallel parameters.

    procedure abs (x : float) : float;
    begin
        if x < 0 then
            return -x;
        else
            return x;
    end;

    . . .
[R] A := abs(A);              -- promote the abs() procedure
        There are three restrictions on the promotion of procedures: First, only sequential procedures can be promoted. This is consistent with the rule that only sequential expressions can be promoted. A sequential procedure is one that does not refer to any parallel variables, either directly or through procedure calls. Any procedure that is not a sequential procedure is a parallel procedure. Note that a procedure that invokes a parallel procedure is itself a parallel procedure, and note that all I/O procedures are considered to be parallel procedures.

Second, only procedures without side effects, i.e., pure functions, can be promoted. The following code fragment shows an illegal attempt to promote a parallel procedure.

    procedure Scale (X : [,] float, factor: integer) : [,] float;
    begin
        return X * factor;
    end;

    . . .
[R] A := Scale (A, B);       -- illegal promotion of a parallel procedure
It is illegal to promote a procedure with side effects because this could lead to unpredictable behavior. To understand this, consider the effect of attempting to promote the following parallel procedure.

    procedure sideEffect (var a, b: float);
    begin
        g := g+1;
        a := b;
    end;

    . . .
[R] copy (A, A@east);       -- dangerous use of promotion
The above procedure is applied to corresponding elements of A and A@east in the region [R]. However, because the procedure is applied to its parameters in an unspecified order, the results are unpredictable. By contrast, the following parallel procedure has well defined semantics because the right hand side of the statement is guaranteed to be evaluated before it is assigned to the left hand side (see Section 7.1).

    procedure Copy (var A, B: [,] float);
    begin
        A := B;
    end;

    . . .
[R] Copy (A, A@east);

Finally, a procedure call must be promoted to a single unambiguous rank. All parallel variables that are passed as parameters must have the same rank. Note that a sequential procedure that accepts multiple arguments will be promoted if any of its actual parameters is a parallel variable.


next up previous contents index
Next: Statements Up: Promotion Previous: Parameter Promotion

Kay Nettle
Fri Feb 21 21:14:29 CST 1997