\pagebreak
\section{\code{scan} Directive}
\label{sec:scan}

The following examples illustrate how to parallelize a loop that saves 
the \emph{prefix sum} of a reduction. This is accomplished by using 
the \code{inscan} modifier in the \code{reduction} clause for the input 
variable of the scan, and specifying with a \code{scan} directive whether 
the storage statement includes or excludes the scan input of the present 
iteration (\texttt{k}).

Basically, the \code{inscan} modifier connects a loop and/or SIMD reduction to 
the scan operation, and a \code{scan} construct with an \code{inclusive} or 
\code{exclusive} clause specifies whether the ``scan phase'' (lexical block 
before and after the directive, respectively) is to use an \plc{inclusive} or 
\plc{exclusive} scan value for the list item (\texttt{x}).

The first example uses the \plc{inclusive} scan operation on a composite
loop-SIMD construct. The \code{scan} directive separates the reduction 
statement on variable \texttt{x} from the use of \texttt{x} (saving to array \texttt{b}).
The order of the statements in this example indicates that
value \texttt{a[k]} (\texttt{a(k)} in Fortran) is included in the computation of 
the prefix sum \texttt{b[k]} (\texttt{b(k)} in Fortran) for iteration \texttt{k}.

\cexample[5.0]{scan}{1}

\ffreeexample[5.0]{scan}{1}

The second example uses the \plc{exclusive} scan operation on a composite
loop-SIMD construct. The \code{scan} directive separates the use of \texttt{x} 
(saving to array \texttt{b}) from the reduction statement on variable \texttt{x}.
The order of the statements in this example indicates that
value \texttt{a[k]} (\texttt{a(k)} in Fortran) is excluded from the computation 
of the prefix sum \texttt{b[k]} (\texttt{b(k)} in Fortran) for iteration \texttt{k}.

\cexample[5.0]{scan}{2}

\ffreeexample[5.0]{scan}{2}
