Parallel example fron documentation does not compile

Ish via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 19 13:57:20 PST 2016


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


More information about the Digitalmars-d-learn mailing list