Parallel example from documentation does not compile

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 19 20:23:56 PST 2016


Sadly the answer is no.

This is due to https://issues.dlang.org/show_bug.cgi?id=5710 which
apparently no-one is either willing or able to fix. The problem
afflicts dmd, l;dc2 and I suspect gdc.

cf. https://github.com/russel/Pi_Quadrature/tree/master/D

for some extra detail and some workarounds.

It appears I had not added this original version, but I am now fixing
this.

On Fri, 2016-02-19 at 21:57 +0000, Ish via Digitalmars-d-learn wrote:
> This code snippet is from: 
> http://dlang.org/phobos/std_parallelism.html
> ---
> import std.algorithm, std.parallelism, std.range;
> 
> void main() {
>      // Parallel reduce can be combined with
>      // std.algorithm.map to interesting effect.
>      // The following example (thanks to Russel Winder)
>      // calculates pi by quadrature  using
>      // std.algorithm.map and TaskPool.reduce.
>      // getTerm is evaluated in parallel as needed by
>      // TaskPool.reduce.
>      //
>      // Timings on an Athlon 64 X2 dual core machine:
>      //
>      // TaskPool.reduce:       12.170 s
>      // std.algorithm.reduce:  24.065 s
> 
>      immutable n = 1_000_000_000;
>      immutable delta = 1.0 / n;
> 
>      real getTerm(int i)
>      {
>          immutable x = ( i - 0.5 ) * delta;
>          return delta / ( 1.0 + x * x ) ;
>      }
> 
>      immutable pi = 4.0 * taskPool.reduce!"a + b"(
>          std.algorithm.map!getTerm(iota(n))
>      );
> }
> 
> dmd compiler gives error:
> /usr/include/dmd/phobos/std/parallelism.d(2624): Error: function 
> std.parallelism.TaskPool.reduce!"a + 
> b".reduce!(MapResult!(getTerm, Result)).reduce cannot get frame 
> pointer to D main
> 
> Is there way to compile it?
> 
> -Ish
-- 
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 winder.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: 181 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20160220/311e8eb4/attachment.sig>


More information about the Digitalmars-d-learn mailing list