Simple parallel foreach and summation/reduction

Neia Neutuladh neia at ikeran.org
Thu Sep 20 05:51:17 UTC 2018


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 much exactly what you're 
asking.

auto taskpool = new TaskPool();
taskpool.reduce!((a, b) => a + b)(iota(1_000_000_000_000L));


More information about the Digitalmars-d-learn mailing list