forked from OpenMP/Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamples_scan.tex
38 lines (30 loc) · 1.81 KB
/
Examples_scan.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
\pagebreak
\section{The \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}