Re: Parallel processing and further use of output

2015-09-26 Thread Zoidberg via Digitalmars-d-learn
Here's a correct version: import std.parallelism, std.range, std.stdio, core.atomic; void main() { shared ulong i = 0; foreach (f; parallel(iota(1, 100+1))) { i.atomicOp!"+="(f); } i.writeln; } Thanks! Works fine. So "shared" and "atomic" is a must?

Parallel processing and further use of output

2015-09-26 Thread Zoidberg via Digitalmars-d-learn
I've run into an issue, which I guess could be resolved easily, if I knew how... [CODE] ulong i = 0; foreach (f; parallel(iota(1, 100+1))) { i += f; } thread_joinAll(); i.writeln; [/CODE] It's basically an example which adds all the numbers from 1 to

Re: Parallel processing and further use of output

2015-09-26 Thread Zoidberg via Digitalmars-d-learn
On Saturday, 26 September 2015 at 13:09:54 UTC, Meta wrote: On Saturday, 26 September 2015 at 12:33:45 UTC, anonymous wrote: foreach (f; parallel(iota(1, 100+1))) { synchronized i += f; } Is this valid syntax? I've never seen synchronized used like this before.