openMP

Peter Alexander peter.alexander.au at gmail.com
Tue Oct 2 13:16:48 PDT 2012


On Tuesday, 2 October 2012 at 19:15:19 UTC, Farmer wrote:
> Hi,
> I am tempted to start D programming but for me it is crucrial 
> to be able to parallelize for-loops as can be done with openMP 
> for C/C++ (mainly @pragma omp parallel for, @pragma omp 
> critical).
> I have already seen the std.parallelism library but I'm unsure 
> whether it can provide me with the same functionality.
>
> Thanks

It can. Here's an example from the docs of parallelising a simple 
for loop:

auto logs = new double[10_000_000];
foreach(i, ref elem; taskPool.parallel(logs, 100))
{
     elem = log(i + 1.0);
}

This creates a pool of workers that each perform 100 iterations 
of the loop body in parallel.


More information about the Digitalmars-d mailing list