On Thu, 2011-03-03 at 09:40 -0500, David Simcha wrote:
> Forgot to mention, though:  The more idiomatic/shorter way to write
> something like this would be to perform a reduction on a
> (non-parallel, lazy, random access) std.parallelism.Map.  The map
> function will be evaluated in parallel naturally, as the parallel
> reduction is performed.  Maybe this should be an example in the docs
> for reduce.  In your pi example:
> 
> // Nested function inside main().
> double calculateTerm(int i) {
>     immutable x = (i - 0.5) * delta ;
>     return 1.0 / (1.0 + x * x);
> }
> 
> immutable sum = taskPool.reduce!"a + b"(
>     std.algorithm.map!calculateTerm(iota(n))
> );

(The above is a slight oversimplification of the situation I have
but . . . )

Sadly this doesn't seem to work.  I tried:

  immutable pi = 4.0 * taskPool.reduce ! ( "a + b" ) ( 0.0 , taskPool.map ! ( 
partialSum ) ( inputData ) ) * delta ;

and this works fine showing good scaling.  However:

  immutable pi = 4.0 * taskPool.reduce ! ( "a + b" ) ( 0.0 , map ! ( partialSum 
) ( inputData ) ) * delta ;

forces serialization so no speed up.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:[email protected]
41 Buckmaster Road    m: +44 7770 465 077   xmpp: [email protected]
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to