www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Code example in std.parallelism fails to compile

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
The code example at https://dlang.org/phobos/std_parallelism.html

containing:


import std.algorithm, std.parallelism, std.range;

void main() {
     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))
     );
}

fails to compile as

std/parallelism.d(2632,36): Error: function 
std.parallelism.TaskPool.reduce!"a + 
b".reduce!(MapResult!(getTerm, Result)).reduce cannot get frame 
pointer to D main

on Git master.

Why?

Is there a solution?
Nov 29 2016
next sibling parent Robert burner Schadek <rburners gmail.com> writes:
Not that I know of, https://github.com/dlang/phobos/pull/4399. I 
think std.parallelism was designed around a D feature that was 
more a bug than a feature. This bug/feature seamed to be fixed 
some years ago. But I'm not 100%, as this was before my time.
Nov 29 2016
prev sibling next sibling parent Mihai <mihai unity3d.com> writes:
On Tuesday, 29 November 2016 at 12:09:32 UTC, Nordlöw wrote:

 Is there a solution?
I've reported the issue recently https://issues.dlang.org/show_bug.cgi?id=16705.
Nov 29 2016
prev sibling parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Tuesday, 29 November 2016 at 12:09:32 UTC, Nordlöw wrote:
 The code example at 
 https://dlang.org/phobos/std_parallelism.html

 containing:


 import std.algorithm, std.parallelism, std.range;

 void main() {
     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))
     );
 }

 fails to compile as

 std/parallelism.d(2632,36): Error: function 
 std.parallelism.TaskPool.reduce!"a + 
 b".reduce!(MapResult!(getTerm, Result)).reduce cannot get frame 
 pointer to D main

 on Git master.

 Why?

 Is there a solution?
Define the function you want to call globally. and not inside another function.
Nov 29 2016
parent Mihai <mihai unity3d.com> writes:
On Tuesday, 29 November 2016 at 12:49:53 UTC, Stefan Koch wrote:
 Define the function you want to call globally.
 and not inside another function.
Yes. You can also find a very detailed explanation here https://github.com/dlang/phobos/pull/4915#issuecomment-262484753.
Nov 29 2016