15-312 Recitation #12: Parallelism with Futures
2002-11-13
Joshua Dunfield (joshuad@cs)
Carnegie Mellon University
- Brief comments on asst6, leading into remarks about coercions
- Futures:
future(e): spawn a new thread to evaluate e, then continue;
block only if the result is actually needed
On uniprocessor: If exclusive priority is given to the thread that
spawned the process, we obtain a form of memoizing suspension;
values will not be computed until (and unless) needed. If the
result of the future *is* actually needed, however, all we get
is extra overhead.
If exclusive priority is given to the new thread, we get nothing
but extra overhead.
On multiprocessor, may get speedups (or not, depending on just
how much overhead is involved).
Example:
fun collect f t =
case t of
Leaf => Leaf
| Node(x,l,r) =>
let val ls = collect f l
val rs = collect r l
val rest = ls @ rs
in
if f(x) then x::rest else rest
end
How should this be parallelized? What inputs will have the greatest
speedup, assuming an unlimited number of concurrently executing
processes?
What about
fun append xs ys =
case xs of
[] => ys
| y::ys => x :: (append r ys)