2024-04-16 08:59:23 -07:00

49 lines
2.4 KiB
TeX

%\pagebreak
\section{\kcode{scan} Directive}
\label{sec:scan}
\index{directives!scan@\kcode{scan}}
\index{scan directive@\kcode{scan} directive}
\index{reduction clause@\kcode{reduction} clause!inscan modifier@\kcode{inscan} modifier}
\index{inscan modifier@\kcode{inscan} modifier}
The following examples illustrate how to parallelize a loop that saves
the \emph{prefix sum} of a reduction. This is accomplished by using
the \kcode{inscan} modifier in the \kcode{reduction} clause for the input
variable of the scan, and specifying with a \kcode{scan} directive whether
the storage statement includes or excludes the scan input of the present
iteration (\ucode{k}).
\index{scan directive@\kcode{scan} directive!inclusive clause@\kcode{inclusive} clause}
\index{scan directive@\kcode{scan} directive!exclusive clause@\kcode{exclusive} clause}
\index{clauses!inclusive@\kcode{inclusive}}
\index{inclusive clause@\kcode{inclusive} clause}
\index{clauses!exclusive@\kcode{exclusive}}
\index{exclusive clause@\kcode{exclusive} clause}
Basically, the \kcode{inscan} modifier connects a loop and/or SIMD reduction to
the scan operation, and a \kcode{scan} construct with an \kcode{inclusive} or
\kcode{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 (\ucode{x}).
The first example uses the \plc{inclusive} scan operation on a composite
loop-SIMD construct. The \kcode{scan} directive separates the reduction
statement on variable \ucode{x} from the use of \ucode{x} (saving to array \ucode{b}).
The order of the statements in this example indicates that
value \ucode{a[k]} (\ucode{a(k)} in Fortran) is included in the computation of
the prefix sum \ucode{b[k]} (\ucode{b(k)} in Fortran) for iteration \ucode{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 \kcode{scan} directive separates the use of \ucode{x}
(saving to array \ucode{b}) from the reduction statement on variable \ucode{x}.
The order of the statements in this example indicates that
value \ucode{a[k]} (\ucode{a(k)} in Fortran) is excluded from the computation
of the prefix sum \ucode{b[k]} (\ucode{b(k)} in Fortran) for iteration \ucode{k}.
\cexample[5.0]{scan}{2}
\ffreeexample[5.0]{scan}{2}