[plt-dev] Parallel Futures Release
On Sun, Dec 13, 2009 at 7:53 AM, Sam TH <samth at ccs.neu.edu> wrote:
> On Mon, Dec 7, 2009 at 12:31 PM, James Swaine <james.swaine at gmail.com> wrote:
>> I'm pleased to announce the initial release of parallel futures, a
>> construct for fine-grained parallelism in PLT. Roughly speaking, a
>> programmer passes a thunk to 'future' and it gets run in parallel.
>> That "roughly" holds a few gotchas, partly because we're just getting
>> started and partly due to the technique we're using. See the
>> documentation for more details:
>
> Another belated question about this:
>
> Say I have two big non-primitive-calling computations, which don't
> affect each other at all. I gather that this is the intended use case
> for futures. Each of them produces a number, and the result of my
> program should be the sum of the two numbers. How would I write this?
>
> I originally though I'd do this:
>
> (let ([f1 (future big-comp1)] [f2 (future big-comp2)])
> (+ (touch f1) (touch f2)))
This is what you want. You will have two parallel computations and
you'll use two cpus on your machine.
> But this implies lots of potentially-unnecessary communication - I
> start each computation on a separate OS thread, and then I join them
> before they're done. I'd rather be able to wait until I know that
> `f1' and `f2' are done before using `touch'. Is there a way to do
> that?
I don't see what you're getting at here. The only reason to avoid
touching is that you have something else to do, but you don't seem to
here. (And if you did, you could put that thing in another future and
then touch all 3.)
Robby