foreach (i; taskPool.parallel(0..2_000_000)
Steven Schveighoffer
schveiguy at gmail.com
Tue Apr 4 14:20:20 UTC 2023
On 4/4/23 5:24 AM, Salih Dincer wrote:
> Is it necessary to enclose the code in `foreach()`? I invite Ali to tell
> me! Please explain why parallel isn't running.
parallel is a shortcut to `TaskPool.parallel`, which is indeed a
foreach-only construct, it does not return a range.
I think what you want is `TaskPool.map`:
```d
// untested, just looking at the
taskPool.map!(/* your map function here */)
(s.iota(len)).writeln;
```
Can't use pipelining with it, because it is a member function.
https://dlang.org/phobos/std_parallelism.html#.TaskPool.map
-Steve
More information about the Digitalmars-d-learn
mailing list