Requesting Help with Optimizing Code

Bastiaan Veelo Bastiaan at Veelo.net
Thu Apr 8 16:59:07 UTC 2021


On Thursday, 8 April 2021 at 16:37:57 UTC, Kyle Ingraham wrote:
> Are compilers able to take loops and parallelize them?

No, but you can quite easily:

```
// Find the logarithm of every number from
// 1 to 1_000_000 in parallel, using the
// default TaskPool instance.
auto logs = new double[1_000_000];

foreach (i, ref elem; parallel(logs))
{
     elem = log(i + 1.0);
}
```

https://dlang.org/phobos/std_parallelism.html#.parallel

-- Bastiaan.


More information about the Digitalmars-d mailing list