
%\documentstyle{csart}

%\begin{document}

\section{\label{primitives}Some ``Communication'' Primitives}

     Here we give the definitions of some of the routines used as
``primitives'' in the examples.  The specification given for
{\em broadcast}, in terms of which
the other routines are defined, is unlikely to be acceptable under
realistic usage regimes---instead it could be taken as a true primitive.
In all cases (except, possibly $and.2$) the implementations given here
would be extremely inefficient.  Most of them are essentially sequential.
The idea is just to specify the behaviour of the routines.

     A useful communication library would need many more such routines.
\begin{linear}
\begin{verbatim}

    PROC broadcast ([] INDEX x, RANK R TYPE T A, VAL {x} \/ R T B,
                   VAL INT src)

      -- Copy elements of `B' from x = src to variable `A', which
      -- is global with respect to `x'.

      -- Notice that this program is illegal under the (most practical)
      -- strict form of WHERE usage rules.

      IF
        (0 <= src) AND (src < (SIZE x))
          WHERE {x}
            IF
              x = src
                WHERE R
                  A := B    -- assignment to global variable!
              TRUE
                SKIP
        TRUE
          STOP
    :

\end{verbatim}
\end{linear}
\begin{linear}
\begin{verbatim}

    PROC rotate ([] INDEX x, {x} \/ RANK R TYPE T A, VAL {x} \/ R T B,
                VAL INT shift)

      -- Shift values in `B' in `x' direction by `shift' sites,
      -- returning result in `A'

      INT n :
      SEQ
        n := SIZE x
        SEQ i = 0 FOR n
          R T element :
          SEQ
            broadcast (x, element, B, i)
            WHERE {x}
              IF
                x = ((i + shift) MOD n)
                  WHERE R
                    A := element
                TRUE
                  SKIP
    :

\end{verbatim}
\end{linear}
\begin{linear}
\begin{verbatim}

    BOOL FUNCTION and ({[] INDEX x} BOOL A)

      -- Logical "and" of 1-d Boolean distribution.

      BOOL result :
      VALOF
        SEQ
          result := TRUE
          SEQ i = 0 FOR SIZE x
            BOOL element :
            SEQ
              broadcast (x, element, A, i)
              result := result AND element
        RESULT result
    :
            
\end{verbatim}
\end{linear}
\begin{linear}
\begin{verbatim}
        
    BOOL FUNCTION and.2 ({[] INDEX x, [] INDEX y} BOOL A)

      -- Logical "and" of 2-d Boolean distribution.
    
      BOOL result :
      VALOF
        {x} BOOL temp :
        SEQ
          WHERE {x}
            temp := and (A)
          result := and (temp)
        RESULT result
    :

\end{verbatim}
\end{linear}

%\end{document}
