Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Shayne Fletcher
Glasgow Haskell Compiler
Commits
816b587f
Commit
816b587f
authored
Oct 24, 2008
by
Simon Marlow
Browse files
Document the new SPARKS statistic, and xref from the parallelism section
parent
b7ea7671
Changes
2
Hide whitespace changes
Inline
Side-by-side
docs/users_guide/parallel.xml
View file @
816b587f
...
...
@@ -114,10 +114,10 @@ All these features are described in the papers mentioned earlier.
<programlisting>
infixr 0 `par`
infixr 1 `seq`
infixr 1 `
p
seq`
par :: a -
>
b -
>
b
seq :: a -
>
b -
>
b
</programlisting>
par
:: a -
>
b -
>
b
p
seq :: a -
>
b -
>
b
</programlisting>
<para>
The expression
<literal>
(x `par` y)
</literal>
<emphasis>
sparks
</emphasis>
the evaluation of
<literal>
x
</literal>
...
...
@@ -136,24 +136,35 @@ import Control.Parallel
nfib :: Int -
>
Int
nfib n | n
<
= 1 = 1
| otherwise = par n1 (seq n2 (n1 + n2 + 1))
| otherwise = par n1 (
p
seq n2 (n1 + n2 + 1))
where n1 = nfib (n-1)
n2 = nfib (n-2)
</programlisting>
<para>
For values of
<varname>
n
</varname>
greater than 1, we use
<function>
par
</function>
to spark a thread to evaluate
<literal>
nfib (n-1)
</literal>
,
and then we use
<function>
seq
</function>
to force the
and then we use
<function>
p
seq
</function>
to force the
parent thread to evaluate
<literal>
nfib (n-2)
</literal>
before going on
to add together these two subexpressions. In this divide-and-conquer
approach, we only spark a new thread for one branch of the computation
(leaving the parent to evaluate the other branch). Also, we must use
<function>
seq
</function>
to ensure that the parent will evaluate
<function>
p
seq
</function>
to ensure that the parent will evaluate
<varname>
n2
</varname>
<emphasis>
before
</emphasis>
<varname>
n1
</varname>
in the expression
<literal>
(n1 + n2 + 1)
</literal>
. It is not sufficient
to reorder the expression as
<literal>
(n2 + n1 + 1)
</literal>
, because
the compiler may not generate code to evaluate the addends from left to
right.
</para>
<para>
Note that we use
<literal>
pseq
</literal>
rather
than
<literal>
seq
</literal>
. The two are almost equivalent, but
differ in their runtime behaviour in a subtle
way:
<literal>
seq
</literal>
can evaluate its arguments in either
order, but
<literal>
pseq
</literal>
is required to evaluate its
first argument before its second, which makes it more suitable
for controlling the evaluation order in conjunction
with
<literal>
par
</literal>
.
</para>
<para>
When using
<literal>
par
</literal>
, the general rule of thumb is that
the sparked computation should be required at a later time, but not too
soon. Also, the sparked computation should not be too small, otherwise
...
...
@@ -161,6 +172,10 @@ nfib n | n <= 1 = 1
amount of parallelism gained. Getting these factors right is tricky in
practice.
</para>
<para>
It is possible to glean a little information about how
well
<literal>
par
</literal>
is working from the runtime
statistics; see
<xref
linkend=
"rts-options-gc"
/>
.
</para>
<para>
More sophisticated combinators for expressing parallelism are
available from the
<ulink
url=
"../libraries/parallel/Control-Parallel-Strategies.html"
><literal>
Control.Parallel.Strategies
</literal></ulink>
module.
...
...
docs/users_guide/runtime_control.xml
View file @
816b587f
...
...
@@ -531,6 +531,8 @@
Generation 0: 67 collections, 0 parallel, 0.04s, 0.03s elapsed
Generation 1: 2 collections, 0 parallel, 0.03s, 0.04s elapsed
SPARKS: 359207 (557 converted, 149591 pruned)
INIT time 0.00s ( 0.00s elapsed)
MUT time 0.01s ( 0.02s elapsed)
GC time 0.07s ( 0.07s elapsed)
...
...
@@ -588,6 +590,17 @@
that generation.
</para>
</listitem>
<listitem>
<para>
The
<literal>
SPARKS
</literal>
statistic refers to the
use of
<literal>
Control.Parallel.par
</literal>
and related
functionality in the program. Each spark represents a call
to
<literal>
par
</literal>
; a spark is "converted" when it is
executed in parallel; and a spark is "pruned" when it is
found to be already evaluated and is discarded from the pool
by the garbage collector. Any remaining sparks are
discarded at the end of execution, so "converted" plus
"pruned" does not necessarily add up to the total.
</para>
</listitem>
<listitem>
<para>
Next there is the CPU time and wall clock time elapsedm broken
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment