openMP

Peter Alexander peter.alexander.au at gmail.com
Tue Oct 2 14:41:54 PDT 2012


On Tuesday, 2 October 2012 at 21:13:33 UTC, Farmer wrote:
> And is there also a pragma omp critical analogon?

For critical sections you could use a low-level mutex. I don't do 
much parallel stuff in D, so I don't know if this is the 
preferred way, but it's an option.

http://dlang.org/phobos/core_sync_mutex.html

import std.stdio;
import std.parallelism;
import std.math;
import core.sync.mutex;
void main()
{
	auto logs = new double[1_000_000];
	double x = 0.0;
	Mutex m = new Mutex();
	foreach(i, ref elem; taskPool.parallel(logs, 100))
	{
		elem = log(i + 1.0);
		m.lock();
		x += 1.0;
		m.unlock();
	}
}


More information about the Digitalmars-d mailing list