[phobos] std.parallelism: Request for review

Russel Winder russel at russel.org.uk
Sun Mar 6 08:34:08 PST 2011


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:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20110306/56358ca3/attachment.pgp>


More information about the phobos mailing list