@@ -1881,6 +1881,35 @@ \subsection{Radix-Sort in Futhark}
18811881that $ S(\kw {rsort}~\kw {v}) = O(\log \, \kw {n})$ , dominated by the
18821882\fop {scan} SOAC calls in $ \kw {rsort\_ step}$ .
18831883
1884+ \section {Counting Primes }
1885+ A variant of a contraction algorithm is an algorithm that first solves
1886+ a smaller problem, recursively, and then uses this result to provide a
1887+ solution to the larger problem. One such algorithm is a version of the
1888+ Sieve of Eratosthenes that, to find the primes smaller than some $ n$ ,
1889+ first calculates the primes smaller than $ \sqrt n$ . It then uses this
1890+ intermediate result for sieving away the integers in the range $ \sqrt
1891+ n$ up to $ n$ that are multiples of the primes smaller than $ \sqrt n$ .
1892+
1893+ A Futhark program calculating the number of primes below some number
1894+ $ n$ , also denoted in the literature as the $ \pi $ function, is shown in
1895+ Figure~\ref {fig:primes }.
1896+
1897+ \begin {figure }
1898+ \begin {wrap }
1899+ \lstinputlisting {src/primes.fut}
1900+ \end {wrap }
1901+ \caption {An Implementation of the Sieve of Eratosthenes.}
1902+ \label {fig:primes }
1903+ \end {figure }
1904+
1905+ Notice that the algorithm applies a parallel sieve for each step,
1906+ using a combination of maps and reductions. The work done by the
1907+ algorithm is $ O(n\, \log \, \log \, n)$ and the span is
1908+ $ O(\log \, \log \, n)$ . The $ \log \, \log \, n$ factor appears because the
1909+ size of the problem is reduced at each step by applying the square
1910+ root, which is identical to halving the exponent size at each
1911+ step (i.e., the sequence $ n, \ldots , 2 ^{16}, 2 ^8 , 2 ^4 , 2 ^2 $ , where $ n=2 ^{2^m}$ , for some positive $ m$ , has $ m = \log \, \log \, n$ elements.)
1912+
18841913\chapter {Algebraic Properties of SOACs }
18851914\label {chap:soac-algebra }
18861915
@@ -1917,17 +1946,16 @@ \section{Segmented Scan}
19171946\label {sec:sgmscan }
19181947
19191948The segmented scan operator is quite essential as we shall see
1920- demonstrated in many of the algorithms explained later. The segmented scan
1921- operator can be implemented with a simple scan using an associative
1922- function that operates on pairs of values. Here is the definition of
1923- the segmented scan operation:
1949+ demonstrated in many of the algorithms explained later. The segmented
1950+ scan operator can be implemented with a simple scan using an
1951+ associative function that operates on pairs of values
1952+ \cite {Schwartz:1980:ULT:357114.357116 ,blelloch1990vector }. Here is the
1953+ definition of the segmented scan operation:
19241954
19251955\begin {wrap }
19261956\lstinputlisting [firstline=7]{src/sgm_scan.fut}
19271957\end {wrap }
19281958
1929-
1930-
19311959\section {Parallel Utility Functions }
19321960For use by other algorithms, a set of utility functions for
19331961manipulating and managing arrays is an important part of the tool
0 commit comments