June 19, 2020 Re: Parallel array append using std.parallelism? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjærås | On Fri, Jun 19, 2020 at 06:48:18AM +0000, Simen Kjærås via Digitalmars-d-learn wrote: [...] > There's an example of exactly this in std.parallelism: https://dlang.org/phobos/std_parallelism.html#.TaskPool.workerIndex > > In short: > > Item[] targetArray = ...; // already contains data > // Get thread count from taskPool > Item[][] tmp = new Item[][taskPool.size+1]; > foreach (elem; input.parallel) { > if (condition(elem)) { > auto output = expensiveComputation(elem); > // Use workerIndex as index > tmp[taskPool.workerIndex] ~= output; > } > } > foreach (a; tmp) > targetArray ~= a; [...] Yes, that's exactly what I was looking for. Thanks!! T -- The best way to destroy a cause is to defend it poorly. |
Copyright © 1999-2021 by the D Language Foundation