Re: Simple parallel foreach and summation/reduction

2018-09-24 Thread Russel Winder via Digitalmars-d-learn
Hi, Apologies for coming late to this thread. I started with: import std.random: uniform; import std.range: iota; import std.stdio: writeln; void main() { ulong sum; foreach(i; iota(1_000_000_000)) { if (uniform(0F,12F) > 6F) sum++; }

Re: Simple parallel foreach and summation/reduction

2018-09-24 Thread Chris Katko via Digitalmars-d-learn
On Monday, 24 September 2018 at 07:13:24 UTC, Chris Katko wrote: On Monday, 24 September 2018 at 05:59:20 UTC, Chris Katko wrote: [...] Actually, I just realized/remembered that the error occurs inside parallelism itself, and MANY times at that: [...] This JUST occurred to me. Wh

Re: Simple parallel foreach and summation/reduction

2018-09-24 Thread Chris Katko via Digitalmars-d-learn
On Monday, 24 September 2018 at 05:59:20 UTC, Chris Katko wrote: On Saturday, 22 September 2018 at 02:26:41 UTC, Chris Katko wrote: On Saturday, 22 September 2018 at 02:13:58 UTC, Chris Katko wrote: On Friday, 21 September 2018 at 12:15:59 UTC, Ali Çehreli wrote: On 09/21/2018 12:25 AM, Chris

Re: Simple parallel foreach and summation/reduction

2018-09-23 Thread Chris Katko via Digitalmars-d-learn
On Saturday, 22 September 2018 at 02:26:41 UTC, Chris Katko wrote: On Saturday, 22 September 2018 at 02:13:58 UTC, Chris Katko wrote: On Friday, 21 September 2018 at 12:15:59 UTC, Ali Çehreli wrote: On 09/21/2018 12:25 AM, Chris Katko wrote: [...] You can use a free-standing function as a wo

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Chris Katko via Digitalmars-d-learn
On Saturday, 22 September 2018 at 02:13:58 UTC, Chris Katko wrote: On Friday, 21 September 2018 at 12:15:59 UTC, Ali Çehreli wrote: On 09/21/2018 12:25 AM, Chris Katko wrote: [...] You can use a free-standing function as a workaround, which is included in the following chapter that explains

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Chris Katko via Digitalmars-d-learn
On Friday, 21 September 2018 at 12:15:59 UTC, Ali Çehreli wrote: On 09/21/2018 12:25 AM, Chris Katko wrote: On Thursday, 20 September 2018 at 05:51:17 UTC, Neia Neutuladh wrote: On Thursday, 20 September 2018 at 05:34:42 UTC, Chris Katko wrote: All I want to do is loop from 0 to [constant] with

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Ali Çehreli via Digitalmars-d-learn
On 09/21/2018 12:25 AM, Chris Katko wrote: On Thursday, 20 September 2018 at 05:51:17 UTC, Neia Neutuladh wrote: On Thursday, 20 September 2018 at 05:34:42 UTC, Chris Katko wrote: All I want to do is loop from 0 to [constant] with a for or foreach, and have it split up across however many cores

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Dennis via Digitalmars-d-learn
On Friday, 21 September 2018 at 07:25:17 UTC, Chris Katko wrote: I get "Error: template instance `reduce!((a, b) => a + b)` cannot use local __lambda1 as parameter to non-global template reduce(functions...)" when trying to compile that using the online D editor with DMD and LDC. Any ideas?

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Chris Katko via Digitalmars-d-learn
On Thursday, 20 September 2018 at 05:51:17 UTC, Neia Neutuladh wrote: On Thursday, 20 September 2018 at 05:34:42 UTC, Chris Katko wrote: All I want to do is loop from 0 to [constant] with a for or foreach, and have it split up across however many cores I have. You're looking at std.parallelism

Re: Simple parallel foreach and summation/reduction

2018-09-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Thursday, 20 September 2018 at 05:34:42 UTC, Chris Katko wrote: All I want to do is loop from 0 to [constant] with a for or foreach, and have it split up across however many cores I have. You're looking at std.parallelism.TaskPool, especially the amap and reduce functions. Should do pretty

Simple parallel foreach and summation/reduction

2018-09-19 Thread Chris Katko via Digitalmars-d-learn
All I want to do is loop from 0 to [constant] with a for or foreach, and have it split up across however many cores I have. ulong sum; foreach(i; [0 to 1 trillion]) { //flip some dice using float die_value = uniform(0F,12F); if(die_value > [constant]) sum++;